cn.kduck.core.utils.ObjectUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kduck-core Show documentation
Show all versions of kduck-core Show documentation
The core of the K-Duck development framework encompasses all the featured components of the framework.
package cn.kduck.core.utils;
import java.util.function.Function;
public final class ObjectUtils {
private ObjectUtils(){}
public static boolean isNull(T obj, Function objectField){
if(obj == null) return true;
return objectField.apply(obj) == null;
}
public static R valueOrNull(T obj, Function objectField){
if(obj == null) return null;
return objectField.apply(obj);
}
public static R valueOrDefault(T obj, Function objectField,R defaultValue){
R r = valueOrNull(obj, objectField);
return r == null ? defaultValue : r;
}
}