java/sql-dk/src/info/globalcode/sql/dk/Functions.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 16 Dec 2013 20:01:37 +0100
branchv_0
changeset 16 5b8fcd35d4d6
parent 1 f32dac78d13a
child 29 d66858b4b563
permissions -rw-r--r--
license: GNU GPLv3+
     1 /**
     2  * SQL-DK
     3  * Copyright © 2013 František Kučera (frantovo.cz)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, either version 3 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 package info.globalcode.sql.dk;
    19 
    20 import java.util.ArrayList;
    21 import java.util.Collection;
    22 import java.util.Map;
    23 
    24 /**
    25  *
    26  * @author Ing. František Kučera (frantovo.cz)
    27  */
    28 public class Functions {
    29 
    30 	private Functions() {
    31 	}
    32 
    33 	public static boolean equalz(Object a, Object b) {
    34 		return a == null ? b == null : a.equals(b);
    35 	}
    36 
    37 	/**
    38 	 *
    39 	 * @param text String to be examinated
    40 	 * @param trim whether text should be trimmed before examination
    41 	 * @return whether text is not empty and one or more characters long (after prospective trim)
    42 	 */
    43 	public static boolean isEmpty(String text, boolean trim) {
    44 		if (text == null) {
    45 			return true;
    46 		} else {
    47 			if (trim) {
    48 				text = text.trim();
    49 			}
    50 			return text.isEmpty();
    51 		}
    52 	}
    53 
    54 	/**
    55 	 * @see #isEmpty(java.lang.String, boolean)
    56 	 */
    57 	public static boolean isNotEmpty(String text, boolean trim) {
    58 		return !isEmpty(text, trim);
    59 	}
    60 
    61 	public boolean isEmpty(Collection c) {
    62 		return c == null || c.isEmpty();
    63 	}
    64 
    65 	public boolean isNotEmpty(Collection c) {
    66 		return !isEmpty(c);
    67 	}
    68 
    69 	public boolean isEmpty(Map m) {
    70 		return m == null || m.isEmpty();
    71 	}
    72 
    73 	public boolean isNotEmpty(Map m) {
    74 		return !isEmpty(m);
    75 	}
    76 
    77 	/**
    78 	 * @return empty collection if given one is null | or the original one
    79 	 */
    80 	public static <T> Collection<T> notNull(Collection<T> c) {
    81 		if (c == null) {
    82 			return new ArrayList<>();
    83 		} else {
    84 			return c;
    85 		}
    86 	}
    87 }