Class PredicateSupport
- java.lang.Object
-
- net.shibboleth.utilities.java.support.logic.PredicateSupport
-
public final class PredicateSupport extends Object
Helper class for constructing predicates. Especially useful for creating internal DSLs via Java's static method import mechanism.
-
-
Constructor Summary
Constructors Modifier Constructor Description privatePredicateSupport()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Predicate<Iterable<T>>allMatch(Predicate<T> target)Creates a predicate that checks that all elements of anIterablematches a given target predicate.static <T> Predicate<T>and(Iterable<? extends Predicate<? super T>> components)Returns a predicate that evaluates totrueif each of its components evaluates totrue.static <T> Predicate<T>and(Predicate<? super T>... components)Returns a predicate that evaluates totrueif each of its components evaluates totrue.static <T> Predicate<T>and(Predicate<? super T> first, Predicate<? super T> second)Returns a predicate that evaluates totrueif each of its components evaluates totrue.static <T> Predicate<Iterable<T>>anyMatch(Predicate<T> target)Creates a predicate that checks that any element in anIterablematches a given target predicate.static Predicate<CharSequence>caseInsensitiveMatch(String target)Creates a predicate that checks if a givenCharSequencematches a target string while ignoring case.static <T> Predicate<T>fromFunction(Function<T,Boolean> function, Predicate<T> defValue)Creates a predicate that applies a function to an input and returns its result, or a default value if null.static <T> Predicate<T>not(Predicate<T> predicate)Returns a predicate that evaluates totrueif the given predicate evaluates tofalse.static <T> Predicate<T>or(Iterable<? extends Predicate<? super T>> components)Returns a predicate that evaluates totrueif any one of its components evaluates totrue.static <T> Predicate<T>or(Predicate<? super T>... components)Returns a predicate that evaluates totrueif any one of its components evaluates totrue.static <T> Predicate<T>or(Predicate<? super T> first, Predicate<? super T> second)Returns a predicate that evaluates totrueif any one of its components evaluates totrue.
-
-
-
Method Detail
-
allMatch
@Nonnull public static <T> Predicate<Iterable<T>> allMatch(@Nonnull Predicate<T> target)
Creates a predicate that checks that all elements of anIterablematches a given target predicate.- Type Parameters:
T- type of objects in the iterable and that the target operates upon- Parameters:
target- predicate used to check each element in the iterable- Returns:
- the constructed predicate
-
anyMatch
@Nonnull public static <T> Predicate<Iterable<T>> anyMatch(@Nonnull Predicate<T> target)
Creates a predicate that checks that any element in anIterablematches a given target predicate.- Type Parameters:
T- type of objects in the iterable and that the target operates upon- Parameters:
target- predicate used to check each element in the iterable- Returns:
- the constructed predicate
-
caseInsensitiveMatch
@Nonnull public static Predicate<CharSequence> caseInsensitiveMatch(@Nonnull String target)
Creates a predicate that checks if a givenCharSequencematches a target string while ignoring case.- Parameters:
target- the target string to match against- Returns:
- the constructed predicate
-
fromFunction
@Nonnull public static <T> Predicate<T> fromFunction(@Nonnull Function<T,Boolean> function, @Nonnull Predicate<T> defValue)
Creates a predicate that applies a function to an input and returns its result, or a default value if null.- Type Parameters:
T- type of function input- Parameters:
function- function to apply to inputdefValue- default predicate to apply if function returns null- Returns:
- a predicate adapter
- Since:
- 7.4.0
-
not
@Nonnull public static <T> Predicate<T> not(@Nonnull Predicate<T> predicate)
Returns a predicate that evaluates totrueif the given predicate evaluates tofalse.- Type Parameters:
T- predicate input type- Parameters:
predicate- the predicate to negate- Returns:
- the negated predicate
-
and
@Nonnull public static <T> Predicate<T> and(@Nonnull Iterable<? extends Predicate<? super T>> components)
Returns a predicate that evaluates totrueif each of its components evaluates totrue. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponentsis empty, the returned predicate will always evaluate totrue.- Type Parameters:
T- predicate input type- Parameters:
components- the predicates to combine- Returns:
- the composite predicate
-
and
@SafeVarargs @Nonnull public static <T> Predicate<T> and(@Nonnull Predicate<? super T>... components)
Returns a predicate that evaluates totrueif each of its components evaluates totrue. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponentsis empty, the returned predicate will always evaluate totrue.- Type Parameters:
T- predicate input type- Parameters:
components- the predicates to combine- Returns:
- the composite predicate
-
and
@Nonnull public static <T> Predicate<T> and(@Nonnull Predicate<? super T> first, @Nonnull Predicate<? super T> second)
Returns a predicate that evaluates totrueif each of its components evaluates totrue. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponentsis empty, the returned predicate will always evaluate totrue.- Type Parameters:
T- predicate input type- Parameters:
first- the first predicatesecond- the second predicate- Returns:
- the composite predicate
-
or
@Nonnull public static <T> Predicate<T> or(@Nonnull Iterable<? extends Predicate<? super T>> components)
Returns a predicate that evaluates totrueif any one of its components evaluates totrue. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponentsis empty, the returned predicate will always evaluate tofalse.- Type Parameters:
T- predicate input type- Parameters:
components- the predicates to combine- Returns:
- the composite predicate
-
or
@SafeVarargs @Nonnull public static <T> Predicate<T> or(@Nonnull Predicate<? super T>... components)
Returns a predicate that evaluates totrueif any one of its components evaluates totrue. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponentsis empty, the returned predicate will always evaluate tofalse.- Type Parameters:
T- predicate input type- Parameters:
components- the predicates to combine- Returns:
- the composite predicate
-
or
@Nonnull public static <T> Predicate<T> or(@Nonnull Predicate<? super T> first, @Nonnull Predicate<? super T> second)
Returns a predicate that evaluates totrueif any one of its components evaluates totrue. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponentsis empty, the returned predicate will always evaluate tofalse.- Type Parameters:
T- predicate input type- Parameters:
first- the first predicatesecond- the second predicate- Returns:
- the composite predicate
-
-