You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2017/04/19 20:12:16 UTC

svn commit: r1791967 - in /httpcomponents/httpcore/trunk/httpcore5/src: main/java/org/apache/hc/core5/util/TimeValue.java test/java/org/apache/hc/core5/util/TestTimeValue.java

Author: ggregory
Date: Wed Apr 19 20:12:15 2017
New Revision: 1791967

URL: http://svn.apache.org/viewvc?rev=1791967&view=rev
Log:
HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Reuse factory method.

Modified:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java?rev=1791967&r1=1791966&r2=1791967&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java Wed Apr 19 20:12:15 2017
@@ -41,9 +41,9 @@ import org.apache.hc.core5.annotation.Th
 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) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java?rev=1791967&r1=1791966&r2=1791967&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java Wed Apr 19 20:12:15 2017
@@ -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