Package ratpack.func
Interface Predicate<T>
-
- Type Parameters:
T
- the type of object “tested” by the predicate
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Predicate<T>
A function that returnstrue
orfalse
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <T> Predicate<T>
alwaysFalse()
A predicate that always returnsfalse
, regardless of the input object.static <T> Predicate<T>
alwaysTrue()
A predicate that always returnstrue
, regardless of the input object.boolean
apply(T t)
Tests the given value.static <T> Predicate<T>
from(Predicate<T> predicate)
Creates a predicate from a JDK predicate.static <T> Predicate<T>
fromGuava(com.google.common.base.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 com.google.common.base.Predicate<T>
toGuavaPredicate()
Creates a GuavaPredicate
from this predicate.default Predicate<T>
toPredicate()
Creates a JDKPredicate
from this predicate.
-
-
-
Method Detail
-
apply
boolean apply(T t) throws Exception
Tests the given value.- Parameters:
t
- the value to “test”- Returns:
true
if the predicate applied, otherwisefalse
- Throws:
Exception
- any
-
toPredicate
default Predicate<T> toPredicate()
Creates a JDKPredicate
from this predicate.Any exceptions thrown by
this
action will be unchecked viaExceptions.uncheck(Throwable)
and rethrown.- Returns:
- this function as a JDK style predicate.
-
toGuavaPredicate
default com.google.common.base.Predicate<T> toGuavaPredicate()
Creates a GuavaPredicate
from this predicate.Any exceptions thrown by
this
action will be unchecked viaExceptions.uncheck(Throwable)
and rethrown.- Returns:
- this function as a Guava style predicate.
-
from
static <T> Predicate<T> from(Predicate<T> predicate)
Creates a predicate from a JDK predicate.- Type Parameters:
T
- the type of object this predicate tests- Parameters:
predicate
- the JDK predicate- Returns:
- the given JDK predicate as a predicate
-
fromGuava
static <T> Predicate<T> fromGuava(com.google.common.base.Predicate<T> predicate)
Creates a predicate from a Guava predicate.- Type Parameters:
T
- the type of object this predicate tests- Parameters:
predicate
- the Guava predicate- Returns:
- the given Guava predicate as a predicate
-
alwaysTrue
static <T> Predicate<T> alwaysTrue()
A predicate that always returnstrue
, regardless of the input object.- Type Parameters:
T
- the type of input object- Returns:
- a predicate that always returns
true
- Since:
- 1.1
-
alwaysFalse
static <T> Predicate<T> alwaysFalse()
A predicate that always returnsfalse
, regardless of the input object.- Type Parameters:
T
- the type of input object- Returns:
- a predicate that always returns
false
- Since:
- 1.1
-
function
default <O> Function<T,O> function(O onTrue, O onFalse)
Creates a function the returns one of the given values.- Type Parameters:
O
- the output value- Parameters:
onTrue
- the value to return if the predicate appliesonFalse
- the value to return if the predicate does not apply- Returns:
- a function
- Since:
- 1.5
-
-