3 * Copyright © 2013 František Kučera (frantovo.cz)
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.
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.
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/>.
18 package info.globalcode.sql.dk;
20 import info.globalcode.sql.dk.configuration.NameIdentified;
21 import java.util.ArrayList;
22 import java.util.Collection;
27 * @author Ing. František Kučera (frantovo.cz)
29 public class Functions {
34 public static boolean equalz(Object a, Object b) {
35 return a == null ? b == null : a.equals(b);
40 * @param text String to be examinated
41 * @param trim whether text should be trimmed before examination
42 * @return whether text is not empty and one or more characters long (after prospective trim)
44 public static boolean isEmpty(String text, boolean trim) {
51 return text.isEmpty();
56 * @see #isEmpty(java.lang.String, boolean)
58 public static boolean isNotEmpty(String text, boolean trim) {
59 return !isEmpty(text, trim);
62 public boolean isEmpty(Collection c) {
63 return c == null || c.isEmpty();
66 public boolean isNotEmpty(Collection c) {
70 public boolean isEmpty(Map m) {
71 return m == null || m.isEmpty();
74 public boolean isNotEmpty(Map m) {
79 * @return empty collection if given one is null | or the original one
81 public static <T> Collection<T> notNull(Collection<T> c) {
83 return new ArrayList<>();
89 public static <T extends NameIdentified> T findByName(Collection<T> collection, String name) {
90 for (T element : collection) {
91 if (equalz(element.getName(), name)) {