Package org.apache.camel.util.function
Class Suppliers
- java.lang.Object
-
- org.apache.camel.util.function.Suppliers
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Supplier<T>constant(T value)Returns a supplier that return a constant value.static <T> Optional<T>firstMatching(Predicate<T> predicate, ThrowingSupplier<T,Exception>... suppliers)Returns the first value provide by the given suppliers that matches the given predicate.static <T> Optional<T>firstNotNull(ThrowingSupplier<T,Exception>... suppliers)Returns the first non null value provide by the given suppliers.static <T> Supplier<T>memorize(Supplier<T> supplier)Returns a supplier which caches the result of the first call toSupplier.get()and returns that value on subsequent calls.static <T> Supplier<T>memorize(ThrowingSupplier<T,? extends Exception> supplier, Consumer<Exception> consumer)Returns a supplier which caches the result of the first call toSupplier.get()and returns that value on subsequent calls.
-
-
-
Method Detail
-
memorize
public static <T> Supplier<T> memorize(Supplier<T> supplier)
Returns a supplier which caches the result of the first call toSupplier.get()and returns that value on subsequent calls.- Type Parameters:
T- the type of results supplied by this supplier.- Parameters:
supplier- the delegateSupplier.- 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 toSupplier.get()and returns that value on subsequent calls.- Type Parameters:
T- the type of results supplied by this supplier.- Parameters:
supplier- the delegateSupplier.consumer- a consumer for any exception thrown by theThrowingSupplier.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
-
-