java/sql-dk/src/info/globalcode/sql/dk/Functions.java
branchv_0
changeset 1 f32dac78d13a
child 16 5b8fcd35d4d6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/Functions.java	Sun Dec 15 19:20:50 2013 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +package info.globalcode.sql.dk;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +import java.util.Collection;
     1.8 +import java.util.Map;
     1.9 +
    1.10 +/**
    1.11 + *
    1.12 + * @author Ing. František Kučera (frantovo.cz)
    1.13 + */
    1.14 +public class Functions {
    1.15 +
    1.16 +	private Functions() {
    1.17 +	}
    1.18 +
    1.19 +	public static boolean equalz(Object a, Object b) {
    1.20 +		return a == null ? b == null : a.equals(b);
    1.21 +	}
    1.22 +
    1.23 +	/**
    1.24 +	 *
    1.25 +	 * @param text String to be examinated
    1.26 +	 * @param trim whether text should be trimmed before examination
    1.27 +	 * @return whether text is not empty and one or more characters long (after prospective trim)
    1.28 +	 */
    1.29 +	public static boolean isEmpty(String text, boolean trim) {
    1.30 +		if (text == null) {
    1.31 +			return true;
    1.32 +		} else {
    1.33 +			if (trim) {
    1.34 +				text = text.trim();
    1.35 +			}
    1.36 +			return text.isEmpty();
    1.37 +		}
    1.38 +	}
    1.39 +
    1.40 +	/**
    1.41 +	 * @see #isEmpty(java.lang.String, boolean)
    1.42 +	 */
    1.43 +	public static boolean isNotEmpty(String text, boolean trim) {
    1.44 +		return !isEmpty(text, trim);
    1.45 +	}
    1.46 +
    1.47 +	public boolean isEmpty(Collection c) {
    1.48 +		return c == null || c.isEmpty();
    1.49 +	}
    1.50 +
    1.51 +	public boolean isNotEmpty(Collection c) {
    1.52 +		return !isEmpty(c);
    1.53 +	}
    1.54 +
    1.55 +	public boolean isEmpty(Map m) {
    1.56 +		return m == null || m.isEmpty();
    1.57 +	}
    1.58 +
    1.59 +	public boolean isNotEmpty(Map m) {
    1.60 +		return !isEmpty(m);
    1.61 +	}
    1.62 +
    1.63 +	/**
    1.64 +	 * @return empty collection if given one is null | or the original one
    1.65 +	 */
    1.66 +	public static <T> Collection<T> notNull(Collection<T> c) {
    1.67 +		if (c == null) {
    1.68 +			return new ArrayList<>();
    1.69 +		} else {
    1.70 +			return c;
    1.71 +		}
    1.72 +	}
    1.73 +}