com.sksamuel.jqm4gwt.Empty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jqm4gwt-standalone Show documentation
Show all versions of jqm4gwt-standalone Show documentation
jqm4gwt bundled with all of its dependencies
The newest version!
package com.sksamuel.jqm4gwt;
import java.util.Collection;
import java.util.Map;
/**
* Null safe empty check for different data types.
*/
public class Empty {
private Empty() {} // static class
public static boolean is(String s) {
return s == null || s.length() == 0; // optimize like Guava: s.isEmpty() -> s.length() == 0
}
public static boolean is(Collection> collect) {
return collect == null || collect.isEmpty();
}
public static boolean is(Map, ?> map) {
return map == null || map.isEmpty();
}
/**
* @return - if value is null returns replaceWithIfNull, otherwise just value.
*/
public static T nvl(T value, T replaceWithIfNull) {
return value != null ? value : replaceWithIfNull;
}
/** The same as {@link Empty#nvl(Object, Object)} */
public static T nonNull(T value, T replaceWithIfNull) {
return value != null ? value : replaceWithIfNull;
}
/**
* @return - similar to nvl(), but returns replaceWithIfEmpty in case of null and empty,
* otherwise just value.
*/
public static String nonEmpty(String value, String replaceWithIfEmpty) {
return Empty.is(value) ? replaceWithIfEmpty : value;
}
public static Collection nonEmpty(Collection value, Collection replaceWithIfEmpty) {
return Empty.is(value) ? replaceWithIfEmpty : value;
}
public static Map nonEmpty(Map value, Map replaceWithIfEmpty) {
return Empty.is(value) ? replaceWithIfEmpty : value;
}
}