P1
- parameter type 1P2
- parameter type 2@FunctionalInterface public interface Predicate2<P1,P2> extends java.util.function.BiPredicate<P1,P2>, Predicate1<ITuple2<? extends P1,? extends P2>>
Predicates can be chained to simulate boolean logic by
and(BiPredicate)
, or(BiPredicate)
,
xor(BiPredicate)
, and negate()
.
There is a general problem with combining types which don't
allow to use the above combination methods in all cases
similar to standard Java's logical expressions. The following
static methods of this interface may be used in all cases:
and(BiPredicate, BiPredicate)
,
or(BiPredicate, BiPredicate)
,
and xor(BiPredicate, BiPredicate)
.
Useful for start values in algorithms or as default values
are the two values returned by alwaysTrue()
(a predicate which always returns true
regardless
the argument applied to the BiPredicate.test(Object, Object)
method)
and alwaysFalse()
(same for false
).
Partial evaluation is possible via partialLeft(Object)
which allows to provide a fix first argument and
partialLeft(Object)
which provides a fix second argument.
Both return a Predicate1
with the type of the other
argument.
If a predicate with arguments in reverse order is required
reverseOrder()
comes to help.
Compared to the standard Java BiPredicate
this implementation has an
improved negate()
and provides optimized
alwaysTrue()
and alwaysFalse()
implementations plus an additional xor(BiPredicate)
.
It also allows to use a predicate where the arguments are expected
in reverse order
or to use this
2 argument predicate where only 1 argument is expected by providing
a fix value for either first
or the second
argument.
Predicate1
,
Predicate3
,
Predicate4
,
Predicate5
,
Predicate6
,
Predicate7
,
Predicate8
,
Predicate9
ALWAYS_FALSE, ALWAYS_TRUE
Modifier and Type | Method and Description |
---|---|
default <FR extends ITuple2<? extends P1,? extends P2>,FP> |
after1(java.util.function.Function<FP,FR> before)
Get a chained predicate which first applies the given function, then this predicate.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2> |
after2(java.util.function.BiFunction<FP1,FP2,FR> before)
Get a chained predicate which first applies the given 2-parameter function, then this predicate.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3> |
after3(Function3<FR,FP1,FP2,FP3> before)
Get a chained predicate which first applies the given 3-parameter function, then this predicate.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5> |
after5(Function5<FR,FP1,FP2,FP3,FP4,FP5> before)
Get a chained predicate which first applies the given 5-parameter function, then this predicate.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6> |
after6(Function6<FR,FP1,FP2,FP3,FP4,FP5,FP6> before)
Get a chained predicate which first applies the given 6-parameter function, then this predicate.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6,FP7> |
after7(Function7<FR,FP1,FP2,FP3,FP4,FP5,FP6,FP7> before)
Get a chained predicate which first applies the given 7-parameter function, then this one.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8> |
after8(Function8<FR,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8> before)
Get a chained predicate which first applies the given 8-parameter function, then this one.
|
default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8,FP9> |
after9(Function9<FR,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8,FP9> before)
Get a chained predicate which first applies the given 9-parameter function, then this one.
|
static <T1,T2> Predicate2<T1,T2> |
alwaysFalse()
Get a predicate which always evaluates to
false . |
static <T1,T2> Predicate2<T1,T2> |
alwaysTrue()
Get a predicate which always evaluates to
true . |
default Predicate2<P1,P2> |
and(java.util.function.BiPredicate<? super P1,? super P2> other)
Combine this and another predicate with logical and.
|
static <T1,T2> Predicate2<T1,T2> |
and(java.util.function.BiPredicate<? super T1,? super T2> pred1,
java.util.function.BiPredicate<? super T1,? super T2> pred2)
Get a predicate which is the combination of two predicates
with a logical and.
|
default boolean |
apply(P1 arg1,
P2 arg2)
Deprecated.
This has been renamed to
BiPredicate.test(Object, Object) to be more in sync with standard Java |
static <T> Predicate2<T,T> |
areIdentical()
Get a predicate which checks whether 2 objects represent the same object.
|
static <T1,T2> Predicate2<T1,T2> |
from(java.util.function.BiPredicate<T1,T2> bipred)
Make a standard
BiPredicate usable as a Predicate2 . |
static <T> Predicate2<T,T> |
isEqual()
Get a predicate which compares 2 objects for deep equality.
|
default Predicate2<P1,P2> |
negate()
Get the negation of this predicate.
|
default Predicate2<P1,P2> |
or(java.util.function.BiPredicate<? super P1,? super P2> other)
Combine this and another predicate with logical or.
|
static <T1,T2> Predicate2<T1,T2> |
or(java.util.function.BiPredicate<? super T1,? super T2> pred1,
java.util.function.BiPredicate<? super T1,? super T2> pred2)
Get a predicate which is the combination of two predicates
with a logical or.
|
default Predicate1<P2> |
partial1(P1 argument)
Get a partially applied predicate using a fix first argument.
|
default Predicate1<P1> |
partial2(P2 argument)
Get a partially applied predicate using a fix second argument.
|
default Predicate1<P2> |
partialLeft(P1 argument)
Get a partially applied predicate.
|
default Predicate1<P1> |
partialRight(P2 argument)
Get a partially applied predicate.
|
default Predicate2<P2,P1> |
reverseOrder()
Get a two argument predicate which expects the arguments in reverse order.
|
default boolean |
test(ITuple2<? extends P1,? extends P2> tuple2)
Expand a tuple into the arguments of this predicate.
|
default Predicate2<P1,P2> |
xor(java.util.function.BiPredicate<? super P1,? super P2> other)
Combine this and another predicate with logical exclusive or.
|
static <T1,T2> Predicate2<T1,T2> |
xor(java.util.function.BiPredicate<? super T1,? super T2> pred1,
java.util.function.BiPredicate<? super T1,? super T2> pred2)
Get a predicate which is the combination of two predicates
with a logical exclusive or.
|
default boolean test(@NotNull ITuple2<? extends P1,? extends P2> tuple2)
@Deprecated default boolean apply(P1 arg1, P2 arg2)
BiPredicate.test(Object, Object)
to be more in sync with standard Javaarg1
- function argument 1arg2
- function argument 2true
or false
@NotNull default Predicate2<P1,P2> and(@NotNull java.util.function.BiPredicate<? super P1,? super P2> other)
false
the other one is
not evaluated.
This method has a problem if either one of the argument types
pf the parameter is not a super class of this predicate's
parameter types. See and(BiPredicate, BiPredicate)
for such cases.
@NotNull default Predicate2<P1,P2> or(@NotNull java.util.function.BiPredicate<? super P1,? super P2> other)
true
the other one is
not evaluated.
This method has a problem if either one of the argument types
pf the parameter is not a super class of this predicate's
parameter types. See or(BiPredicate, BiPredicate)
for such cases.
@NotNull default Predicate2<P1,P2> xor(@NotNull java.util.function.BiPredicate<? super P1,? super P2> other)
This method has a problem if either one of the argument types
pf the parameter is not a super class of this predicate's
parameter types. See xor(BiPredicate, BiPredicate)
for such cases.
other
- other predicate to be chained with logical exclusive or@NotNull default Predicate2<P1,P2> negate()
@NotNull default Predicate1<P2> partialLeft(P1 argument)
argument
- value applied for first argument@NotNull default Predicate1<P2> partial1(P1 argument)
partialLeft(Object)
but more consistently named.argument
- value applied for first argument@NotNull default Predicate1<P1> partialRight(P2 argument)
argument
- value applied for second argument@NotNull default Predicate1<P1> partial2(P2 argument)
partialRight(Object)
but more consistently named.argument
- value applied for second argument@NotNull default Predicate2<P2,P1> reverseOrder()
@NotNull static <T1,T2> Predicate2<T1,T2> from(@NotNull java.util.function.BiPredicate<T1,T2> bipred)
BiPredicate
usable as a Predicate2
.T1
- type of first argumentT2
- type of second argumentbipred
- bipredicatePredicate2
view of the given bipredicatge@NotNull static <T1,T2> Predicate2<T1,T2> alwaysTrue()
true
.alwaysTrue
in interface Predicate1<ITuple2<? extends P1,? extends P2>>
T1
- type of first predicate parameterT2
- type of second predicate parametertrue
@NotNull static <T1,T2> Predicate2<T1,T2> alwaysFalse()
false
.alwaysFalse
in interface Predicate1<ITuple2<? extends P1,? extends P2>>
T1
- type of first predicate parameterT2
- type of second predicate parameterfalse
@NotNull static <T> Predicate2<T,T> isEqual()
This internally uses Objects.deepEquals(Object, Object)
for the equality test.
T
- object type@NotNull static <T> Predicate2<T,T> areIdentical()
T
- object type@NotNull static <T1,T2> Predicate2<T1,T2> and(@NotNull java.util.function.BiPredicate<? super T1,? super T2> pred1, @NotNull java.util.function.BiPredicate<? super T1,? super T2> pred2)
The result will use shortcut evaluation, so if this
predicate already returns false
the other one is
not evaluated.
T1
- resulting type of first argument,
which is the most extending type of both pred1
's
first argument type and pred2
's first argument type,
so if neither type is extending the
other this method will not compileT2
- resulting type of second argument, see <T1>
for the fine printpred1
- first predicatepred2
- second predicateand(BiPredicate)
@NotNull static <T1,T2> Predicate2<T1,T2> or(@NotNull java.util.function.BiPredicate<? super T1,? super T2> pred1, @NotNull java.util.function.BiPredicate<? super T1,? super T2> pred2)
The result will use shortcut evaluation, so if this
predicate already returns true
the other one is
not evaluated.
T1
- resulting type of first argument,
which is the most extending type of both pred1
's
first argument type and pred2
's first argument type,
so if neither type is extending the
other this method will not compileT2
- resulting type of second argument, see <T1>
for the fine printpred1
- first predicatepred2
- second predicateor(BiPredicate)
@NotNull static <T1,T2> Predicate2<T1,T2> xor(@NotNull java.util.function.BiPredicate<? super T1,? super T2> pred1, @NotNull java.util.function.BiPredicate<? super T1,? super T2> pred2)
The result will use shortcut evaluation, so if this
predicate already returns true
the other one is
not evaluated.
T1
- resulting type of first argument,
which is the most extending type of both pred1
's
first argument type and pred2
's first argument type,
so if neither type is extending the
other this method will not compileT2
- resulting type of second argument, see <T1>
for the fine printpred1
- first predicatepred2
- second predicatexor(BiPredicate)
@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP> Predicate1<FP> after1(@NotNull java.util.function.Function<FP,FR> before)
ITuple2
with matching parametric types
which are applied in their order to this predicate.FR
- function before
's return type, has to be a 2-tuple with matching typesFP
- function before
's parameter type, same for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2> Predicate2<FP1,FP2> after2(@NotNull java.util.function.BiFunction<FP1,FP2,FR> before)
ITuple2
with matching parametric types
which are applied in their order to this predicate.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, same for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3> Predicate3<FP1,FP2,FP3> after3(@NotNull Function3<FR,FP1,FP2,FP3> before)
ITuple2
with matching parametric types
which are applied in their order to this predicate.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, sane for returned predicateFP3
- function before
's third parameter type, sane for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5> Predicate5<FP1,FP2,FP3,FP4,FP5> after5(@NotNull Function5<FR,FP1,FP2,FP3,FP4,FP5> before)
ITuple2
with matching parametric types
which are applied in their order to this function.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, sane for returned predicateFP3
- function before
's third parameter type, sane for returned predicateFP4
- function before
's fourth parameter type, sane for returned predicateFP5
- function before
's fifth parameter type, sane for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6> Predicate6<FP1,FP2,FP3,FP4,FP5,FP6> after6(@NotNull Function6<FR,FP1,FP2,FP3,FP4,FP5,FP6> before)
ITuple2
with matching parametric types
which are applied in their order to this function.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, sane for returned predicateFP3
- function before
's third parameter type, sane for returned predicateFP4
- function before
's fourth parameter type, sane for returned predicateFP5
- function before
's fifth parameter type, sane for returned predicateFP6
- function before
's sixth parameter type, sane for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6,FP7> Predicate7<FP1,FP2,FP3,FP4,FP5,FP6,FP7> after7(@NotNull Function7<FR,FP1,FP2,FP3,FP4,FP5,FP6,FP7> before)
ITuple2
with matching parametric types
which are applied in their order to this predicate.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, sane for returned predicateFP3
- function before
's third parameter type, sane for returned predicateFP4
- function before
's fourth parameter type, sane for returned predicateFP5
- function before
's fifth parameter type, sane for returned predicateFP6
- function before
's sixth parameter type, sane for returned predicateFP7
- function before
's seventh parameter type, sane for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8> Predicate8<FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8> after8(@NotNull Function8<FR,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8> before)
ITuple2
with matching parametric types
which are applied in their order to this predicate.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, sane for returned predicateFP3
- function before
's third parameter type, sane for returned predicateFP4
- function before
's fourth parameter type, sane for returned predicateFP5
- function before
's fifth parameter type, sane for returned predicateFP6
- function before
's sixth parameter type, sane for returned predicateFP7
- function before
's seventh parameter type, sane for returned predicateFP8
- function before
's seventh parameter type, sane for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible@NotNull default <FR extends ITuple2<? extends P1,? extends P2>,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8,FP9> Predicate9<FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8,FP9> after9(@NotNull Function9<FR,FP1,FP2,FP3,FP4,FP5,FP6,FP7,FP8,FP9> before)
ITuple2
with matching parametric types
which are applied in their order to this predicate.FR
- function before
's return type, has to be a 2-tuple with matching typesFP1
- function before
's first parameter type, sane for returned predicateFP2
- function before
's second parameter type, sane for returned predicateFP3
- function before
's third parameter type, sane for returned predicateFP4
- function before
's fourth parameter type, sane for returned predicateFP5
- function before
's fifth parameter type, sane for returned predicateFP6
- function before
's sixth parameter type, sane for returned predicateFP7
- function before
's seventh parameter type, sane for returned predicateFP8
- function before
's seventh parameter type, sane for returned predicateFP9
- function before
's ninth parameter type, sane for returned predicatebefore
- function to apply first, has to return a non-null
result so unpacking the parameters
from the tuple is possible