You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/09 19:57:58 UTC

[06/50] [abbrv] httpcomponents-core git commit: HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Reuse factory method.

HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Reuse factory method.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791967 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/5f87041d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/5f87041d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/5f87041d

Branch: refs/heads/trunk
Commit: 5f87041d1e8d03003c49037ad4729d8c61e7b958
Parents: e7043b5
Author: Gary D. Gregory <gg...@apache.org>
Authored: Wed Apr 19 20:12:15 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Wed Apr 19 20:12:15 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/util/TimeValue.java    | 16 ++++++++--------
 .../org/apache/hc/core5/util/TestTimeValue.java     | 14 +++++++-------
 2 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5f87041d/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
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 23ac579..770264f 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
@@ -41,9 +41,9 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
 public class TimeValue {
 
     private static final int UNDEFINED = -1;
-    public static final TimeValue NEG_ONE_MILLISECONDS = new TimeValue(UNDEFINED, TimeUnit.MILLISECONDS);
-    public static final TimeValue NEG_ONE_SECONDS = new TimeValue(UNDEFINED, TimeUnit.SECONDS);
-    public static final TimeValue ZERO_MILLISECONDS = new TimeValue(0, TimeUnit.MILLISECONDS);
+    public static final TimeValue NEG_ONE_MILLISECONDS = TimeValue.of(UNDEFINED, TimeUnit.MILLISECONDS);
+    public static final TimeValue NEG_ONE_SECONDS = TimeValue.of(UNDEFINED, TimeUnit.SECONDS);
+    public static final TimeValue ZERO_MILLISECONDS = TimeValue.of(0, TimeUnit.MILLISECONDS);
 
     /**
      * Returns the given {@code long} value as an {@code int} where long values out of int range are returned as
@@ -120,23 +120,23 @@ public class TimeValue {
     }
 
     public static TimeValue ofDays(final long days) {
-        return new TimeValue(days, TimeUnit.DAYS);
+        return of(days, TimeUnit.DAYS);
     }
 
     public static TimeValue ofHours(final long hours) {
-        return new TimeValue(hours, TimeUnit.HOURS);
+        return of(hours, TimeUnit.HOURS);
     }
 
     public static TimeValue ofMillis(final long millis) {
-        return new TimeValue(millis, TimeUnit.MILLISECONDS);
+        return of(millis, TimeUnit.MILLISECONDS);
     }
 
     public static TimeValue ofMinutes(final long minutes) {
-        return new TimeValue(minutes, TimeUnit.MINUTES);
+        return of(minutes, TimeUnit.MINUTES);
     }
 
     public static TimeValue ofSeconds(final long seconds) {
-        return new TimeValue(seconds, TimeUnit.SECONDS);
+        return of(seconds, TimeUnit.SECONDS);
     }
 
     public static boolean isPositive(final TimeValue timeValue) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5f87041d/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
----------------------------------------------------------------------
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 0e5c56f..559b11a 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
@@ -35,31 +35,31 @@ import org.junit.Test;
 public class TestTimeValue {
 
     private void checkToSeconds(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toSeconds(value), new TimeValue(value, timeUnit).toSeconds());
+        Assert.assertEquals(timeUnit.toSeconds(value), TimeValue.of(value, timeUnit).toSeconds());
     }
 
     private void checkToDays(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toDays(value), new TimeValue(value, timeUnit).toDays());
+        Assert.assertEquals(timeUnit.toDays(value), TimeValue.of(value, timeUnit).toDays());
     }
 
     private void checkToHours(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toHours(value), new TimeValue(value, timeUnit).toHours());
+        Assert.assertEquals(timeUnit.toHours(value), TimeValue.of(value, timeUnit).toHours());
     }
 
     private void checkToMinutes(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMinutes(value), new TimeValue(value, timeUnit).toMinutes());
+        Assert.assertEquals(timeUnit.toMinutes(value), TimeValue.of(value, timeUnit).toMinutes());
     }
 
     private void checkToMillis(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMillis(value), new TimeValue(value, timeUnit).toMillis());
+        Assert.assertEquals(timeUnit.toMillis(value), TimeValue.of(value, timeUnit).toMillis());
     }
 
     private void checkToMicros(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMicros(value), new TimeValue(value, timeUnit).toMicros());
+        Assert.assertEquals(timeUnit.toMicros(value), TimeValue.of(value, timeUnit).toMicros());
     }
 
     private void checkToNanos(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toNanos(value), new TimeValue(value, timeUnit).toNanos());
+        Assert.assertEquals(timeUnit.toNanos(value), TimeValue.of(value, timeUnit).toNanos());
     }
 
     @Test