Package net.shibboleth.shared.logic
Class PredicateSupport
java.lang.Object
net.shibboleth.shared.logic.PredicateSupport
Helper class for constructing predicates. Especially useful for creating internal DSLs via Java's static method
import mechanism.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a predicate that checks that all elements of anIterablematches a given target predicate.static <T> Predicate<T>Creates a predicate that is always false.static <T> Predicate<T>Creates a predicate that is always true.static <T> Predicate<T>Returns a predicate that evaluates totrueif each of its components evaluates totrue.static <T> Predicate<T>Returns a predicate that evaluates totrueif each of its components evaluates totrue.static <T> Predicate<T>Returns a predicate that evaluates totrueif each of its components evaluates totrue.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>constant(boolean flag) Returns a predicate that returns the value of an input parameter.static <T> Predicate<T>fromFunction(Function<T, Boolean> function, Predicate<? super T> defValue) Creates a predicate that applies a function to an input and returns its result, or a default value if null.static <T> booleanisAlwaysFalse(Predicate<T> p) Returns true iff the input parameter is the result of callingalwaysFalse().static <T> booleanisAlwaysTrue(Predicate<T> p) Returns true iff the input parameter is the result of callingalwaysTrue().static <T> Predicate<T>Returns a predicate that evaluates totrueif the given predicate evaluates tofalse.static <T> Predicate<T>Returns a predicate that evaluates totrueif any one of its components evaluates totrue.static <T> Predicate<T>Returns a predicate that evaluates totrueif any one of its components evaluates totrue.static <T> Predicate<T>Returns a predicate that evaluates totrueif any one of its components evaluates totrue.
-
Constructor Details
-
PredicateSupport
private PredicateSupport()Constructor.
-
-
Method Details
-
alwaysTrue
Creates a predicate that is always true.- Type Parameters:
T- input type- Returns:
- the constructed predicate
- Since:
- 9.0.0
-
alwaysFalse
Creates a predicate that is always false.- Type Parameters:
T- input type- Returns:
- the constructed predicate
- Since:
- 9.0.0
-
isAlwaysTrue
Returns true iff the input parameter is the result of callingalwaysTrue().- Type Parameters:
T- predicate type- Parameters:
p- candidate to test- Returns:
- true iff the input parameter is the result of calling
alwaysTrue(). - Since:
- 9.0.0
-
isAlwaysFalse
Returns true iff the input parameter is the result of callingalwaysFalse().- Type Parameters:
T- predicate type- Parameters:
p- candidate to test- Returns:
- true iff the input parameter is the result of calling
alwaysFalse(). - Since:
- 9.0.0
-
constant
Returns a predicate that returns the value of an input parameter.- Type Parameters:
T- input type- Parameters:
flag- flag controlling result of predicate- Returns:
- the newly constructed predicate
- Since:
- 9.0.0
-
allMatch
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
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
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<? super 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
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
-