@Test public void testNormalize() { Duration d = new Duration(0, 0); d.secs = 1; d.nsecs = 1000000000; d.normalize(); assertEquals(2, d.secs); assertEquals(0, d.nsecs); d.secs = 1; d.nsecs = -1; d.normalize(); assertEquals(0, d.secs); assertEquals(1000000000 - 1, d.nsecs); }
public void normalize() { while (nsecs < 0) { nsecs += 1000000000; secs -= 1; } while (nsecs >= 1000000000) { nsecs -= 1000000000; secs += 1; } }
Duration implements Comparable<Duration> { public void normalize() { while (nsecs < 0) { nsecs += 1000000000; secs -= 1; } while (nsecs >= 1000000000) { nsecs -= 1000000000; secs += 1; } } }
Duration implements Comparable<Duration> { public void normalize() { while (nsecs < 0) { nsecs += 1000000000; secs -= 1; } while (nsecs >= 1000000000) { nsecs -= 1000000000; secs += 1; } } Duration();  Duration(int secs, int nsecs);  Duration(double secs);  Duration(Duration t); }
Duration implements Comparable<Duration> { public void normalize() { while (nsecs < 0) { nsecs += 1000000000; secs -= 1; } while (nsecs >= 1000000000) { nsecs -= 1000000000; secs += 1; } } Duration();  Duration(int secs, int nsecs);  Duration(double secs);  Duration(Duration t); Duration add(Duration d); Duration subtract(Duration d); static Duration fromMillis(long durationInMillis); static Duration fromNano(long durationInNs); void normalize(); long totalNsecs(); boolean isZero(); boolean isPositive(); boolean isNegative(); @Override String toString(); @Override int hashCode(); @Override /** * Check for equality between Time objects. * equals() does not normalize Time representations, so fields must match exactly. */ boolean equals(Object obj); @Override int compareTo(Duration d); }
Duration implements Comparable<Duration> { public void normalize() { while (nsecs < 0) { nsecs += 1000000000; secs -= 1; } while (nsecs >= 1000000000) { nsecs -= 1000000000; secs += 1; } } Duration();  Duration(int secs, int nsecs);  Duration(double secs);  Duration(Duration t); Duration add(Duration d); Duration subtract(Duration d); static Duration fromMillis(long durationInMillis); static Duration fromNano(long durationInNs); void normalize(); long totalNsecs(); boolean isZero(); boolean isPositive(); boolean isNegative(); @Override String toString(); @Override int hashCode(); @Override /** * Check for equality between Time objects. * equals() does not normalize Time representations, so fields must match exactly. */ boolean equals(Object obj); @Override int compareTo(Duration d); static final Duration MAX_VALUE; public int secs; public int nsecs; }