Top Description Constructors Methods
io.vavr

public final Class Predicates

extends Object
Class Inheritance
Imports
io.vavr.collection.Iterator, .List, java.util.Objects, java.util.function.Predicate

Defines general-purpose predicates which are particularly useful when working with API.Match.
Author
Daniel Dietrich, Grzegorz Piwowarek

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
closure over tested object types
T
>
Predicate<T>

Returns:

A new Predicate
allOf
(Predicate<T>...
An array of predicates
predicates
)

A combinator that checks if all of the given predicates are satisfied.

public static <
closure over tested object types
T
>
Predicate<T>

Returns:

A new Predicate
anyOf
(Predicate<T>...
An array of predicates
predicates
)

A combinator that checks if at least one of the given predicates is satisfies.

public static <
tested object type
T
>
Predicate<Iterable<T>>

Returns:

A new Predicate
exists
(Predicate<? super T>
A Predicate that tests elements of type T
predicate
)

A combinator that checks if one or more elements of an Iterable satisfy the predicate.

public static <
tested object type
T
>
Predicate<Iterable<T>>

Returns:

A new Predicate
forAll
(Predicate<? super T>
A Predicate that tests elements of type T
predicate
)

A combinator that checks if all elements of an Iterable satisfy the predicate.

public static <
tested object type
T
>
Predicate<T>

Returns:

A new Predicate
instanceOf
(Class<? extends T>
A type
type
)

Creates a Predicate that tests, if an object is instance of the specified type.

public static <
tested object type
T
>
Predicate<T>

Returns:

A new Predicate
is
(T
A value, may be null
value
)

Creates a Predicate that tests, if an object is equal to the specified value using Objects#equals(Object, Object) for comparison.

public static <
closure over tested object types
T
>
Predicate<T>

Returns:

A new Predicate
isIn
(T...
an array of values of type 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.

public static <
tested object type
T
>
Predicate<T>

Returns:

A new Predicate
isNotNull
()

Creates a Predicate that tests, if an object is not null

Predicate<Integer> isNotNull = isNotNull();
isNotNull.test(0);    // true
isNotNull.test(null); // false
public static <
tested object type
T
>
Predicate<T>

Returns:

A new Predicate
isNull
()

Creates a Predicate that tests, if an object is null

Predicate<Integer> isNull = isNull();
isNull.test(null); // true
isNull.test(0);    // false
public static <
closure over tested object types
T
>
Predicate<T>

Returns:

A new Predicate
noneOf
(Predicate<T>...
An array of predicates
predicates
)

A combinator that checks if none of the given predicates is satisfied.

public static <
tested object type
T
>
Predicate<T>

Returns:

A new Predicate
not
(Predicate<? super T>
A Predicate that tests elements of type T
predicate
)

Negates a given Predicate.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Predicatesback to summary
private Predicates()

Method Detail

allOfback to summary
public static <T> Predicate<T> allOf(Predicate<T>... predicates)

A combinator that checks if all of the given 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
Parameters
<T>
closure over tested object types
predicates:Predicate<T>[]

An array of predicates

Returns:Predicate<T>

A new Predicate

Annotations
@SuppressWarnings:unchecked, varargs
@SafeVarargs
Exceptions
NullPointerException:
if predicates is null
anyOfback to summary
public static <T> Predicate<T> anyOf(Predicate<T>... predicates)

A combinator that checks if at least one of the given 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
Parameters
<T>
closure over tested object types
predicates:Predicate<T>[]

An array of predicates

Returns:Predicate<T>

A new Predicate

Annotations
@SuppressWarnings:unchecked, varargs
@SafeVarargs
Exceptions
NullPointerException:
if predicates is null
existsback to summary
public 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.

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
Parameters
<T>
tested object type
predicate:Predicate<? super T>

A Predicate that tests elements of type T

Returns:Predicate<Iterable<T>>

A new Predicate

Exceptions
NullPointerException:
if predicate is null
forAllback to summary
public static <T> Predicate<Iterable<T>> forAll(Predicate<? super T> predicate)

A combinator that checks if all elements of an 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
Parameters
<T>
tested object type
predicate:Predicate<? super T>

A Predicate that tests elements of type T

Returns:Predicate<Iterable<T>>

A new Predicate

Exceptions
NullPointerException:
if predicate is null
instanceOfback to summary
public static <T> Predicate<T> instanceOf(Class<? extends T> type)

Creates a 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
Parameters
<T>
tested object type
type:Class<? extends T>

A type

Returns:Predicate<T>

A new Predicate

Annotations
@GwtIncompatible
Exceptions
NullPointerException:
if type is null
isback to summary
public 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.

Predicate<Integer> isOne = is(1);
isOne.test(1); // true
isOne.test(2); // false
Parameters
<T>
tested object type
value:T

A value, may be null

Returns:Predicate<T>

A new Predicate

isInback to summary
public 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.

Predicate<Integer> isIn = isIn(1, 2, 3);
isIn.test(1); // true
isIn.test(0); // false
Parameters
<T>
closure over tested object types
values:T[]

an array of values of type T

Returns:Predicate<T>

A new Predicate

Annotations
@SuppressWarnings:unchecked, varargs
@SafeVarargs
Exceptions
NullPointerException:
if values is null
isNotNullback to summary
public static <T> Predicate<T> isNotNull()

Creates a Predicate that tests, if an object is not null

Predicate<Integer> isNotNull = isNotNull();
isNotNull.test(0);    // true
isNotNull.test(null); // false
Parameters
<T>
tested object type
Returns:Predicate<T>

A new Predicate

isNullback to summary
public static <T> Predicate<T> isNull()

Creates a Predicate that tests, if an object is null

Predicate<Integer> isNull = isNull();
isNull.test(null); // true
isNull.test(0);    // false
Parameters
<T>
tested object type
Returns:Predicate<T>

A new Predicate

noneOfback to summary
public static <T> Predicate<T> noneOf(Predicate<T>... predicates)

A combinator that checks if none of the given 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
Parameters
<T>
closure over tested object types
predicates:Predicate<T>[]

An array of predicates

Returns:Predicate<T>

A new Predicate

Annotations
@SuppressWarnings:unchecked, varargs
@SafeVarargs
Exceptions
NullPointerException:
if predicates is null
notback to summary
public static <T> Predicate<T> not(Predicate<? super T> predicate)

Negates a given 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
Parameters
<T>
tested object type
predicate:Predicate<? super T>

A Predicate that tests elements of type T

Returns:Predicate<T>

A new Predicate

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if predicate is null