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