In order to demonstrate the use of the predicate, the following variables are declared:
Integer ONE = Integer.valueOf(1);
Integer TWO = Integer.valueOf(2);
Comparator comparator = new Comparator() {
public int compare(Object first, Object second) {
return ((Integer) second) - ((Integer) first);
}
};
Using the declared variables, the ComparatorPredicate can be used used in the
following way:
ComparatorPredicate.comparatorPredicate(ONE, comparator).evaluate(TWO);
The input variable TWO in compared to the stored variable ONE using
the supplied comparator. This is the default usage of the predicate and will return
true if the underlying comparator returns 0. In addition to the default
usage of the predicate, it is possible to evaluate the comparator's result in several ways. The
following Criterion enumeration values are provided by the predicate:
The following examples demonstrates how these constants can be used in order to manipulate the evaluation of a comparator result.
ComparatorPredicate.comparatorPredicate(ONE, comparator,ComparatorPredicate.Criterion.GREATER).evaluate(TWO);
The input variable TWO is compared to the stored variable ONE using the supplied comparator
using the GREATER evaluation criterion constant. This instructs the predicate to
return true if the comparator returns a value greater than 0.
| Modifier and Type | Class and Description |
|---|---|
| public static enum |
| Modifier and Type | Field and Description |
|---|---|
| private final Comparator | comparator
The comparator to use for comparison |
| private final ComparatorPredicate. | criterion
The comparison evaluation criterion to use |
| private final T | object
The internal object to compare with |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | ComparatorPredicate(final T
the object to compare to object, final Comparator<T> the comparator to use for comparison comparator, final ComparatorPredicate.the criterion to use to evaluate comparison criterionConstructor that performs no validation. |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type that the predicate queries T> Predicate | Returns: the predicatethe object to compare to object, final Comparator<T> the comparator to use for comparison comparator)Factory to create the comparator predicate |
| public static < the type that the predicate queries T> Predicate | Returns: the predicatethe object to compare to object, final Comparator<T> the comparator to use for comparison comparator, final ComparatorPredicate.the criterion to use to evaluate comparison criterionFactory to create the comparator predicate |
| public boolean | Returns: true if the comparison succeeds according to the selected criterionthe target object to compare to target)Implements org. |
| comparator | back to summary |
|---|---|
| private final Comparator<T> comparator The comparator to use for comparison | |
| criterion | back to summary |
|---|---|
| private final ComparatorPredicate. The comparison evaluation criterion to use | |
| object | back to summary |
|---|---|
| private final T object The internal object to compare with | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| ComparatorPredicate | back to summary |
|---|---|
| public ComparatorPredicate(final T object, final Comparator<T> comparator, final ComparatorPredicate. Constructor that performs no validation.
Use
| |
| comparatorPredicate | back to summary |
|---|---|
| public static <T> Predicate Factory to create the comparator predicate
| |
| comparatorPredicate | back to summary |
|---|---|
| public static <T> Predicate Factory to create the comparator predicate
| |
| evaluate | back to summary |
|---|---|
| public boolean evaluate(final T target) Implements org. Evaluates the predicate. The predicate evaluates to
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final ComparatorPredicate. | |
| public static final ComparatorPredicate. | |
| public static final ComparatorPredicate. | |
| public static final ComparatorPredicate. | |
| public static final ComparatorPredicate. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ComparatorPredicate. | |
| public static ComparatorPredicate. |
| EQUAL | back to summary |
|---|---|
| public static final ComparatorPredicate. | |
| GREATER | back to summary |
|---|---|
| public static final ComparatorPredicate. | |
| GREATER_OR_EQUAL | back to summary |
|---|---|
| public static final ComparatorPredicate. | |
| LESS | back to summary |
|---|---|
| public static final ComparatorPredicate. | |
| LESS_OR_EQUAL | back to summary |
|---|---|
| public static final ComparatorPredicate. | |
| Criterion | back to summary |
|---|---|
| private Criterion() | |
| valueOf | back to summary |
|---|---|
| public static ComparatorPredicate. | |
| values | back to summary |
|---|---|
| public static ComparatorPredicate. | |