This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit de4b7f8bbe3a31e58255e79e0e740bb26e907857
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Dec 8 17:06:22 2024 -0500

    EqualPredicate.test(Object) should return true if the parameter is the
    same object as given the constructor
---
 .../commons/collections4/functors/EqualPredicate.java     | 15 ++++++++-------
 .../commons/collections4/functors/EqualPredicateTest.java |  5 ++++-
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java 
b/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java
index 6143d1758..b59379e4a 100644
--- a/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/EqualPredicate.java
@@ -17,6 +17,7 @@
 package org.apache.commons.collections4.functors;
 
 import java.io.Serializable;
+import java.util.Objects;
 
 import org.apache.commons.collections4.Equator;
 import org.apache.commons.collections4.Predicate;
@@ -64,7 +65,7 @@ public final class EqualPredicate<T> extends 
AbstractPredicate<T> implements Ser
     }
 
     /** The value to compare to */
-    private final T iValue;
+    private final T test;
 
     /** The equator to use for comparison */
     private final Equator<T> equator;
@@ -85,12 +86,12 @@ public final class EqualPredicate<T> extends 
AbstractPredicate<T> implements Ser
      * Constructor that performs no validation.
      * Use {@code equalPredicate} if you want that.
      *
-     * @param object  the object to compare to
+     * @param test  the object to compare to
      * @param equator  the equator to use for comparison
      * @since 4.0
      */
-    public EqualPredicate(final T object, final Equator<T> equator) {
-        iValue = object;
+    public EqualPredicate(final T test, final Equator<T> equator) {
+        this.test = test;
         this.equator = equator;
     }
 
@@ -101,7 +102,7 @@ public final class EqualPredicate<T> extends 
AbstractPredicate<T> implements Ser
      * @since 3.1
      */
     public Object getValue() {
-        return iValue;
+        return test;
     }
 
     /**
@@ -113,9 +114,9 @@ public final class EqualPredicate<T> extends 
AbstractPredicate<T> implements Ser
     @Override
     public boolean test(final T object) {
         if (equator != null) {
-            return equator.equate(iValue, object);
+            return equator.equate(test, object);
         }
-        return iValue.equals(object);
+        return Objects.equals(test, object);
     }
 
 }
diff --git 
a/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java
 
b/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java
index 990d7e37b..bb9627bbc 100644
--- 
a/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java
+++ 
b/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java
@@ -52,7 +52,10 @@ public class EqualPredicateTest extends 
AbstractPredicateTest {
     @Test
     public void testObjectFactoryUsesEqualsForTest() throws Exception {
         final Predicate<EqualsTestObject> predicate = 
EqualPredicate.equalPredicate(FALSE_OBJECT);
-        assertPredicateFalse(predicate, FALSE_OBJECT);
+        assertPredicateFalse(predicate, null);
+        assertPredicateFalse(predicate, TRUE_OBJECT); // different object
+        assertPredicateTrue(predicate, FALSE_OBJECT); // the same object
+        assertPredicateFalse(predicate, new EqualsTestObject(false)); // 
different object but always returns false from equals()
         assertPredicateTrue(EqualPredicate.equalPredicate(TRUE_OBJECT), 
TRUE_OBJECT);
     }
 

Reply via email to