It is a memorandum I don't know if it's a comment or something
Utils.java
package util;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.Arrays;
public class Utils {
/** --------------- Object --------------- */
/**True if not null*/
public static final Predicate<Object> nonNull = v -> v != null;
/**Convert to empty string if null*/
public static final Function<Object, String> nullToEmpty = v -> v == null ? "" : v.toString();
/**Convert to 0 if null and non-numeric*/
public static final Function<Object, Integer> nullToZero = v -> {
try {
return v == null ? 0 : Integer.parseInt(v.toString());
} catch (NumberFormatException e) {
return 0;
}
};
/** --------------- String --------------- */
/**True if neither null nor empty string*/
public static final Predicate<String> nonEmpty = v -> v != null && !v.equals("");
/**Whitespace character, null or empty string(Half-width and full-width)If not true*/
public static final Predicate<String> nonBlank = v -> v != null && !v.equals("")
&& Arrays.stream(v.split("")).anyMatch(x -> !x.equals(" ") && !x.equals(" "));
}
I really want you to forgive me for the date type.
Recommended Posts