Package eu.bandm.tools.util.java
Class BiPredicates
java.lang.Object
eu.bandm.tools.util.java.BiPredicates
Library of constants and operations for working with binary predicates.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,
B> BiPredicate <A, B> all()
Returns a binary predicate that is true for all arguments.static <A,
B> BiPredicate <A, B> complement
(BiPredicate<? super A, ? super B> pred) Returns a binary predicate that is true for all arguments where the given predicate is false and vice versa.static <A,
B> BiPredicate <Collection<? extends A>, Collection<? extends B>> cover
(BiPredicate<A, B> rel) Returns a binary predicate that is true for two collections if and only if for every element on either side there is an element on the other side such that the given binary predicate is true.static <A,
B> BiPredicate <A, B> eq()
Returns a binary predicate that is true if and only if the arguments are identical.static <A extends Comparable<? super A>>
BiPredicate<A, A> equal()
Returns a binary predicate that is true if and only if the first argument is equal to the second, according to the natural order.static <A> BiPredicate
<A, A> equal
(Comparator<? super A> order) Returns a binary predicate that is true if and only if the first argument is equal to the second, according to the given order.static <A,
B> BiPredicate <A, B> equals()
Deprecated.static <A extends Comparable<? super A>>
BiPredicate<A, A> greater()
Returns a binary predicate that is true if and only if the first argument is greater than the second, according to the natural order.static <A> BiPredicate
<A, A> greater
(Comparator<? super A> order) Returns a binary predicate that is true if and only if the first argument is greater than the second, according to the given order.static <A extends Comparable<? super A>>
BiPredicate<A, A> Returns a binary predicate that is true if and only if the first argument is greater than or equal to the second, according to the natural order.static <A> BiPredicate
<A, A> greaterOrEqual
(Comparator<? super A> order) Returns a binary predicate that is true if and only if the first argument is greater than or equal to the second, according to the given order.static <A,
B> BiPredicate <A, B> intersection
(Collection<? extends BiPredicate<? super A, ? super B>> rels) Returns a predicate that is true for all arguments where all of the given predicates are.static <A,
B> BiPredicate <B, A> inverse
(BiPredicate<? super A, ? super B> pred) Returns a binary predicate that is true for all arguments where the given predicate is for the flipped pair of arguments.static <A,
B> BiPredicate <A, A> kernel
(Function<? super A, ? extends B> fun, BiPredicate<? super B, ? super B> pred) Returns a binary predicate that is true if and only if the given binary predicate is true for the results of the given function.static <A,
B, C, D>
BiPredicate<A, C> kernel
(Function<? super A, ? extends B> left, Function<? super C, ? extends D> right, BiPredicate<? super B, ? super D> pred) Returns a binary predicate that is true if and only if the given binary predicate is true for the results of the two given functions.static <A extends Comparable<? super A>>
BiPredicate<A, A> less()
Returns a binary predicate that is true if and only if the first argument is less than the second, according to the natural order.static <A> BiPredicate
<A, A> less
(Comparator<? super A> order) Returns a binary predicate that is true if and only if the first argument is less than the second, according to the given order.static <A extends Comparable<? super A>>
BiPredicate<A, A> Returns a binary predicate that is true if and only if the first argument is less than or equal to the second, according to the natural order.static <A> BiPredicate
<A, A> lessOrEqual
(Comparator<? super A> order) Returns a binary predicate that is true if and only if the first argument is less than or equal to the second, according to the given order.static <A,
B> BiPredicate <A, B> none()
Returns a binary predicate that is false for all arguments.static <A,
B> BiPredicate <A, B> union
(Collection<? extends BiPredicate<? super A, ? super B>> rels) Returns a predicate that is true for all arguments where any of the given predicates is.
-
Method Details
-
all
Returns a binary predicate that is true for all arguments.- Type Parameters:
A
- the first argument typeB
- the second argument type- Returns:
- a binary predicate that is true for all arguments, including null
-
none
Returns a binary predicate that is false for all arguments.- Type Parameters:
A
- the first argument typeB
- the second argument type- Returns:
- a binary predicate that is false for all arguments, including null
-
eq
Returns a binary predicate that is true if and only if the arguments are identical.- Type Parameters:
A
- the first argument typeB
- the second argument type- Returns:
- a binary predicate that true if and only if the arguments
are identical according to
==
-
equals
Deprecated.useObject::equals
insteadReturns a binary predicate that is true if and only if the arguments are equal.- Type Parameters:
A
- the first argument typeB
- the second argument type- Returns:
- a binary predicate that true if and only if the arguments
are equal according to
Objects.equals(Object, Object)
-
lessOrEqual
Returns a binary predicate that is true if and only if the first argument is less than or equal to the second, according to the given order.- Type Parameters:
A
- the argument type- Parameters:
order
- a comparator that specifies the desired order- Returns:
- a binary predicate that true if and only if the first
argument is less than or equal to the second according to
Comparator.compare(T, T)
- Throws:
NullPointerException
- iforder
is null
-
lessOrEqual
Returns a binary predicate that is true if and only if the first argument is less than or equal to the second, according to the natural order.- Type Parameters:
A
- the argument type- Returns:
- a binary predicate that true if and only if the first
argument is less than or equal to the second according to
Comparable.compareTo(T)
-
less
Returns a binary predicate that is true if and only if the first argument is less than the second, according to the given order.- Type Parameters:
A
- the argument type- Parameters:
order
- a comparator that specifies the desired order- Returns:
- a binary predicate that true if and only if the first
argument is less than the second according to
Comparator.compare(T, T)
- Throws:
NullPointerException
- iforder
is null
-
less
Returns a binary predicate that is true if and only if the first argument is less than the second, according to the natural order.- Type Parameters:
A
- the argument type- Returns:
- a binary predicate that true if and only if the first
argument is less than the second according to
Comparable.compareTo(T)
-
equal
Returns a binary predicate that is true if and only if the first argument is equal to the second, according to the natural order.- Type Parameters:
A
- the argument type- Returns:
- a binary predicate that true if and only if the first
argument is equal to the second according to
Comparable.compareTo(T)
-
greater
Returns a binary predicate that is true if and only if the first argument is greater than the second, according to the natural order.- Type Parameters:
A
- the argument type- Returns:
- a binary predicate that true if and only if the first
argument is greater than the second according to
Comparable.compareTo(T)
-
greaterOrEqual
Returns a binary predicate that is true if and only if the first argument is greater than or equal to the second, according to the natural order.- Type Parameters:
A
- the argument type- Returns:
- a binary predicate that true if and only if the first
argument is greater than or equal to the second according to
Comparable.compareTo(T)
-
greaterOrEqual
Returns a binary predicate that is true if and only if the first argument is greater than or equal to the second, according to the given order.- Type Parameters:
A
- the argument type- Parameters:
order
- a comparator that specifies the desired order- Returns:
- a binary predicate that true if and only if the first
argument is greater than or equal to the second according to
Comparator.compare(T, T)
- Throws:
NullPointerException
- iforder
is null
-
greater
Returns a binary predicate that is true if and only if the first argument is greater than the second, according to the given order.- Type Parameters:
A
- the argument type- Parameters:
order
- a comparator that specifies the desired order- Returns:
- a binary predicate that true if and only if the first
argument is greater than the second according to
Comparator.compare(T, T)
- Throws:
NullPointerException
- iforder
is null
-
equal
Returns a binary predicate that is true if and only if the first argument is equal to the second, according to the given order.- Type Parameters:
A
- the argument type- Parameters:
order
- a comparator that specifies the desired order- Returns:
- a binary predicate that true if and only if the first
argument is equal to the second according to
Comparator.compare(T, T)
- Throws:
NullPointerException
- iforder
is null
-
inverse
Returns a binary predicate that is true for all arguments where the given predicate is for the flipped pair of arguments.- Type Parameters:
A
- the first argument typeB
- the second argument type- Parameters:
pred
- a binary predicate- Returns:
- a binary predicate that is true for
(a, b)
if and only ifpred
is true for(b, a)
- Throws:
NullPointerException
- ifpred
is null
-
complement
Returns a binary predicate that is true for all arguments where the given predicate is false and vice versa.- Type Parameters:
A
- the first argument typeB
- the second argument type- Parameters:
pred
- a binary predicate- Returns:
- a binary predicate that is true for all arguments where
pred
is false and vice versa - Throws:
NullPointerException
- ifpred
is null
-
kernel
public static <A,B, BiPredicate<A,C, D> C> kernel(Function<? super A, ? extends B> left, Function<? super C, ? extends D> right, BiPredicate<? super B, ? super D> pred) Returns a binary predicate that is true if and only if the given binary predicate is true for the results of the two given functions.- Type Parameters:
A
- the first argument type of the resulting predicateB
- the second argument type of the resulting predicateC
- the first argument type of the given predicateD
- the second argument type of the given predicate- Parameters:
left
- the function used to transform the first argumentright
- the function used to transform the second argumentpred
- the binary predicate to apply to the results- Returns:
- a binary predicate that is true for
(a, b)
if and only ifpred
is true for(left(a), right(b))
- Throws:
NullPointerException
- if any ofleft
,right
,pred
is null
-
kernel
public static <A,B> BiPredicate<A,A> kernel(Function<? super A, ? extends B> fun, BiPredicate<? super B, ? super B> pred) Returns a binary predicate that is true if and only if the given binary predicate is true for the results of the given function.- Type Parameters:
A
- the argument type of the resulting predicateB
- the argument type of the given predicate- Parameters:
fun
- the function used to transform the argumentspred
- the binary predicate to apply to the results- Returns:
- a binary predicate that is true for
(a, b)
if and only ifpred
is true for(fun(a), fun(b))
- Throws:
NullPointerException
- if any offun
,pred
is null
-
cover
public static <A,B> BiPredicate<Collection<? extends A>,Collection<? extends B>> cover(BiPredicate<A, B> rel) Returns a binary predicate that is true for two collections if and only if for every element on either side there is an element on the other side such that the given binary predicate is true.- Type Parameters:
A
- the first argument type of the given predicateB
- the second argument type of the given predicate- Parameters:
rel
- the given binary predicate- Returns:
- a binary predicate that holds for
(as, bs)
if and only if for every elementa
inas
there is an elementb
inbs
such thatrel
is true for(a, b)
, and vice versa - Throws:
NullPointerException
- ifrel
is null
-
union
public static <A,B> BiPredicate<A,B> union(Collection<? extends BiPredicate<? super A, ? super B>> rels) Returns a predicate that is true for all arguments where any of the given predicates is.- Type Parameters:
A
- the first argument typeB
- the second argument type- Parameters:
rels
- a collection of binary predicates- Returns:
- a predicate that is true for
(a, b)
if and only if there is a binary predicater
inrels
for which this is the case - Throws:
NullPointerException
- ifrels
or any element of it is null
-
intersection
public static <A,B> BiPredicate<A,B> intersection(Collection<? extends BiPredicate<? super A, ? super B>> rels) Returns a predicate that is true for all arguments where all of the given predicates are.- Type Parameters:
A
- the first argument typeB
- the second argument type- Parameters:
rels
- a collection of binary predicates- Returns:
- a predicate that is true for
(a, b)
if and only if this is the case for all binary predicatesr
inrels
- Throws:
NullPointerException
- ifrels
or any element of it is null
-
Object::equals
instead