From 3618193221ef4ea40640930ed18285a56d6b174b Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 10 Jul 2024 09:35:54 -0400 Subject: [PATCH] Migrate toward java.util.function.Predicate - Maintains binary and source compatibility - Javadoc --- .../apache/commons/collections4/CollectionUtils.java | 10 +++++----- .../org/apache/commons/collections4/IterableUtils.java | 2 +- .../org/apache/commons/collections4/IteratorUtils.java | 6 +++--- .../org/apache/commons/collections4/ListUtils.java | 2 +- .../org/apache/commons/collections4/Predicate.java | 1 - .../collections4/collection/PredicatedCollection.java | 4 ++-- .../functors/AbstractQuantifierPredicate.java | 7 ++----- .../commons/collections4/functors/AllPredicate.java | 3 ++- .../commons/collections4/functors/AndPredicate.java | 7 ++++--- .../commons/collections4/functors/AnyPredicate.java | 3 ++- .../collections4/functors/ComparatorPredicate.java | 6 +++--- .../commons/collections4/functors/FunctorUtils.java | 4 ++-- .../commons/collections4/functors/IfClosure.java | 2 +- .../commons/collections4/functors/IfTransformer.java | 2 +- .../commons/collections4/functors/NonePredicate.java | 3 ++- .../commons/collections4/functors/NotPredicate.java | 7 ++++--- .../functors/NullIsExceptionPredicate.java | 7 ++++--- .../collections4/functors/NullIsFalsePredicate.java | 7 ++++--- .../collections4/functors/NullIsTruePredicate.java | 7 ++++--- .../commons/collections4/functors/OnePredicate.java | 3 ++- .../commons/collections4/functors/OrPredicate.java | 7 ++++--- .../collections4/functors/PredicateTransformer.java | 2 +- .../commons/collections4/functors/SwitchClosure.java | 2 +- .../collections4/functors/SwitchTransformer.java | 2 +- .../collections4/functors/TransformedPredicate.java | 7 ++++--- .../commons/collections4/functors/WhileClosure.java | 2 +- .../commons/collections4/iterators/FilterIterator.java | 2 +- .../collections4/iterators/FilterListIterator.java | 4 ++-- .../apache/commons/collections4/map/PredicatedMap.java | 6 +++--- .../functors/AbstractMockPredicateTest.java | 2 +- .../collections4/functors/AllPredicateTest.java | 9 +++------ 31 files changed, 71 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java index 98ab1231f7..1990c3798d 100644 --- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java +++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java @@ -833,7 +833,7 @@ public static boolean filter(final Iterable collection, final Predicate it = collection.iterator(); it.hasNext();) { - if (!predicate.evaluate(it.next())) { + if (!predicate.test(it.next())) { it.remove(); result = true; } @@ -1740,7 +1740,7 @@ public static > R select(final Iterable> R select(final Iterable> R selectRejected(final Iterab if (inputCollection != null && predicate != null) { for (final O item : inputCollection) { - if (!predicate.evaluate(item)) { + if (!predicate.test(item)) { outputCollection.add(item); } } @@ -1998,7 +1998,7 @@ public static Collection subtract(final Iterable a, final ArrayList list = new ArrayList<>(); final HashBag bag = new HashBag<>(); for (final O element : b) { - if (p.evaluate(element)) { + if (p.test(element)) { bag.add(element); } } diff --git a/src/main/java/org/apache/commons/collections4/IterableUtils.java b/src/main/java/org/apache/commons/collections4/IterableUtils.java index 9c5d58336d..448de58f99 100644 --- a/src/main/java/org/apache/commons/collections4/IterableUtils.java +++ b/src/main/java/org/apache/commons/collections4/IterableUtils.java @@ -698,7 +698,7 @@ public static > List partition(final Iterable E find(final Iterator iterator, final Predicate if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); - if (predicate.evaluate(element)) { + if (predicate.test(element)) { return element; } } @@ -860,7 +860,7 @@ public static int indexOf(final Iterator iterator, final Predicate boolean matchesAll(final Iterator iterator, final Predicate if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); - if (!predicate.evaluate(element)) { + if (!predicate.test(element)) { return false; } } diff --git a/src/main/java/org/apache/commons/collections4/ListUtils.java b/src/main/java/org/apache/commons/collections4/ListUtils.java index 8760455303..7a995286f2 100644 --- a/src/main/java/org/apache/commons/collections4/ListUtils.java +++ b/src/main/java/org/apache/commons/collections4/ListUtils.java @@ -242,7 +242,7 @@ public static int indexOf(final List list, final Predicate predicate) if (list != null && predicate != null) { for (int i = 0; i < list.size(); i++) { final E item = list.get(i); - if (predicate.evaluate(item)) { + if (predicate.test(item)) { return i; } } diff --git a/src/main/java/org/apache/commons/collections4/Predicate.java b/src/main/java/org/apache/commons/collections4/Predicate.java index 2403ca0613..e6d7008137 100644 --- a/src/main/java/org/apache/commons/collections4/Predicate.java +++ b/src/main/java/org/apache/commons/collections4/Predicate.java @@ -31,7 +31,6 @@ *

* * @param the type of the input to the predicate. - * * @since 1.0 * @deprecated Use {@link java.util.function.Predicate}. */ diff --git a/src/main/java/org/apache/commons/collections4/collection/PredicatedCollection.java b/src/main/java/org/apache/commons/collections4/collection/PredicatedCollection.java index def3191335..588c86a08e 100644 --- a/src/main/java/org/apache/commons/collections4/collection/PredicatedCollection.java +++ b/src/main/java/org/apache/commons/collections4/collection/PredicatedCollection.java @@ -118,7 +118,7 @@ public Builder(final Predicate predicate) { * @return the PredicatedCollectionBuilder. */ public Builder add(final E item) { - if (predicate.evaluate(item)) { + if (predicate.test(item)) { accepted.add(item); } else { rejected.add(item); @@ -419,7 +419,7 @@ public boolean addAll(final Collection coll) { * @throws IllegalArgumentException if the add is invalid */ protected void validate(final E object) { - if (!predicate.evaluate(object)) { + if (!predicate.test(object)) { throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate '" + predicate + "' rejected it"); } diff --git a/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java index 8862877088..fe0ad219de 100644 --- a/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java @@ -23,9 +23,10 @@ /** * Abstract base class for quantification predicates, e.g. All, Any, None. * + * @param the type of the input to the predicate. * @since 4.0 */ -public abstract class AbstractQuantifierPredicate implements PredicateDecorator, Serializable { +public abstract class AbstractQuantifierPredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -3094696765038308799L; @@ -53,8 +54,4 @@ public Predicate[] getPredicates() { return FunctorUtils.copy(iPredicates); } - @Override - public boolean evaluate(final T object) { - return test(object); - } } diff --git a/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java index f656706f16..ddaa26c0c4 100644 --- a/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java @@ -33,6 +33,7 @@ * threw an exception. *

* + * @param the type of the input to the predicate. * @since 3.0 */ public final class AllPredicate extends AbstractQuantifierPredicate { @@ -106,7 +107,7 @@ public AllPredicate(final Predicate... predicates) { @Override public boolean test(final T object) { for (final Predicate iPredicate : iPredicates) { - if (!iPredicate.evaluate(object)) { + if (!iPredicate.test(object)) { return false; } } diff --git a/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java index 87d8fbc2be..402fda89f1 100644 --- a/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java @@ -24,9 +24,10 @@ /** * Predicate implementation that returns true if both the predicates return true. * + * @param the type of the input to the predicate. * @since 3.0 */ -public final class AndPredicate implements PredicateDecorator, Serializable { +public final class AndPredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = 4189014213763186912L; @@ -70,8 +71,8 @@ public AndPredicate(final Predicate predicate1, final Predicate * + * @param the type of the input to the predicate. * @since 3.0 */ public final class AnyPredicate extends AbstractQuantifierPredicate { @@ -103,7 +104,7 @@ public AnyPredicate(final Predicate... predicates) { @Override public boolean test(final T object) { for (final Predicate iPredicate : iPredicates) { - if (iPredicate.evaluate(object)) { + if (iPredicate.test(object)) { return true; } } diff --git a/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java b/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java index 0efc3bebfc..d42cb97327 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/ComparatorPredicate.java @@ -45,7 +45,7 @@ * following way:

* *
- * ComparatorPredicate.comparatorPredicate(ONE, comparator).evaluate(TWO);
+ * ComparatorPredicate.comparatorPredicate(ONE, comparator).test(TWO);
  * 
* *

The input variable {@code TWO} in compared to the stored variable {@code ONE} using @@ -67,7 +67,7 @@ * evaluation of a comparator result.

* *
- * ComparatorPredicate.comparatorPredicate(ONE, comparator,ComparatorPredicate.Criterion.GREATER).evaluate(TWO);
+ * ComparatorPredicate.comparatorPredicate(ONE, comparator,ComparatorPredicate.Criterion.GREATER).test(TWO);
  * 
* *

The input variable TWO is compared to the stored variable ONE using the supplied {@code comparator} @@ -150,7 +150,7 @@ public ComparatorPredicate(final T object, final Comparator comparator, final *

  • {@code comparator.compare(object, input) <= 0 && criterion == LESS_OR_EQUAL}
  • * * - * @see org.apache.commons.collections4.Predicate#evaluate(Object) + * @see org.apache.commons.collections4.Predicate#test(Object) * @see java.util.Comparator#compare(Object first, Object second) * * @param target the target object to compare to diff --git a/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java b/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java index c4b8fe3c66..d118dd24d1 100644 --- a/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java +++ b/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java @@ -49,7 +49,7 @@ static Closure coerce(final Closure closure) { /** * A very simple method that coerces Predicate to Predicate. - * Due to the {@link Predicate#evaluate(T)} method, Predicate is + * Due to the {@link Predicate#test(T)} method, Predicate is * able to be coerced to Predicate without casting issues. *

    This method exists * simply as centralised documentation and atomic unchecked warning @@ -96,7 +96,7 @@ static Closure[] copy(final Closure... closures) { /** * Clone the predicates to ensure that the internal reference can't be messed with. - * Due to the {@link Predicate#evaluate(T)} method, Predicate is + * Due to the {@link Predicate#test(T)} method, Predicate is * able to be coerced to Predicate without casting issues. * * @param predicates the predicates to copy diff --git a/src/main/java/org/apache/commons/collections4/functors/IfClosure.java b/src/main/java/org/apache/commons/collections4/functors/IfClosure.java index 277981593a..d2d10d9e3f 100644 --- a/src/main/java/org/apache/commons/collections4/functors/IfClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/IfClosure.java @@ -112,7 +112,7 @@ public IfClosure(final Predicate predicate, final Closure */ @Override public void execute(final E input) { - if (iPredicate.evaluate(input)) { + if (iPredicate.test(input)) { iTrueClosure.accept(input); } else { iFalseClosure.accept(input); diff --git a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java index fc3788d7d5..ddf4a532a2 100644 --- a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java @@ -133,7 +133,7 @@ public Predicate getPredicate() { */ @Override public O transform(final I input) { - if (iPredicate.evaluate(input)) { + if (iPredicate.test(input)) { return iTrueTransformer.transform(input); } return iFalseTransformer.transform(input); diff --git a/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java b/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java index b3532f4bae..1aa5b8b498 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java @@ -29,6 +29,7 @@ * threw an exception. *

    * + * @param the type of the input to the predicate. * @since 3.0 */ public final class NonePredicate extends AbstractQuantifierPredicate { @@ -93,7 +94,7 @@ public NonePredicate(final Predicate... predicates) { @Override public boolean test(final T object) { for (final Predicate iPredicate : iPredicates) { - if (iPredicate.evaluate(object)) { + if (iPredicate.test(object)) { return false; } } diff --git a/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java b/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java index c2ea1108bb..987bbd4768 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NotPredicate.java @@ -24,9 +24,10 @@ /** * Predicate implementation that returns the opposite of the decorated predicate. * + * @param the type of the input to the predicate. * @since 3.0 */ -public final class NotPredicate implements PredicateDecorator, Serializable { +public final class NotPredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -2654603322338049674L; @@ -63,8 +64,8 @@ public NotPredicate(final Predicate predicate) { * @return true if predicate returns false */ @Override - public boolean evaluate(final T object) { - return !iPredicate.evaluate(object); + public boolean test(final T object) { + return !iPredicate.test(object); } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java index 1916835ada..4b31140bd2 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullIsExceptionPredicate.java @@ -25,9 +25,10 @@ /** * Predicate implementation that throws an exception if the input is null. * + * @param the type of the input to the predicate. * @since 3.0 */ -public final class NullIsExceptionPredicate implements PredicateDecorator, Serializable { +public final class NullIsExceptionPredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = 3243449850504576071L; @@ -66,11 +67,11 @@ public NullIsExceptionPredicate(final Predicate predicate) { * @throws FunctorException if input is null */ @Override - public boolean evaluate(final T object) { + public boolean test(final T object) { if (object == null) { throw new FunctorException("Input Object must not be null"); } - return iPredicate.evaluate(object); + return iPredicate.test(object); } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java index b56e2754d9..b70b1b93f1 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullIsFalsePredicate.java @@ -24,9 +24,10 @@ /** * Predicate implementation that returns false if the input is null. * + * @param the type of the input to the predicate. * @since 3.0 */ -public final class NullIsFalsePredicate implements PredicateDecorator, Serializable { +public final class NullIsFalsePredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -2997501534564735525L; @@ -64,11 +65,11 @@ public NullIsFalsePredicate(final Predicate predicate) { * @return true if decorated predicate returns true, false if input is null */ @Override - public boolean evaluate(final T object) { + public boolean test(final T object) { if (object == null) { return false; } - return iPredicate.evaluate(object); + return iPredicate.test(object); } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java b/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java index e3334d77a2..2dc0a107f5 100644 --- a/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/NullIsTruePredicate.java @@ -24,9 +24,10 @@ /** * Predicate implementation that returns true if the input is null. * + * @param the type of the input to the predicate. * @since 3.0 */ -public final class NullIsTruePredicate implements PredicateDecorator, Serializable { +public final class NullIsTruePredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -7625133768987126273L; @@ -64,11 +65,11 @@ public NullIsTruePredicate(final Predicate predicate) { * @return true if decorated predicate returns true or input is null */ @Override - public boolean evaluate(final T object) { + public boolean test(final T object) { if (object == null) { return true; } - return iPredicate.evaluate(object); + return iPredicate.test(object); } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java b/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java index 4ce4eae2fc..a8b74935e2 100644 --- a/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java @@ -29,6 +29,7 @@ * threw an exception. *

    * + * @param the type of the input to the predicate. * @since 3.0 */ public final class OnePredicate extends AbstractQuantifierPredicate { @@ -95,7 +96,7 @@ public OnePredicate(final Predicate... predicates) { public boolean test(final T object) { boolean match = false; for (final Predicate iPredicate : iPredicates) { - if (iPredicate.evaluate(object)) { + if (iPredicate.test(object)) { if (match) { return false; } diff --git a/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java b/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java index f221c37fc0..cdd027aac9 100644 --- a/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java @@ -24,9 +24,10 @@ /** * Predicate implementation that returns true if either of the predicates return true. * + * @param the type of the input to the predicate. * @since 3.0 */ -public final class OrPredicate implements PredicateDecorator, Serializable { +public final class OrPredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -8791518325735182855L; @@ -70,8 +71,8 @@ public OrPredicate(final Predicate predicate1, final Predicate getPredicate() { */ @Override public Boolean transform(final T input) { - return Boolean.valueOf(iPredicate.evaluate(input)); + return Boolean.valueOf(iPredicate.test(input)); } } diff --git a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java index 1b5013f6ec..6108b93d16 100644 --- a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java @@ -142,7 +142,7 @@ public SwitchClosure(final Predicate[] predicates, final Closure[] getPredicates() { @Override public O transform(final I input) { for (int i = 0; i < iPredicates.length; i++) { - if (iPredicates[i].evaluate(input)) { + if (iPredicates[i].test(input)) { return iTransformers[i].transform(input); } } diff --git a/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java b/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java index 7da882215f..8fe496e127 100644 --- a/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java +++ b/src/main/java/org/apache/commons/collections4/functors/TransformedPredicate.java @@ -26,9 +26,10 @@ * Predicate implementation that transforms the given object before invoking * another {@code Predicate}. * + * @param the type of the input to the predicate. * @since 3.1 */ -public final class TransformedPredicate implements PredicateDecorator, Serializable { +public final class TransformedPredicate extends AbstractPredicate implements PredicateDecorator, Serializable { /** Serial version UID */ private static final long serialVersionUID = -5596090919668315834L; @@ -75,9 +76,9 @@ public TransformedPredicate(final Transformer transforme * @return true if decorated predicate returns true */ @Override - public boolean evaluate(final T object) { + public boolean test(final T object) { final T result = iTransformer.transform(object); - return iPredicate.evaluate(result); + return iPredicate.test(result); } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java b/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java index 5bded3e020..39a52c01e1 100644 --- a/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java @@ -82,7 +82,7 @@ public void execute(final E input) { if (iDoLoop) { iClosure.accept(input); } - while (iPredicate.evaluate(input)) { + while (iPredicate.test(input)) { iClosure.accept(input); } } diff --git a/src/main/java/org/apache/commons/collections4/iterators/FilterIterator.java b/src/main/java/org/apache/commons/collections4/iterators/FilterIterator.java index 4b0d8f4a7f..3364366460 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/FilterIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/FilterIterator.java @@ -155,7 +155,7 @@ public void setIterator(final Iterator iterator) { private boolean setNextObject() { while (iterator.hasNext()) { final E object = iterator.next(); - if (predicate.evaluate(object)) { + if (predicate.test(object)) { nextObject = object; nextObjectSet = true; return true; diff --git a/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java index 5aeb6f5754..ab6616ae05 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java @@ -229,7 +229,7 @@ private boolean setNextObject() { } while (iterator.hasNext()) { final E object = iterator.next(); - if (predicate.evaluate(object)) { + if (predicate.test(object)) { nextObject = object; nextObjectSet = true; return true; @@ -265,7 +265,7 @@ private boolean setPreviousObject() { } while (iterator.hasPrevious()) { final E object = iterator.previous(); - if (predicate.evaluate(object)) { + if (predicate.test(object)) { previousObject = object; previousObjectSet = true; return true; diff --git a/src/main/java/org/apache/commons/collections4/map/PredicatedMap.java b/src/main/java/org/apache/commons/collections4/map/PredicatedMap.java index ab68449997..7e7f6455d0 100644 --- a/src/main/java/org/apache/commons/collections4/map/PredicatedMap.java +++ b/src/main/java/org/apache/commons/collections4/map/PredicatedMap.java @@ -111,7 +111,7 @@ protected PredicatedMap(final Map map, final Predicate keyPredi */ @Override protected V checkSetValue(final V value) { - if (!valuePredicate.evaluate(value)) { + if (!valuePredicate.test(value)) { throw new IllegalArgumentException("Cannot set value - Predicate rejected it"); } return value; @@ -164,10 +164,10 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot * @throws IllegalArgumentException if invalid */ protected void validate(final K key, final V value) { - if (keyPredicate != null && !keyPredicate.evaluate(key)) { + if (keyPredicate != null && !keyPredicate.test(key)) { throw new IllegalArgumentException("Cannot add key - Predicate rejected it"); } - if (valuePredicate != null && !valuePredicate.evaluate(value)) { + if (valuePredicate != null && !valuePredicate.test(value)) { throw new IllegalArgumentException("Cannot add value - Predicate rejected it"); } } diff --git a/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java index 690b03ba76..46535b9fa2 100644 --- a/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java @@ -62,7 +62,7 @@ protected AbstractMockPredicateTest(final T testValue) { protected final Predicate createMockPredicate(final Boolean returnValue) { final Predicate mockPredicate = EasyMock.createMock(Predicate.class); if (returnValue != null) { - EasyMock.expect(mockPredicate.evaluate(testValue)).andReturn(returnValue); + EasyMock.expect(mockPredicate.test(testValue)).andReturn(returnValue); } replay(mockPredicate); mockPredicatesToVerify.add(mockPredicate); diff --git a/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java index d69a5616ab..3025123cc0 100644 --- a/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java @@ -80,8 +80,7 @@ public void testEmptyArrayToGetInstance() { */ @Test public void testEmptyCollectionToGetInstance() { - final Predicate allPredicate = getPredicateInstance( - Collections.>emptyList()); + final Predicate allPredicate = getPredicateInstance(Collections.>emptyList()); assertTrue(allPredicate.evaluate(getTestValue()), "empty collection not true"); } @@ -94,8 +93,7 @@ public void testOneFalsePredicate() { // use the constructor directly, as getInstance() returns the original predicate when passed // an array of size one. final Predicate predicate = createMockPredicate(false); - assertFalse(allPredicate(predicate).evaluate(getTestValue()), - "single false predicate evaluated to true"); + assertFalse(allPredicate(predicate).test(getTestValue()), "single false predicate evaluated to true"); } /** @@ -107,8 +105,7 @@ public void testOneTruePredicate() { // use the constructor directly, as getInstance() returns the original predicate when passed // an array of size one. final Predicate predicate = createMockPredicate(true); - - assertTrue(allPredicate(predicate).evaluate(getTestValue()), "single true predicate evaluated to false"); + assertTrue(allPredicate(predicate).test(getTestValue()), "single true predicate evaluated to false"); } /**