Class Duration
- java.lang.Object
-
- org.apache.wicket.util.value.LongValue
-
- org.apache.wicket.util.time.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. UseDurationinsteadADurationis 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)orhours(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 usingMath.round().The precise number of milliseconds represented by a
Durationobject can be retrieved by calling thegetMillisecondsmethod. The value of aDurationobject 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)andsubtract(Duration)methods, each of which returns a new immutableDurationobject.Stringvalues can be converted toDurationobjects using the staticvalueOffactory methods. TheStringformat is the opposite of the one created bytoString(), which converts aDurationobject 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 creatingStringvalues and are parsed as well. TheLocaleis respected and "," will be used instead of "." in the Eurozone.The benchmark method will "benchmark" a
Runnableor anICodeimplementing object, returning aDurationobject that represents the amount of time elapsed in running the code.Finally, the
sleepmethod will sleep for the value of aDuration.- Since:
- 1.2.6
- Author:
- Jonathan Locke
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static DurationMAXIMUMDeprecated.Constant for maximum duration.static DurationNONEDeprecated.Constant for no duration.static DurationONE_DAYDeprecated.Constant for one day.static DurationONE_HOURDeprecated.Constant for one hour.static DurationONE_MINUTEDeprecated.Constant for on minute.static DurationONE_SECONDDeprecated.Constant for one second.static DurationONE_WEEKDeprecated.Constant for one week.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDuration(long milliseconds)Deprecated.Private constructor forces use of static factory methods.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Durationadd(Duration duration)Deprecated.Adds a givenDurationto thisDuration.static Durationbenchmark(Runnable code)Deprecated.Benchmark the given command.static Durationbenchmark(ICode code, org.slf4j.Logger log)Deprecated.Benchmark the given command.doubledays()Deprecated.Retrieves the number of days of the currentDuration.static Durationdays(double days)Deprecated.Retrieves theDurationbased on days.static Durationdays(int days)Deprecated.Retrieves theDurationbased on days.static Durationelapsed(Time start)Deprecated.Calculates the amount of time elapsed since start time.longgetMilliseconds()Deprecated.Retrieves the number of milliseconds in thisTimevalue.doublehours()Deprecated.Retrieves the number of hours of the currentDuration.static Durationhours(double hours)Deprecated.Retrieves theDurationbased on hours.static Durationhours(int hours)Deprecated.Retrieves theDurationbased on hours.static Durationmilliseconds(double milliseconds)Deprecated.Retrieves theDurationbased on milliseconds.static Durationmilliseconds(long milliseconds)Deprecated.Retrieves theDurationbased on milliseconds.doubleminutes()Deprecated.Retrieves the number of minutes of the currentDuration.static Durationminutes(double minutes)Deprecated.Retrieves theDurationbased on minutes.static Durationminutes(int minutes)Deprecated.Retrieves theDurationbased on minutes.doubleseconds()Deprecated.Retrieves the number of seconds of the currentDuration.static Durationseconds(double seconds)Deprecated.Retrieves theDurationbased on seconds.static Durationseconds(int seconds)Deprecated.Retrieves theDurationbased on seconds.voidsleep()Deprecated.Sleeps for the currentDuration.Durationsubtract(Duration that)Deprecated.Subtracts a givenDurationfrom thisDuration.DurationtoJavaDuration()Deprecated.StringtoString()Deprecated.Retrieves theStringrepresentation of thisDurationin days, hours, minutes, seconds or milliseconds, as appropriate.StringtoString(Locale locale)Deprecated.Retrieves theStringrepresentation of thisDurationin days, hours, minutes, seconds or milliseconds, as appropriate.static DurationvalueOf(long time)Deprecated.Retrieves the givenlongas aDuration.static DurationvalueOf(String string)Deprecated.Converts the givenStringto a newDurationobject.static DurationvalueOf(String string, Locale locale)Deprecated.Converts the givenStringto a newDurationobject.voidwait(Object object)Deprecated.Wait for this duration on the given monitor-
Methods inherited from class org.apache.wicket.util.value.LongValue
compareTo, equals, greaterThan, greaterThan, greaterThanOrEqual, greaterThanOrEqual, hashCode, lessThan, lessThan, lessThanOrEqual, lessThanOrEqual, max, maxNullSafe, min
-
-
-
-
Field Detail
-
ONE_MINUTE
public static final Duration ONE_MINUTE
Deprecated.Constant for on minute.
-
ONE_SECOND
public static final Duration ONE_SECOND
Deprecated.Constant for one second.
-
-
Constructor Detail
-
Duration
protected Duration(long milliseconds)
Deprecated.Private constructor forces use of static factory methods.- Parameters:
milliseconds- number of milliseconds in thisDuration
-
-
Method Detail
-
benchmark
public static Duration benchmark(ICode code, org.slf4j.Logger log)
Deprecated.Benchmark the given command.- Parameters:
code- anICodelog- optional logger to use with errors and exceptions- Returns:
- the
Timevalue it took to run the code
-
benchmark
public static Duration benchmark(Runnable code)
Deprecated.Benchmark the given command.- Parameters:
code- aRunnable- Returns:
- the
Timevalue it took to run the code
-
days
public static Duration days(double days)
Deprecated.Retrieves theDurationbased on days.- Parameters:
days- daysdoublevalue- Returns:
- the
Durationbased on days
-
days
public static Duration days(int days)
Deprecated.Retrieves theDurationbased on days.- Parameters:
days- daysintvalue- Returns:
- the
Durationbased on days
-
elapsed
public static Duration elapsed(Time start)
Deprecated.Calculates the amount of time elapsed since start time.- Parameters:
start- the startTime- Returns:
- the elapsed period as a
Duration - Throws:
IllegalStateException- if startTimeis in the future
-
hours
public static Duration hours(double hours)
Deprecated.Retrieves theDurationbased on hours.- Parameters:
hours- hoursdoublevalue- Returns:
- the
Durationbased on hours
-
hours
public static Duration hours(int hours)
Deprecated.Retrieves theDurationbased on hours.- Parameters:
hours- hoursintvalue- Returns:
- the
Durationbased on hours
-
milliseconds
public static Duration milliseconds(double milliseconds)
Deprecated.Retrieves theDurationbased on milliseconds.- Parameters:
milliseconds- millisecondsdoublevalue- Returns:
- the
Durationbased on milliseconds
-
milliseconds
public static Duration milliseconds(long milliseconds)
Deprecated.Retrieves theDurationbased on milliseconds.- Parameters:
milliseconds- millisecondslongvalue- Returns:
- the
Durationbased on milliseconds
-
minutes
public static Duration minutes(double minutes)
Deprecated.Retrieves theDurationbased on minutes.- Parameters:
minutes- minutesdoublevalue- Returns:
- the
Durationbased on minutes
-
minutes
public static Duration minutes(int minutes)
Deprecated.Retrieves theDurationbased on minutes.- Parameters:
minutes- minutesintvalue- Returns:
- the
Durationbased on minutes
-
seconds
public static Duration seconds(double seconds)
Deprecated.Retrieves theDurationbased on seconds.- Parameters:
seconds- secondsdoublevalue- Returns:
- the
Durationbased on seconds
-
seconds
public static Duration seconds(int seconds)
Deprecated.Retrieves theDurationbased on seconds.- Parameters:
seconds- secondsintvalue- Returns:
- the
Durationbased on seconds
-
valueOf
public static Duration valueOf(long time)
Deprecated.Retrieves the givenlongas aDuration.- Parameters:
time- the durationlongvalue in milliseconds- Returns:
- the
Durationvalue
-
valueOf
public static Duration valueOf(String string) throws StringValueConversionException
Deprecated.Converts the givenStringto a newDurationobject. 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- aStringto parse- Returns:
- the
Durationvalue of the givenString - Throws:
StringValueConversionException
-
valueOf
public static Duration valueOf(String string, Locale locale) throws StringValueConversionException
Deprecated.Converts the givenStringto a newDurationobject. 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- aStringto parselocale- theLocaleused for parsing- Returns:
- the
Durationvalue of the givenString - Throws:
StringValueConversionException
-
add
public Duration add(Duration duration)
Deprecated.Adds a givenDurationto thisDuration.- Parameters:
duration- theDurationto add- Returns:
- the sum of the
Durations
-
days
public final double days()
Deprecated.Retrieves the number of days of the currentDuration.- Returns:
- number of days of the current
Duration
-
hours
public final double hours()
Deprecated.Retrieves the number of hours of the currentDuration.- Returns:
- number of hours of the current
Duration
-
minutes
public final double minutes()
Deprecated.Retrieves the number of minutes of the currentDuration.- Returns:
- number of minutes of the current
Duration
-
seconds
public final double seconds()
Deprecated.Retrieves the number of seconds of the currentDuration.- Returns:
- number of seconds of the current
Duration
-
sleep
public final void sleep()
Deprecated.Sleeps for the currentDuration.
-
subtract
public Duration subtract(Duration that)
Deprecated.Subtracts a givenDurationfrom thisDuration.- Parameters:
that- theDurationto subtract- Returns:
- this
Durationminus thatDuration
-
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 theStringrepresentation of thisDurationin days, hours, minutes, seconds or milliseconds, as appropriate. Uses the defaultLocale.
-
toString
public String toString(Locale locale)
Deprecated.Retrieves theStringrepresentation of thisDurationin days, hours, minutes, seconds or milliseconds, as appropriate.- Parameters:
locale- aLocale- Returns:
- a
Stringrepresentation
-
toJavaDuration
public Duration toJavaDuration()
Deprecated.- Returns:
- returns a
Duration
-
getMilliseconds
public final long getMilliseconds()
Deprecated.Retrieves the number of milliseconds in thisTimevalue.- Returns:
- the number of milliseconds in this
Timevalue
-
-