You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2020/08/20 08:40:00 UTC

[commons-collections] branch master updated (62febb3 -> d5de68c)

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

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


    from 62febb3  Merge pull request #174 from apache/dependabot/github_actions/actions/setup-java-v1.4.1
     new d0551d0  [COLLECTIONS-708]  Add hashcode method to CollectionUtils that supports an equator parameter
     new 8d6f5ae  [COLLECTIONS-708] Formatting and update javadocs
     new 28bd743  [COLLECTIONS-708] changelog
     new d5de68c  Merge branch 'pr-89'

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  3 ++
 .../commons/collections4/CollectionUtils.java      | 27 ++++++++++++
 .../commons/collections4/CollectionUtilsTest.java  | 49 +++++++++++++++++++++-
 3 files changed, 78 insertions(+), 1 deletion(-)


[commons-collections] 02/04: [COLLECTIONS-708] Formatting and update javadocs

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8d6f5ae3bdf24c1a924d58efd5c8ebac89daa36a
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Thu Aug 20 20:33:04 2020 +1200

    [COLLECTIONS-708] Formatting and update javadocs
---
 .../java/org/apache/commons/collections4/CollectionUtils.java | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
index 7f7d6bc..4c2f416 100644
--- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java
+++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
@@ -644,20 +644,21 @@ public class CollectionUtils {
     }
 
     /**
-     * Returns the hash code the the input collection using the hash method of the equator.
+     * Returns the hash code of the input collection using the hash method of an equator.
+     *
      * <p>
-     * If the input collection is null return 0.
+     * Returns 0 if the input collection is {@code null}.
      * </p>
      *
      * @param <E>  the element type
      * @param collection  the input collection
      * @param equator  the equator used for generate hashCode
-     * @return the hashCode of Collection through the hash method of Equator
-     * @throws NullPointerException if the equator is null
+     * @return the hash code of the input collection using the hash method of an equator
+     * @throws NullPointerException if the equator is {@code null}
      * @since 4.5
      */
     public static <E> int hashCode(final Collection<? extends E> collection,
-                                final Equator<? super E> equator) {
+            final Equator<? super E> equator) {
         Objects.requireNonNull(equator, "equator");
         if (null == collection) {
             return 0;


[commons-collections] 03/04: [COLLECTIONS-708] changelog

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 28bd7432bb7bd6c093fc837935057ba4d5f73d61
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Thu Aug 20 20:35:49 2020 +1200

    [COLLECTIONS-708] changelog
---
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c7d8c98..0da4fbd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -21,6 +21,9 @@
   </properties>
   <body>
   <release version="4.5" date="2020-MM-DD" description="Maintenance release.">
+    <action issue="COLLECTIONS-708" dev="kinow" type="fix" due-to="dota17">
+      Add hashCode method to CollectionUtils that supports an equator parameter.
+    </action>
     <action issue="COLLECTIONS-759" dev="kinow" type="fix">
       Fix checkstyle issues regarding missing newline at end of file, and CRLF vs LF.
     </action>


[commons-collections] 04/04: Merge branch 'pr-89'

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d5de68c2d1cbc68043605ee5286a4f8d08965053
Merge: 62febb3 28bd743
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Thu Aug 20 20:38:59 2020 +1200

    Merge branch 'pr-89'
    
    This closes #89

 src/changes/changes.xml                            |  3 ++
 .../commons/collections4/CollectionUtils.java      | 27 ++++++++++++
 .../commons/collections4/CollectionUtilsTest.java  | 49 +++++++++++++++++++++-
 3 files changed, 78 insertions(+), 1 deletion(-)


[commons-collections] 01/04: [COLLECTIONS-708] Add hashcode method to CollectionUtils that supports an equator parameter

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d0551d01b3d7e97aa5d8fb1ec91e648a93dab929
Author: dota17 <ch...@163.com>
AuthorDate: Tue Oct 22 09:55:26 2019 +0800

    [COLLECTIONS-708]  Add hashcode method to CollectionUtils that supports an equator parameter
---
 .../commons/collections4/CollectionUtils.java      | 26 ++++++++++++
 .../commons/collections4/CollectionUtilsTest.java  | 49 +++++++++++++++++++++-
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
index 2b73511..7f7d6bc 100644
--- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java
+++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
@@ -644,6 +644,32 @@ public class CollectionUtils {
     }
 
     /**
+     * Returns the hash code the the input collection using the hash method of the equator.
+     * <p>
+     * If the input collection is null return 0.
+     * </p>
+     *
+     * @param <E>  the element type
+     * @param collection  the input collection
+     * @param equator  the equator used for generate hashCode
+     * @return the hashCode of Collection through the hash method of Equator
+     * @throws NullPointerException if the equator is null
+     * @since 4.5
+     */
+    public static <E> int hashCode(final Collection<? extends E> collection,
+                                final Equator<? super E> equator) {
+        Objects.requireNonNull(equator, "equator");
+        if (null == collection) {
+            return 0;
+        }
+        int hashCode = 1;
+        for (final E e : collection) {
+            hashCode = 31 * hashCode + equator.hash(e);
+        }
+        return hashCode;
+    }
+
+    /**
      * Wraps another object and uses the provided Equator to implement
      * {@link #equals(Object)} and {@link #hashCode()}.
      * <p>
diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
index 7d1bd98..4922a91 100644
--- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
@@ -37,6 +37,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Queue;
 import java.util.Set;
 import java.util.SortedMap;
@@ -741,6 +742,52 @@ public class CollectionUtilsTest extends MockTestCase {
         CollectionUtils.isEqualCollection(collectionA, collectionA, null);
     }
 
+    @Test
+    public void testHashCode() {
+        final Equator<Integer> e = new Equator<Integer>() {
+            @Override
+            public boolean equate(final Integer o1, final Integer o2) {
+                if (o1 % 2 == 0 ^ o2 % 2 == 0) {
+                    return false;
+                }
+                return true;
+            }
+
+            @Override
+            public int hash(final Integer o) {
+                return o == null ? 0 : Objects.hashCode(o);
+            }
+        };
+
+        assertEquals(collectionA.hashCode(), CollectionUtils.hashCode(collectionA, e));
+    }
+
+    @Test
+    public void testHashCodeNullCollection() {
+        final Equator<Integer> e = new Equator<Integer>() {
+            @Override
+            public boolean equate(final Integer o1, final Integer o2) {
+                if (o1 % 2 == 0 ^ o2 % 2 == 0) {
+                    return false;
+                }
+                return true;
+            }
+
+            @Override
+            public int hash(final Integer o) {
+                return o == null ? 0 : Objects.hashCode(o);
+            }
+        };
+
+        final Collection<Integer> collection = null;
+        assertEquals(0, CollectionUtils.hashCode(collection, e));
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testHashCodeNullEquator() {
+        CollectionUtils.hashCode(collectionB, null);
+    }
+
     @Test(expected = NullPointerException.class)
     public void testIsEqualCollectionNullColl1() {
         final Collection<Integer> list = new ArrayList<>(1);
@@ -1073,7 +1120,7 @@ public class CollectionUtilsTest extends MockTestCase {
         CollectionUtils.get(array, 2);
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void getFromObject() throws Exception {
         // Invalid object
         final Object obj = new Object();