Class Duration

  • All Implemented Interfaces:
    Serializable, Comparable<Duration>

    @Deprecated
    public class Duration
    extends Object
    implements Comparable<Duration>, Serializable
    Deprecated.
    Please use standard Java 8 classes.
    Wraps a duration as the number of seconds as well as positive nanoseconds into an immutable value type.

    This will be deprecated once Java 8 is ubiquitous and only serves as an extremely simplified stop-gap.

    Author:
    AO Industries, Inc.
    See Also:
    Serialized Form
    • Field Detail

      • ZERO

        public static final Duration ZERO
        Deprecated.
    • Constructor Detail

      • Duration

        public Duration​(long seconds,
                        int nano)
        Deprecated.
    • Method Detail

      • readResolve

        protected Object readResolve()
        Deprecated.
      • equals

        public boolean equals​(Object obj)
        Deprecated.
        Overrides:
        equals in class Object
      • equals

        public boolean equals​(Duration other)
        Deprecated.
      • hashCode

        public int hashCode()
        Deprecated.
        Overrides:
        hashCode in class Object
      • getSeconds

        public long getSeconds()
        Deprecated.
      • getNano

        public int getNano()
        Deprecated.

        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:

        1. -1.999999998
        2. -1.999999999
        3. 0.000000000
        4. 0.000000001
        5. 0.000000002
      • toNanos

        public long toNanos()
                     throws ArithmeticException
        Deprecated.
        Gets this duration as a number of nanoseconds only. This covers a range around -292 years to +292 years.
        Throws:
        ArithmeticException - if duration is outside the range representable in nanoseconds