diff -r 29df3b2e34df -r f32dac78d13a java/sql-dk/src/info/globalcode/sql/dk/Functions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/sql-dk/src/info/globalcode/sql/dk/Functions.java Sun Dec 15 19:20:50 2013 +0100 @@ -0,0 +1,70 @@ +package info.globalcode.sql.dk; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +/** + * + * @author Ing. František Kučera (frantovo.cz) + */ +public class Functions { + + private Functions() { + } + + public static boolean equalz(Object a, Object b) { + return a == null ? b == null : a.equals(b); + } + + /** + * + * @param text String to be examinated + * @param trim whether text should be trimmed before examination + * @return whether text is not empty and one or more characters long (after prospective trim) + */ + public static boolean isEmpty(String text, boolean trim) { + if (text == null) { + return true; + } else { + if (trim) { + text = text.trim(); + } + return text.isEmpty(); + } + } + + /** + * @see #isEmpty(java.lang.String, boolean) + */ + public static boolean isNotEmpty(String text, boolean trim) { + return !isEmpty(text, trim); + } + + public boolean isEmpty(Collection c) { + return c == null || c.isEmpty(); + } + + public boolean isNotEmpty(Collection c) { + return !isEmpty(c); + } + + public boolean isEmpty(Map m) { + return m == null || m.isEmpty(); + } + + public boolean isNotEmpty(Map m) { + return !isEmpty(m); + } + + /** + * @return empty collection if given one is null | or the original one + */ + public static Collection notNull(Collection c) { + if (c == null) { + return new ArrayList<>(); + } else { + return c; + } + } +}