Modifier and Type | Method and Description |
---|---|
static <T> Predicate<T> |
allOf(Predicate<T>... predicates)
A combinator that checks if all of the given
predicates are satisfied. |
static <T> Predicate<T> |
anyOf(Predicate<T>... predicates)
A combinator that checks if at least one of the given
predicates is satisfies. |
static <T> Predicate<Iterable<T>> |
exists(Predicate<? super T> predicate)
A combinator that checks if one or more elements of an
Iterable satisfy the predicate . |
static <T> Predicate<Iterable<T>> |
forAll(Predicate<? super T> predicate)
A combinator that checks if all elements of an
Iterable satisfy the predicate . |
static <T> Predicate<T> |
instanceOf(Class<? extends T> type)
Creates a
Predicate that tests, if an object is instance of the specified type . |
static <T> Predicate<T> |
is(T value)
Creates a
Predicate that tests, if an object is equal to the specified value using
Objects.equals(Object, Object) for comparison. |
static <T> Predicate<T> |
isIn(T... values)
Creates a
Predicate that tests, if an object is equal to at least one of the specified values
using Objects.equals(Object, Object) for comparison. |
static <T> Predicate<T> |
isNotNull()
Creates a
Predicate that tests, if an object is not null |
static <T> Predicate<T> |
isNull()
Creates a
Predicate that tests, if an object is null |
static <T> Predicate<T> |
noneOf(Predicate<T>... predicates)
A combinator that checks if none of the given
predicates is satisfied. |
static <T> Predicate<T> |
not(Predicate<? super T> predicate)
Negates a given
Predicate . |
@SafeVarargs public static <T> Predicate<T> allOf(Predicate<T>... predicates)
predicates
are satisfied.
By definition allOf
is satisfied if the given predicates
are empty.
Predicate<Integer> isGreaterThanOne = i -> i > 1;
Predicate<Integer> isGreaterThanTwo = i -> i > 2;
allOf().test(0); // true
allOf(isGreaterThanOne, isGreaterThanTwo).test(3); // true
allOf(isGreaterThanOne, isGreaterThanTwo).test(2); // false
T
- closure over tested object typespredicates
- An array of predicatesPredicate
NullPointerException
- if predicates
is null@SafeVarargs public static <T> Predicate<T> anyOf(Predicate<T>... predicates)
predicates
is satisfies.
Predicate<Integer> isGreaterThanOne = i -> i > 1;
Predicate<Integer> isGreaterThanTwo = i -> i > 2;
anyOf().test(0); // false
anyOf(isGreaterThanOne, isGreaterThanTwo).test(3); // true
anyOf(isGreaterThanOne, isGreaterThanTwo).test(2); // true
anyOf(isGreaterThanOne, isGreaterThanTwo).test(1); // false
T
- closure over tested object typespredicates
- An array of predicatesPredicate
NullPointerException
- if predicates
is nullpublic static <T> Predicate<Iterable<T>> exists(Predicate<? super T> predicate)
Iterable
satisfy the predicate
.
Predicate<Integer> isGreaterThanOne = i -> i > 1;
Predicate<Iterable<Integer>> existsGreaterThanOne = exists(isGreaterThanOne);
existsGreaterThanOne.test(List.of(0, 1, 2)); // true
existsGreaterThanOne.test(List.of(0, 1)); // false
T
- tested object typepredicate
- A Predicate
that tests elements of type T
Predicate
NullPointerException
- if predicate
is nullpublic static <T> Predicate<Iterable<T>> forAll(Predicate<? super T> predicate)
Iterable
satisfy the predicate
.
Predicate<Integer> isGreaterThanOne = i -> i > 1;
Predicate<Iterable<Integer>> forAllGreaterThanOne = forAll(isGreaterThanOne);
forAllGreaterThanOne.test(List.of(0, 1, 2)); // false
forAllGreaterThanOne.test(List.of(2, 3, 4)); // true
T
- tested object typepredicate
- A Predicate
that tests elements of type T
Predicate
NullPointerException
- if predicate
is null@GwtIncompatible public static <T> Predicate<T> instanceOf(Class<? extends T> type)
Predicate
that tests, if an object is instance of the specified type
.
Predicate<Object> instanceOfNumber = instanceOf(Number.class);
instanceOfNumber.test(1); // true
instanceOfNumber.test("1"); // false
T
- tested object typetype
- A typePredicate
NullPointerException
- if type
is nullpublic static <T> Predicate<T> is(T value)
Predicate
that tests, if an object is equal to the specified value
using
Objects.equals(Object, Object)
for comparison.
Predicate<Integer> isOne = is(1);
isOne.test(1); // true
isOne.test(2); // false
T
- tested object typevalue
- A value, may be nullPredicate
@SafeVarargs public static <T> Predicate<T> isIn(T... values)
Predicate
that tests, if an object is equal to at least one of the specified values
using Objects.equals(Object, Object)
for comparison.
Predicate<Integer> isIn = isIn(1, 2, 3);
isIn.test(1); // true
isIn.test(0); // false
T
- closure over tested object typesvalues
- an array of values of type TPredicate
NullPointerException
- if values
is nullpublic static <T> Predicate<T> isNotNull()
Predicate
that tests, if an object is not null
Predicate<Integer> isNotNull = isNotNull();
isNotNull.test(0); // true
isNotNull.test(null); // false
T
- tested object typePredicate
public static <T> Predicate<T> isNull()
Predicate
that tests, if an object is null
Predicate<Integer> isNull = isNull();
isNull.test(null); // true
isNull.test(0); // false
T
- tested object typePredicate
@SafeVarargs public static <T> Predicate<T> noneOf(Predicate<T>... predicates)
predicates
is satisfied.
Naturally noneOf
is satisfied if the given predicates
are empty.
Predicate<Integer> isGreaterThanOne = i -> i > 1;
Predicate<Integer> isGreaterThanTwo = i -> i > 2;
noneOf().test(0); // true
noneOf(isGreaterThanOne, isGreaterThanTwo).test(1); // true
noneOf(isGreaterThanOne, isGreaterThanTwo).test(2); // false
T
- closure over tested object typespredicates
- An array of predicatesPredicate
NullPointerException
- if predicates
is nullpublic static <T> Predicate<T> not(Predicate<? super T> predicate)
Predicate
.
// negates a method reference
Predicate<String> isNotNull1 = not(Objects::isNull);
isNotNull1.test(""); // true
isNotNull1.test(null); // false
// negates a predicate instance
Predicate<String> isNotNull2 = not(Predicates.isNull());
isNotNull2.test(""); // true
isNotNull2.test(null); // false
T
- tested object typepredicate
- A Predicate
that tests elements of type T
Predicate
NullPointerException
- if predicate
is nullCopyright © 2021. All Rights Reserved.