package io.trygvis.esper.testing; import fj.*; import fj.data.*; import static fj.data.Option.*; import org.jdom2.*; import org.joda.time.*; import java.net.*; import java.sql.*; public class Util { public static final F timestampToDate = new F() { public java.util.Date f(Timestamp timestamp) { return new java.util.Date(timestamp.getTime()); } }; public static final F timestampToLocalDateTime = new F() { public LocalDateTime f(Timestamp timestamp) { return new LocalDateTime(timestamp.getTime()); } }; public static final F dateToTimestamp = new F() { public Timestamp f(java.util.Date date) { return new Timestamp(date.getTime()); } }; public static F> parseInt = new F>() { public Option f(String s) { try { return some(Integer.parseInt(s)); } catch (NumberFormatException e) { return none(); } } }; public static F> parseLong = new F>() { public Option f(String s) { try { return some(Long.parseLong(s)); } catch (NumberFormatException e) { return none(); } } }; public static F> parseUri = new F>() { public Option f(String s) { try { return some(URI.create(s)); } catch (Throwable e) { return none(); } } }; public static F> parseBoolean = new F>() { public Option f(String s) { try { return some(Boolean.parseBoolean(s)); } catch (Throwable e) { return none(); } } }; public static Option childText(Element e, String childName) { return fromNull(e.getChildText(childName)); } public static Option child(Element e, String childName) { return fromNull(e.getChild(childName)); } }