You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by mi...@apache.org on 2019/12/26 14:36:22 UTC

[httpcomponents-core] branch TimeValue-equals-hashCode updated (2bb2c38 -> 98d2d1d)

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

michaelo pushed a change to branch TimeValue-equals-hashCode
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git.


 discard 2bb2c38  Normalize TimeUnit in TimeValue's equals() and hashCode()
     new 98d2d1d  Normalize TimeUnit in TimeValue's equals() and hashCode()

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (2bb2c38)
            \
             N -- N -- N   refs/heads/TimeValue-equals-hashCode (98d2d1d)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java | 1 -
 1 file changed, 1 deletion(-)


[httpcomponents-core] 01/01: Normalize TimeUnit in TimeValue's equals() and hashCode()

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

michaelo pushed a commit to branch TimeValue-equals-hashCode
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 98d2d1d7b4d84f32054c9c617d862ce210222db3
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Dec 25 19:38:33 2019 +0100

    Normalize TimeUnit in TimeValue's equals() and hashCode()
    
    This closes #172
---
 httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java    | 7 ++++---
 .../src/test/java/org/apache/hc/core5/util/TestTimeValue.java      | 6 ++++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index 576d875..d2e50f3 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -229,7 +229,9 @@ public class TimeValue implements Comparable<TimeValue> {
         }
         if (obj instanceof TimeValue) {
             final TimeValue that = (TimeValue) obj;
-            return this.duration == that.duration && LangUtils.equals(this.timeUnit, that.timeUnit);
+            final long thisDuration = this.convert(TimeUnit.NANOSECONDS);
+            final long thatDuration = that.convert(TimeUnit.NANOSECONDS);
+            return thisDuration == thatDuration;
         }
         return false;
     }
@@ -274,8 +276,7 @@ public class TimeValue implements Comparable<TimeValue> {
     @Override
     public int hashCode() {
         int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, duration);
-        hash = LangUtils.hashCode(hash, timeUnit);
+        hash = LangUtils.hashCode(hash, this.convert(TimeUnit.NANOSECONDS));
         return hash;
     }
 
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
index 38c3b3f..f9724f3 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
@@ -275,12 +275,14 @@ public class TestTimeValue {
         Assert.assertThat(tv1.equals(null), CoreMatchers.equalTo(false));
         Assert.assertThat(tv1.equals(tv2), CoreMatchers.equalTo(false));
         Assert.assertThat(tv1.equals(tv3), CoreMatchers.equalTo(true));
-        Assert.assertThat(tv1.equals(tv4), CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.equals(tv4), CoreMatchers.equalTo(true));
+        Assert.assertThat(tv4.equals(tv1), CoreMatchers.equalTo(true));
         Assert.assertThat(tv1.equals(tv5), CoreMatchers.equalTo(false));
 
         Assert.assertThat(tv1.hashCode() == tv2.hashCode(), CoreMatchers.equalTo(false));
         Assert.assertThat(tv1.hashCode() == tv3.hashCode(), CoreMatchers.equalTo(true));
-        Assert.assertThat(tv1.hashCode() == tv4.hashCode(), CoreMatchers.equalTo(false));
+        Assert.assertThat(tv1.hashCode() == tv4.hashCode(), CoreMatchers.equalTo(true));
+        Assert.assertThat(tv4.hashCode() == tv1.hashCode(), CoreMatchers.equalTo(true));
         Assert.assertThat(tv1.hashCode() == tv5.hashCode(), CoreMatchers.equalTo(false));
     }