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

io.polyglotted.common.util.NullUtil Maven / Gradle / Ivy

The newest version!
package io.polyglotted.common.util;

import java.util.function.Function;
import java.util.function.Supplier;

@SuppressWarnings({"unused", "WeakerAccess"})
public abstract class NullUtil {

    public static  T nonNull(T nullable, Supplier function) { return nullable != null ? nullable : function.get(); }

    public static  T nonNull(T nullable, T defValue) { return nullable != null ? nullable : defValue; }

    public static  T nonNull(T first, T second, T third) { return first != null ? first : second != null ? second : third; }

    @SafeVarargs public static  T nonNullIn(T... list) { for (T t : list) { if (t != null) return t; } return null; }

    public static  V nonNullFn(K nullable, Function function, V defVal) { return nullable != null ? function.apply(nullable) : defVal; }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy