Package org.kiwiproject.base
Class KiwiObjects
java.lang.Object
org.kiwiproject.base.KiwiObjects
Utilities for any object which are not in
Objects or MoreObjects.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<T>firstNonNull(T first, T second, T... rest) static <T> TfirstNonNullOrNull(T first, T second, T... rest) Return the first non-null object, ornullif all are null.static <T> Optional<T>firstSuppliedNonNull(Supplier<T> first, Supplier<T> second, Supplier<T>... rest) static <T> TfirstSuppliedNonNullOrNull(Supplier<T> first, Supplier<T> second, Supplier<T>... rest) Return the first supplied non-null object, ornullif all suppliers return null.
-
Method Details
-
firstNonNullOrNull
Return the first non-null object, ornullif all are null.- Type Parameters:
T- the type of objects- Parameters:
first- the first objectsecond- the second objectrest- zero or more additional objects- Returns:
- the first non-null object or null if all are null
-
firstSuppliedNonNullOrNull
@SafeVarargs public static <T> T firstSuppliedNonNullOrNull(Supplier<T> first, Supplier<T> second, Supplier<T>... rest) Return the first supplied non-null object, ornullif all suppliers return null.- Type Parameters:
T- the type of objects- Parameters:
first- the first object suppliersecond- the second object supplierrest- zero or more additional object suppliers- Returns:
- the first non-null supplied object or null if all suppliers return null
- Implementation Note:
- once a non-null object is supplied, no further suppliers are called
-
firstNonNull
- Type Parameters:
T- the type of objects- Parameters:
first- the first objectsecond- the second objectrest- zero or more additional objects- Returns:
- an optional containing the first non-null object or empty optional if all are null
-
firstSuppliedNonNull
@SafeVarargs public static <T> Optional<T> firstSuppliedNonNull(Supplier<T> first, Supplier<T> second, Supplier<T>... rest) Return anOptionalcontaining the first non-null object, or an emptyOptionalif all suppliers return null.- Type Parameters:
T- the type of objects- Parameters:
first- the first object suppliersecond- the second object supplierrest- zero or more additional object suppliers- Returns:
- an optional containing the first non-null supplied object or empty optional if all suppliers return null
- Implementation Note:
- once a non-null object is supplied, no further suppliers are called
-