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-io.git


The following commit(s) were added to refs/heads/master by this push:
     new c1d7975  Implement hashCode() and equals() on counters.
c1d7975 is described below

commit c1d7975ae3a6572ac15b934d86f2a8d0088a69ca
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Mon Nov 25 20:39:36 2019 -0500

    Implement hashCode() and equals() on counters.
---
 src/main/java/org/apache/commons/io/file/Counters.java       | 12 ++++++------
 .../commons/io/file/CountersEqualsAndHashCodeTest.java       | 11 +++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/file/Counters.java 
b/src/main/java/org/apache/commons/io/file/Counters.java
index e3fad94..44329b6 100644
--- a/src/main/java/org/apache/commons/io/file/Counters.java
+++ b/src/main/java/org/apache/commons/io/file/Counters.java
@@ -116,11 +116,11 @@ public class Counters {
             if (this == obj) {
                 return true;
             }
-            if (!(obj instanceof BigIntegerCounter)) {
+            if (!(obj instanceof Counter)) {
                 return false;
             }
-            BigIntegerCounter other = (BigIntegerCounter) obj;
-            return Objects.equals(value, other.value);
+            Counter other = (Counter) obj;
+            return Objects.equals(value, other.getBigInteger());
         }
 
         @Override
@@ -226,11 +226,11 @@ public class Counters {
             if (this == obj) {
                 return true;
             }
-            if (!(obj instanceof LongCounter)) {
+            if (!(obj instanceof Counter)) {
                 return false;
             }
-            LongCounter other = (LongCounter) obj;
-            return value == other.value;
+            Counter other = (Counter) obj;
+            return value == other.get();
         }
 
         @Override
diff --git 
a/src/test/java/org/apache/commons/io/file/CountersEqualsAndHashCodeTest.java 
b/src/test/java/org/apache/commons/io/file/CountersEqualsAndHashCodeTest.java
index 43388bb..2419af2 100644
--- 
a/src/test/java/org/apache/commons/io/file/CountersEqualsAndHashCodeTest.java
+++ 
b/src/test/java/org/apache/commons/io/file/CountersEqualsAndHashCodeTest.java
@@ -88,6 +88,12 @@ public class CountersEqualsAndHashCodeTest {
     }
 
     @Test
+    public void testLongCounterMixEquals() {
+        testEquals(Counters.longCounter(), Counters.bigIntegerCounter());
+        testEquals(Counters.bigIntegerCounter(), Counters.longCounter());
+    }
+
+    @Test
     public void testLongCounterHashCodes() {
         testHashCodes(Counters.longCounter(), Counters.longCounter());
     }
@@ -111,4 +117,9 @@ public class CountersEqualsAndHashCodeTest {
     public void testLongPathCountersHashCodeFileCounters() {
         testHashCodeFileCounters(Counters.longPathCounters(), 
Counters.longPathCounters());
     }
+
+    @Test
+    public void testMix() {
+        testHashCodeFileCounters(Counters.longPathCounters(), 
Counters.bigIntegerPathCounters());
+    }
 }

Reply via email to