Class KiwiObjects

java.lang.Object
org.kiwiproject.base.KiwiObjects

public final class KiwiObjects extends Object
Utilities for any object which are not in Objects or MoreObjects.
  • Method Details

    • firstNonNullOrNull

      @SafeVarargs public static <T> T firstNonNullOrNull(T first, T second, T... rest)
      Return the first non-null object, or null if all are null.
      Type Parameters:
      T - the type of objects
      Parameters:
      first - the first object
      second - the second object
      rest - 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, or null if all suppliers return null.
      Type Parameters:
      T - the type of objects
      Parameters:
      first - the first object supplier
      second - the second object supplier
      rest - 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)
      Return an Optional containing the first non-null object, or an empty Optional if all are null.
      Type Parameters:
      T - the type of objects
      Parameters:
      first - the first object
      second - the second object
      rest - 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 an Optional containing the first non-null object, or an empty Optional if all suppliers return null.
      Type Parameters:
      T - the type of objects
      Parameters:
      first - the first object supplier
      second - the second object supplier
      rest - 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