package net.jodah.failsafe.util;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * Duration, consisting of length of a time unit.
 */
public class Duration {
  public static final Duration NONE = new Duration(0, TimeUnit.MILLISECONDS);

  private final long length;
  private final TimeUnit timeUnit;

  public Duration(long length, TimeUnit timeUnit) {
    this.length = length;
    this.timeUnit = timeUnit;
  }

  @Override public boolean equals(Object o)
  {
    return this == o 
        || Duration.class.isInstance(o)
           && toNanos() == Duration.class.cast(o).toNanos();
  }

  @Override public int hashCode()
  {
    return Objects.hash(toNanos(), TimeUnit.NANOSECONDS);
  }
    
  @Override public String toString()
  {
    return "Duration{" + "length=" + length + ", timeUnit=" + timeUnit + '}';
  }

  /**
   * Returns the Duration in nanoseconds.
   */
  public long toNanos() {
    return timeUnit.toNanos(length);
  }

  /**
   * Returns the Duration in milliseconds.
   */
  public long toMillis() {
    return timeUnit.toMillis(length);
  }

  /**
   * Returns the Duration in seconds.
   */
  public long toSeconds() {
    return timeUnit.toSeconds(length);
  }

  /**
   * Returns the Duration in minutes.
   */
  public long toMinutes() {
    return timeUnit.toMinutes(length);
  }

  /**
   * Returns the Duration in hours.
   */
  public long toHours() {
    return timeUnit.toHours(length);
  }

  /**
   * Returns the Duration in days.
   */
  public long toDays() {
    return timeUnit.toDays(length);
  }
}

@@ -48,24 +48,69 @@
 til.
-Objects
+Arrays;%0Aimport java.util.concurrent.TimeUnit
 ;%0A
+%0A
 import 
+static 
 java
@@ -134,16 +134,28 @@
 TimeUnit
+.NANOSECONDS
 ;%0A%0A/**%0A 
@@ -717,21 +717,38 @@
 urn 
-Objects.hash(
+Arrays.hashCode(new Object%5B%5D %7B
 toNa
@@ -754,25 +754,16 @@
 anos(), 
-TimeUnit.
 NANOSECO
@@ -769,19 +769,16 @@
 ONDS
+%7D
 );%0A  %7D%0A
-    
 %0A  @

Add Duration.equals/toString/hashCode + some simple tests for same.