kendal.utils.Utils Maven / Gradle / Ivy
package kendal.utils;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
public class Utils {
public static void ifNotNull(T object, Consumer consumer) {
if(object != null) {
consumer.accept(object);
}
}
public static R ifNotNull(T object, Function function, R otherwise) {
if (object != null) {
return function.apply(object);
}
return otherwise;
}
public static R map(T obj, Function mapping) {
return Stream.of(obj).map(mapping).findFirst().orElse(null);
}
public static T map(T obj, Consumer consumer) {
consumer.accept(obj);
return obj;
}
public static void with(T object, Consumer consumer) {
consumer.accept(object);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy