Package org.apache.juneau.commons.utils
Class PredicateUtils
java.lang.Object
org.apache.juneau.commons.utils.PredicateUtils
Utility methods for composing
Predicate instances.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidConsumes the specified value if the predicate isnull or matches the specified value.static <T> Predicate<T>distinctByKey(Function<? super T, ?> keyExtractor) static <T> Function<T,T> peek()Returns a function that prints the input value to stderr and returns it unchanged.static <T> Function<T,T> Returns a function that prints the input value to stderr using a custom formatter and returns it unchanged.static <T> booleanReturnstrue if the specified predicate isnull or matches the specified value.
-
Method Details
-
consumeIf
Consumes the specified value if the predicate isnull or matches the specified value.- Type Parameters:
T- The type being consumed.- Parameters:
predicate- The predicate.consumer- The consumer.value- The value.
-
peek
Returns a function that prints the input value to stderr and returns it unchanged.Useful for debugging streams by inserting into a stream pipeline with
.map(peek()).Example:
list.stream() .map(peek()) .filter(x -> x !=
null ) .collect(Collectors.toList());- Type Parameters:
T- The type of value.- Returns:
- A function that prints and returns the value.
-
peek
Returns a function that prints the input value to stderr using a custom formatter and returns it unchanged.Useful for debugging streams by inserting into a stream pipeline with
.map(peek(...)).Example:
list.stream() .map(peek(
"Processing: {0}" , x -> x.getName())) .filter(x -> x !=null ) .collect(Collectors.toList());- Type Parameters:
T- The type of value.- Parameters:
message- A format string using{0}as placeholder for the formatted value.formatter- A function to extract/format the value for display.- Returns:
- A function that prints and returns the value.
-
test
Returnstrue if the specified predicate isnull or matches the specified value.- Type Parameters:
T- The type being tested.- Parameters:
predicate- The predicate.value- The value to test.- Returns:
true if the specified predicate isnull or matches the specified value.
-
distinctByKey
-