Package eu.bandm.tools.util.java
Class Predicates
java.lang.Object
eu.bandm.tools.util.java.Predicates
Library of constants and operations for working with predicates.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> Predicate
<A> Returns the logical conjunction of the given predicates.static <A> Predicate
<A> bottom()
Returns a predicate which never matches.Iverson bracket.characteristic
(Predicate<A> pred) Returns a function which delivers the test result of the given predicate.static <A> void
classify
(Predicate<? super A> pred, Collection<? extends A> in, Collection<? super A> positive, Collection<? super A> negative) Sorts all given objets into one of two collections, whether the predicate applies or not.static <A> Predicate
<A> eq
(A a) Returns a predicate which matches only the given object.static <A> Predicate
<A> Returns a predicate which matches all objects which are equal to the given object.static <A extends Comparable<? super A>>
Predicate<A> geq
(A a) Returns a predicate which matches all objects greater or equal the given object.static <A extends Comparable<? super A>>
Predicate<A> gt
(A a) Returns a predicate which matches all objects greater the given object.static <A> Predicate
<A> instanceOf
(Class<?> c) Returns a predicate which matches all instances of the given class.static <A> Predicate
<A> Returns a predicate which matches the keys contained in the given map.static <A extends Comparable<? super A>>
Predicate<A> leq
(A a) Returns a predicate which matches all objects less or equal the given object.static <A extends Comparable<? super A>>
Predicate<A> lt
(A a) Returns a predicate which matches all objects less than the given object.static <A> Predicate
<A> memberOf
(Collection<? super A> c) Returns a predicate which matches the members of the given collection.static <A> Predicate
<A> Returns the logical inversion of the given predicate.static <A> Predicate
<A> notNull()
Returns a predicate which matches every non-null argument.static <A> Predicate
<A> Returns the logical disjunction of the given predicates.static <A> Predicate
<A> Returns a predicate which tests the given boolean function.static <A> Predicate
<A> top()
Returns a predicate which always matches.static <A,
B> Predicate <A> Returns a predicate which is tested only for instances of the given class.static <A> Predicate
<A> Returns the logical exclusive disjunction of the given predicates.
-
Method Details
-
top
Returns a predicate which always matches.- Type Parameters:
A
- the domain of the predicate.- Returns:
- a predicate which always matches.
-
bottom
Returns a predicate which never matches.- Type Parameters:
A
- the domain of the predicate.- Returns:
- a predicate which never matches.
-
notNull
Returns a predicate which matches every non-null argument.- Type Parameters:
A
- the domain of the predicate. (Should have the form@Opt B
for this method to be sensible.)- Returns:
- a predicate which matches every non-null argument.
-
not
Returns the logical inversion of the given predicate. The result will match ever object the given predicate does not match, et vice versa.- Type Parameters:
A
- the domain of the predicate.- Parameters:
p
- the predicate to negate.- Returns:
- the logical inversion of the given predicate.
-
and
Returns the logical conjunction of the given predicates. The result will match every object both given predicate match.- Type Parameters:
A
- the domain of the predicates.- Parameters:
p
- the first predicate.q
- the second predicate.- Returns:
- the logical conjunction of the given predicates.
-
or
Returns the logical disjunction of the given predicates. The result will match every object at least one of the given predicates match. The test function of both given predicates may not be called.- Type Parameters:
A
- the domain of the predicates.- Parameters:
p
- the first predicate.q
- the second predicate.- Returns:
- the logical disjunction of the given predicates.
-
xor
Returns the logical exclusive disjunction of the given predicates. The result will match every object exactly one of the given predicates match. The test function of both given predicates are called.- Type Parameters:
A
- the domain of the predicates.- Parameters:
p
- the first predicate.q
- the second predicate.- Returns:
- the logical exclusive disjunction of the given predicates.
-
eq
Returns a predicate which matches only the given object. The identity is tested by the==
operator.- Type Parameters:
A
- the domain of the predicate.- Parameters:
a
- the object to test for.- Returns:
- a predicate which matches only the given object.
-
leq
Returns a predicate which matches all objects less or equal the given object.- Type Parameters:
A
- the domain of the predicate.- Parameters:
a
- the object to compare with.- Returns:
- a predicate which matches all objects less or equal the given object.
-
lt
Returns a predicate which matches all objects less than the given object.- Type Parameters:
A
- the domain of the predicate.- Parameters:
a
- the object to compare with.- Returns:
- a predicate which matches all objects less or equal the given object.
-
geq
Returns a predicate which matches all objects greater or equal the given object.- Type Parameters:
A
- the domain of the predicate.- Parameters:
a
- the object to compare with.- Returns:
- a predicate which matches all objects greater or equal the given object.
-
gt
Returns a predicate which matches all objects greater the given object.- Type Parameters:
A
- the domain of the predicate.- Parameters:
a
- the object to compare with.- Returns:
- a predicate which matches all objects greater the given object.
-
equal
Returns a predicate which matches all objects which are equal to the given object. The identity is tested by applying theObject.equals(java.lang.Object)
method.- Type Parameters:
A
- the domain of the predicate.- Parameters:
a
- the object to test for.- Returns:
- a predicate which matches all objects which are equal to the given object.
-
instanceOf
Returns a predicate which matches all instances of the given class.- Type Parameters:
A
- the domain of the predicate.- Parameters:
c
- the class for which to test.- Returns:
- a predicate which matches all instances of the given class.
-
test
Returns a predicate which tests the given boolean function.- Type Parameters:
A
- the domain of the predicate.- Parameters:
fun
- the function to apply for getting the test result.- Returns:
- a predicate which tests the given boolean function.
-
characteristic
Returns a function which delivers the test result of the given predicate.- Type Parameters:
A
- the domain of the predicate.- Parameters:
pred
- the predicate for which the characteristic function is returned.- Returns:
- a function which delivers the test result of the given predicate.
-
bracket
Iverson bracket. Returns 1 if the predicate matches, else 0.- Type Parameters:
A
- the domain of the predicate.- Parameters:
pred
- the predicate for which the Iverson bracket is returned.- Returns:
- 1 if the predicate matches, else 0.
-
memberOf
Returns a predicate which matches the members of the given collection.- Type Parameters:
A
- the domain of the predicate.- Parameters:
c
- the collection to test for.- Returns:
- a predicate which matches the members of the given collection.
-
keyOf
Returns a predicate which matches the keys contained in the given map.- Type Parameters:
A
- the domain of the predicate.- Parameters:
map
- the map to test for.- Returns:
- a predicate which matches the keys contained in the given map.
-
totalize
Returns a predicate which is tested only for instances of the given class. All objects outside this class do not match.- Type Parameters:
A
- the domain of the predicate.B
- the class to test for.- Parameters:
c
- the class to test for.pred
- the predicate to test for.- Returns:
- a predicate which is tested only for instances of the given class.
-
classify
public static <A> void classify(Predicate<? super A> pred, Collection<? extends A> in, Collection<? super A> positive, Collection<? super A> negative) Sorts all given objets into one of two collections, whether the predicate applies or not.- Type Parameters:
A
- the domain of the predicate.- Parameters:
pred
- the classifying predicate.in
- the objects to sort.positive
- result parameter of all objects the predicate matches.negative
- result parameter of all objects the predicate does not match.
-