Class Suppliers

java.lang.Object
org.apache.camel.util.function.Suppliers

public final class Suppliers extends Object
  • Method Details

    • memorize

      public static <T> Supplier<T> memorize(Supplier<T> supplier)
      Returns a supplier which caches the result of the first call to Supplier.get()and returns that value on subsequent calls.
      Type Parameters:
      T - the type of results supplied by this supplier.
      Parameters:
      supplier - the delegate Supplier.
      Returns:
      the result fo the first call to the delegate's Supplier.get() method.
    • memorize

      public static <T> Supplier<T> memorize(ThrowingSupplier<T,? extends Exception> supplier, Consumer<Exception> consumer)
      Returns a supplier which caches the result of the first call to Supplier.get() and returns that value on subsequent calls.
      Type Parameters:
      T - the type of results supplied by this supplier.
      Parameters:
      supplier - the delegate Supplier.
      consumer - a consumer for any exception thrown by the ThrowingSupplier.get().
      Returns:
      the result fo the first call to the delegate's Supplier.get() method.
    • constant

      public static <T> Supplier<T> constant(T value)
      Returns a supplier that return a constant value.
      Type Parameters:
      T - the type of results supplied by this supplier.
      Parameters:
      value - the constant value to return.
      Returns:
      the supplied value.
    • firstNotNull

      @SafeVarargs public static <T> Optional<T> firstNotNull(ThrowingSupplier<T,Exception>... suppliers) throws Exception
      Returns the first non null value provide by the given suppliers.
      Type Parameters:
      T - the type of results supplied by this supplier.
      Parameters:
      suppliers - a list of supplier.
      Returns:
      the optional computed value.
      Throws:
      Exception
    • firstMatching

      public static <T> Optional<T> firstMatching(Predicate<T> predicate, ThrowingSupplier<T,Exception>... suppliers) throws Exception
      Returns the first value provide by the given suppliers that matches the given predicate.
      Type Parameters:
      T - the type of results supplied by this supplier.
      Parameters:
      predicate - the predicate used to evaluate the computed values.
      suppliers - a list fo supplier.
      Returns:
      the optional matching value.
      Throws:
      Exception