All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kendal.utils.Utils Maven / Gradle / Ivy

The newest version!
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