Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public class Duration extends Object implements Comparable<Duration>, Serializable, ObjectInputValidation
This will be deprecated once Java 8 is ubiquitous and only serves as an extremely simplified stop-gap.
| Constructor and Description |
|---|
Duration(long seconds,
int nano) |
| Modifier and Type | Method and Description |
|---|---|
static Duration |
between(Instant startInclusive,
Instant endExclusive) |
int |
compareTo(Duration other) |
boolean |
equals(Duration other) |
boolean |
equals(Object obj) |
int |
getNano()
The nanoseconds, to simplify this is always in the positive direction.
|
long |
getSeconds() |
int |
hashCode() |
long |
toNanos()
Gets this duration as a number of nanoseconds only.
|
String |
toString() |
void |
validateObject() |
public static final Duration ZERO
public void validateObject()
throws InvalidObjectException
validateObject in interface ObjectInputValidationInvalidObjectExceptionpublic boolean equals(Duration other)
public int compareTo(Duration other)
compareTo in interface Comparable<Duration>public long getSeconds()
public int getNano()
The nanoseconds, to simplify this is always in the positive direction. For negative durations, this means the nanos goes up from zero to 1 billion, then the seconds go up one (toward zero). This may be counterintuitive if one things of nanoseconds as a fractional part of seconds, but this definition leads to a very clean implementation.
Counting up by nanoseconds:
public long toNanos()
throws ArithmeticException
ArithmeticException - if duration is outside the range representable in nanosecondsCopyright © 2000–2016 AO Industries, Inc.. All rights reserved.