Package org.kiwiproject.base
Class KiwiObjects
- java.lang.Object
-
- org.kiwiproject.base.KiwiObjects
-
-
Constructor Summary
Constructors Constructor Description KiwiObjects()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 all suppliers return null.
-
-
-
Method Detail
-
firstNonNullOrNull
@SafeVarargs public static <T> T firstNonNullOrNull(T first, T second, T... rest)
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 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
@SafeVarargs public static <T> Optional<T> firstNonNull(T first, T second, T... rest)
- 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
-
-