T
- the type of object “tested” by the predicate@FunctionalInterface
public interface Predicate<T>
true
or false
for a value.
This type serves the same purpose as the JDK's Predicate
, but allows throwing checked exceptions.
It contains methods for bridging to and from the JDK type.
Modifier and Type | Field and Description |
---|---|
static Predicate<java.lang.Object> |
FALSE
A predicate that always returns
false , regardless of the input object. |
static Predicate<java.lang.Object> |
TRUE
A predicate that always returns
true , regardless of the input object. |
Modifier and Type | Method and Description |
---|---|
static <T> Predicate<T> |
alwaysFalse()
A predicate that always returns
false , regardless of the input object. |
static <T> Predicate<T> |
alwaysTrue()
A predicate that always returns
true , regardless of the input object. |
boolean |
apply(T t)
Tests the given value.
|
static <T> Predicate<T> |
from(java.util.function.Predicate<T> predicate)
Creates a predicate from a JDK predicate.
|
static <T> Predicate<T> |
fromGuava(Predicate<T> predicate)
Creates a predicate from a Guava predicate.
|
default <O> Function<T,O> |
function(O onTrue,
O onFalse)
Creates a function the returns one of the given values.
|
default Predicate<T> |
toGuavaPredicate()
Creates a Guava
Predicate from this predicate. |
default java.util.function.Predicate<T> |
toPredicate()
Creates a JDK
Predicate from this predicate. |
static final Predicate<java.lang.Object> TRUE
true
, regardless of the input object.static final Predicate<java.lang.Object> FALSE
false
, regardless of the input object.boolean apply(T t) throws java.lang.Exception
t
- the value to “test”true
if the predicate applied, otherwise false
java.lang.Exception
- anydefault java.util.function.Predicate<T> toPredicate()
Predicate
from this predicate.
Any exceptions thrown by this
action will be unchecked via Exceptions.uncheck(Throwable)
and rethrown.
default Predicate<T> toGuavaPredicate()
Predicate
from this predicate.
Any exceptions thrown by this
action will be unchecked via Exceptions.uncheck(Throwable)
and rethrown.
static <T> Predicate<T> from(java.util.function.Predicate<T> predicate)
T
- the type of object this predicate testspredicate
- the JDK predicatestatic <T> Predicate<T> fromGuava(Predicate<T> predicate)
T
- the type of object this predicate testspredicate
- the Guava predicatestatic <T> Predicate<T> alwaysTrue()
true
, regardless of the input object.T
- the type of input objecttrue
static <T> Predicate<T> alwaysFalse()
false
, regardless of the input object.T
- the type of input objectfalse
default <O> Function<T,O> function(O onTrue, O onFalse)
O
- the output valueonTrue
- the value to return if the predicate appliesonFalse
- the value to return if the predicate does not apply