Class Duration

  • All Implemented Interfaces:
    Serializable, Comparable<LongValue>

    @Deprecated
    public class Duration
    extends LongValue
    Deprecated.
    Since Wicket 9 this class is obsolete and no more used. It will be removed in Wicket 10. Use Duration instead
    A Duration is an immutable length of time stored as a number of milliseconds. Various factory and conversion methods are available for convenience.

    These static factory methods allow easy construction of value objects using either long values like seconds(2034) or hours(3):

    • Duration.milliseconds(long)
    • Duration.seconds(int)
    • Duration.minutes(int)
    • Duration.hours(int)
    • Duration.days(int)

    ...or double-precision floating point values like days(3.2):

    • Duration.milliseconds(double)
    • Duration.seconds(double)
    • Duration.minutes(double)
    • Duration.hours(double)
    • Duration.days(double)

    In the case of milliseconds(double), the value will be rounded off to the nearest integral millisecond using Math.round().

    The precise number of milliseconds represented by a Duration object can be retrieved by calling the getMilliseconds method. The value of a Duration object in a given unit like days or hours can be retrieved by calling one of the following unit methods, each of which returns a double-precision floating point number:

    • seconds()
    • minutes()
    • hours()
    • days()

    Values can be added and subtracted using the add(Duration) and subtract(Duration) methods, each of which returns a new immutable Duration object.

    String values can be converted to Duration objects using the static valueOf factory methods. The String format is the opposite of the one created by toString(), which converts a Duration object to a readable form, such as "3.2 hours" or "32.5 minutes". Valid units are: milliseconds, seconds, minutes hours and days. Correct English plural forms are used in creating String values and are parsed as well. The Locale is respected and "," will be used instead of "." in the Eurozone.

    The benchmark method will "benchmark" a Runnable or an ICode implementing object, returning a Duration object that represents the amount of time elapsed in running the code.

    Finally, the sleep method will sleep for the value of a Duration.

    Since:
    1.2.6
    Author:
    Jonathan Locke
    See Also:
    Serialized Form
    • Field Detail

      • MAXIMUM

        public static final Duration MAXIMUM
        Deprecated.
        Constant for maximum duration.
      • NONE

        public static final Duration NONE
        Deprecated.
        Constant for no duration.
      • ONE_DAY

        public static final Duration ONE_DAY
        Deprecated.
        Constant for one day.
      • ONE_HOUR

        public static final Duration ONE_HOUR
        Deprecated.
        Constant for one hour.
      • ONE_SECOND

        public static final Duration ONE_SECOND
        Deprecated.
        Constant for one second.
      • ONE_WEEK

        public static final Duration ONE_WEEK
        Deprecated.
        Constant for one week.
    • Constructor Detail

      • Duration

        protected Duration​(long milliseconds)
        Deprecated.
        Private constructor forces use of static factory methods.
        Parameters:
        milliseconds - number of milliseconds in this Duration
    • Method Detail

      • benchmark

        public static Duration benchmark​(ICode code,
                                         org.slf4j.Logger log)
        Deprecated.
        Benchmark the given command.
        Parameters:
        code - an ICode
        log - optional logger to use with errors and exceptions
        Returns:
        the Time value it took to run the code
      • benchmark

        public static Duration benchmark​(Runnable code)
        Deprecated.
        Benchmark the given command.
        Parameters:
        code - a Runnable
        Returns:
        the Time value it took to run the code
      • days

        public static Duration days​(double days)
        Deprecated.
        Retrieves the Duration based on days.
        Parameters:
        days - days double value
        Returns:
        the Duration based on days
      • days

        public static Duration days​(int days)
        Deprecated.
        Retrieves the Duration based on days.
        Parameters:
        days - days int value
        Returns:
        the Duration based on days
      • elapsed

        public static Duration elapsed​(Time start)
        Deprecated.
        Calculates the amount of time elapsed since start time.
        Parameters:
        start - the start Time
        Returns:
        the elapsed period as a Duration
        Throws:
        IllegalStateException - if start Time is in the future
      • hours

        public static Duration hours​(double hours)
        Deprecated.
        Retrieves the Duration based on hours.
        Parameters:
        hours - hours double value
        Returns:
        the Duration based on hours
      • hours

        public static Duration hours​(int hours)
        Deprecated.
        Retrieves the Duration based on hours.
        Parameters:
        hours - hours int value
        Returns:
        the Duration based on hours
      • milliseconds

        public static Duration milliseconds​(double milliseconds)
        Deprecated.
        Retrieves the Duration based on milliseconds.
        Parameters:
        milliseconds - milliseconds double value
        Returns:
        the Duration based on milliseconds
      • milliseconds

        public static Duration milliseconds​(long milliseconds)
        Deprecated.
        Retrieves the Duration based on milliseconds.
        Parameters:
        milliseconds - milliseconds long value
        Returns:
        the Duration based on milliseconds
      • minutes

        public static Duration minutes​(double minutes)
        Deprecated.
        Retrieves the Duration based on minutes.
        Parameters:
        minutes - minutes double value
        Returns:
        the Duration based on minutes
      • minutes

        public static Duration minutes​(int minutes)
        Deprecated.
        Retrieves the Duration based on minutes.
        Parameters:
        minutes - minutes int value
        Returns:
        the Duration based on minutes
      • seconds

        public static Duration seconds​(double seconds)
        Deprecated.
        Retrieves the Duration based on seconds.
        Parameters:
        seconds - seconds double value
        Returns:
        the Duration based on seconds
      • seconds

        public static Duration seconds​(int seconds)
        Deprecated.
        Retrieves the Duration based on seconds.
        Parameters:
        seconds - seconds int value
        Returns:
        the Duration based on seconds
      • valueOf

        public static Duration valueOf​(long time)
        Deprecated.
        Retrieves the given long as a Duration.
        Parameters:
        time - the duration long value in milliseconds
        Returns:
        the Duration value
      • valueOf

        public static Duration valueOf​(String string)
                                throws StringValueConversionException
        Deprecated.
        Converts the given String to a new Duration object. The string can take the form of a floating point number followed by a number of milliseconds, seconds, minutes, hours or days. For example "6 hours" or "3.4 days". Parsing is case-insensitive.
        Parameters:
        string - a String to parse
        Returns:
        the Duration value of the given String
        Throws:
        StringValueConversionException
      • valueOf

        public static Duration valueOf​(String string,
                                       Locale locale)
                                throws StringValueConversionException
        Deprecated.
        Converts the given String to a new Duration object. The string can take the form of a floating point number followed by a number of milliseconds, seconds, minutes, hours or days. For example "6 hours" or "3.4 days". Parsing is case-insensitive.
        Parameters:
        string - a String to parse
        locale - the Locale used for parsing
        Returns:
        the Duration value of the given String
        Throws:
        StringValueConversionException
      • add

        public Duration add​(Duration duration)
        Deprecated.
        Adds a given Duration to this Duration.
        Parameters:
        duration - the Duration to add
        Returns:
        the sum of the Durations
      • days

        public final double days()
        Deprecated.
        Retrieves the number of days of the current Duration.
        Returns:
        number of days of the current Duration
      • hours

        public final double hours()
        Deprecated.
        Retrieves the number of hours of the current Duration.
        Returns:
        number of hours of the current Duration
      • minutes

        public final double minutes()
        Deprecated.
        Retrieves the number of minutes of the current Duration.
        Returns:
        number of minutes of the current Duration
      • seconds

        public final double seconds()
        Deprecated.
        Retrieves the number of seconds of the current Duration.
        Returns:
        number of seconds of the current Duration
      • sleep

        public final void sleep()
        Deprecated.
        Sleeps for the current Duration.
      • subtract

        public Duration subtract​(Duration that)
        Deprecated.
        Subtracts a given Duration from this Duration.
        Parameters:
        that - the Duration to subtract
        Returns:
        this Duration minus that Duration
      • wait

        public void wait​(Object object)
        Deprecated.
        Wait for this duration on the given monitor
        Parameters:
        object - The monitor to wait on
      • toString

        public String toString()
        Deprecated.
        Retrieves the String representation of this Duration in days, hours, minutes, seconds or milliseconds, as appropriate. Uses the default Locale .
        Overrides:
        toString in class LongValue
        Returns:
        a String representation
      • toString

        public String toString​(Locale locale)
        Deprecated.
        Retrieves the String representation of this Duration in days, hours, minutes, seconds or milliseconds, as appropriate.
        Parameters:
        locale - a Locale
        Returns:
        a String representation
      • getMilliseconds

        public final long getMilliseconds()
        Deprecated.
        Retrieves the number of milliseconds in this Time value.
        Returns:
        the number of milliseconds in this Time value