java/sql-dk/src/info/globalcode/sql/dk/Functions.java
branchv_0
changeset 1 f32dac78d13a
child 16 5b8fcd35d4d6
equal deleted inserted replaced
0:29df3b2e34df 1:f32dac78d13a
       
     1 package info.globalcode.sql.dk;
       
     2 
       
     3 import java.util.ArrayList;
       
     4 import java.util.Collection;
       
     5 import java.util.Map;
       
     6 
       
     7 /**
       
     8  *
       
     9  * @author Ing. František Kučera (frantovo.cz)
       
    10  */
       
    11 public class Functions {
       
    12 
       
    13 	private Functions() {
       
    14 	}
       
    15 
       
    16 	public static boolean equalz(Object a, Object b) {
       
    17 		return a == null ? b == null : a.equals(b);
       
    18 	}
       
    19 
       
    20 	/**
       
    21 	 *
       
    22 	 * @param text String to be examinated
       
    23 	 * @param trim whether text should be trimmed before examination
       
    24 	 * @return whether text is not empty and one or more characters long (after prospective trim)
       
    25 	 */
       
    26 	public static boolean isEmpty(String text, boolean trim) {
       
    27 		if (text == null) {
       
    28 			return true;
       
    29 		} else {
       
    30 			if (trim) {
       
    31 				text = text.trim();
       
    32 			}
       
    33 			return text.isEmpty();
       
    34 		}
       
    35 	}
       
    36 
       
    37 	/**
       
    38 	 * @see #isEmpty(java.lang.String, boolean)
       
    39 	 */
       
    40 	public static boolean isNotEmpty(String text, boolean trim) {
       
    41 		return !isEmpty(text, trim);
       
    42 	}
       
    43 
       
    44 	public boolean isEmpty(Collection c) {
       
    45 		return c == null || c.isEmpty();
       
    46 	}
       
    47 
       
    48 	public boolean isNotEmpty(Collection c) {
       
    49 		return !isEmpty(c);
       
    50 	}
       
    51 
       
    52 	public boolean isEmpty(Map m) {
       
    53 		return m == null || m.isEmpty();
       
    54 	}
       
    55 
       
    56 	public boolean isNotEmpty(Map m) {
       
    57 		return !isEmpty(m);
       
    58 	}
       
    59 
       
    60 	/**
       
    61 	 * @return empty collection if given one is null | or the original one
       
    62 	 */
       
    63 	public static <T> Collection<T> notNull(Collection<T> c) {
       
    64 		if (c == null) {
       
    65 			return new ArrayList<>();
       
    66 		} else {
       
    67 			return c;
       
    68 		}
       
    69 	}
       
    70 }