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. UseDuration
insteadADuration
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)
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
Duration
object can be retrieved by calling thegetMilliseconds
method. The value of aDuration
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)
andsubtract(Duration)
methods, each of which returns a new immutableDuration
object.String
values can be converted toDuration
objects using the staticvalueOf
factory methods. TheString
format is the opposite of the one created bytoString()
, which converts aDuration
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 creatingString
values and are parsed as well. TheLocale
is respected and "," will be used instead of "." in the Eurozone.The benchmark method will "benchmark" a
Runnable
or anICode
implementing object, returning aDuration
object that represents the amount of time elapsed in running the code.Finally, the
sleep
method 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 Duration
MAXIMUM
Deprecated.Constant for maximum duration.static Duration
NONE
Deprecated.Constant for no duration.static Duration
ONE_DAY
Deprecated.Constant for one day.static Duration
ONE_HOUR
Deprecated.Constant for one hour.static Duration
ONE_MINUTE
Deprecated.Constant for on minute.static Duration
ONE_SECOND
Deprecated.Constant for one second.static Duration
ONE_WEEK
Deprecated.Constant for one week.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Duration(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 Duration
add(Duration duration)
Deprecated.Adds a givenDuration
to thisDuration
.static Duration
benchmark(Runnable code)
Deprecated.Benchmark the given command.static Duration
benchmark(ICode code, org.slf4j.Logger log)
Deprecated.Benchmark the given command.double
days()
Deprecated.Retrieves the number of days of the currentDuration
.static Duration
days(double days)
Deprecated.Retrieves theDuration
based on days.static Duration
days(int days)
Deprecated.Retrieves theDuration
based on days.static Duration
elapsed(Time start)
Deprecated.Calculates the amount of time elapsed since start time.long
getMilliseconds()
Deprecated.Retrieves the number of milliseconds in thisTime
value.double
hours()
Deprecated.Retrieves the number of hours of the currentDuration
.static Duration
hours(double hours)
Deprecated.Retrieves theDuration
based on hours.static Duration
hours(int hours)
Deprecated.Retrieves theDuration
based on hours.static Duration
milliseconds(double milliseconds)
Deprecated.Retrieves theDuration
based on milliseconds.static Duration
milliseconds(long milliseconds)
Deprecated.Retrieves theDuration
based on milliseconds.double
minutes()
Deprecated.Retrieves the number of minutes of the currentDuration
.static Duration
minutes(double minutes)
Deprecated.Retrieves theDuration
based on minutes.static Duration
minutes(int minutes)
Deprecated.Retrieves theDuration
based on minutes.double
seconds()
Deprecated.Retrieves the number of seconds of the currentDuration
.static Duration
seconds(double seconds)
Deprecated.Retrieves theDuration
based on seconds.static Duration
seconds(int seconds)
Deprecated.Retrieves theDuration
based on seconds.void
sleep()
Deprecated.Sleeps for the currentDuration
.Duration
subtract(Duration that)
Deprecated.Subtracts a givenDuration
from thisDuration
.Duration
toJavaDuration()
Deprecated.String
toString()
Deprecated.Retrieves theString
representation of thisDuration
in days, hours, minutes, seconds or milliseconds, as appropriate.String
toString(Locale locale)
Deprecated.Retrieves theString
representation of thisDuration
in days, hours, minutes, seconds or milliseconds, as appropriate.static Duration
valueOf(long time)
Deprecated.Retrieves the givenlong
as aDuration
.static Duration
valueOf(String string)
Deprecated.Converts the givenString
to a newDuration
object.static Duration
valueOf(String string, Locale locale)
Deprecated.Converts the givenString
to a newDuration
object.void
wait(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
- anICode
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
- aRunnable
- Returns:
- the
Time
value it took to run the code
-
days
public static Duration days(double days)
Deprecated.Retrieves theDuration
based on days.- Parameters:
days
- daysdouble
value- Returns:
- the
Duration
based on days
-
days
public static Duration days(int days)
Deprecated.Retrieves theDuration
based on days.- Parameters:
days
- daysint
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 startTime
- Returns:
- the elapsed period as a
Duration
- Throws:
IllegalStateException
- if startTime
is in the future
-
hours
public static Duration hours(double hours)
Deprecated.Retrieves theDuration
based on hours.- Parameters:
hours
- hoursdouble
value- Returns:
- the
Duration
based on hours
-
hours
public static Duration hours(int hours)
Deprecated.Retrieves theDuration
based on hours.- Parameters:
hours
- hoursint
value- Returns:
- the
Duration
based on hours
-
milliseconds
public static Duration milliseconds(double milliseconds)
Deprecated.Retrieves theDuration
based on milliseconds.- Parameters:
milliseconds
- millisecondsdouble
value- Returns:
- the
Duration
based on milliseconds
-
milliseconds
public static Duration milliseconds(long milliseconds)
Deprecated.Retrieves theDuration
based on milliseconds.- Parameters:
milliseconds
- millisecondslong
value- Returns:
- the
Duration
based on milliseconds
-
minutes
public static Duration minutes(double minutes)
Deprecated.Retrieves theDuration
based on minutes.- Parameters:
minutes
- minutesdouble
value- Returns:
- the
Duration
based on minutes
-
minutes
public static Duration minutes(int minutes)
Deprecated.Retrieves theDuration
based on minutes.- Parameters:
minutes
- minutesint
value- Returns:
- the
Duration
based on minutes
-
seconds
public static Duration seconds(double seconds)
Deprecated.Retrieves theDuration
based on seconds.- Parameters:
seconds
- secondsdouble
value- Returns:
- the
Duration
based on seconds
-
seconds
public static Duration seconds(int seconds)
Deprecated.Retrieves theDuration
based on seconds.- Parameters:
seconds
- secondsint
value- Returns:
- the
Duration
based on seconds
-
valueOf
public static Duration valueOf(long time)
Deprecated.Retrieves the givenlong
as aDuration
.- Parameters:
time
- the durationlong
value in milliseconds- Returns:
- the
Duration
value
-
valueOf
public static Duration valueOf(String string) throws StringValueConversionException
Deprecated.Converts the givenString
to a newDuration
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
- aString
to parse- Returns:
- the
Duration
value of the givenString
- Throws:
StringValueConversionException
-
valueOf
public static Duration valueOf(String string, Locale locale) throws StringValueConversionException
Deprecated.Converts the givenString
to a newDuration
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
- aString
to parselocale
- theLocale
used for parsing- Returns:
- the
Duration
value of the givenString
- Throws:
StringValueConversionException
-
add
public Duration add(Duration duration)
Deprecated.Adds a givenDuration
to thisDuration
.- Parameters:
duration
- theDuration
to add- Returns:
- the sum of the
Duration
s
-
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 givenDuration
from thisDuration
.- Parameters:
that
- theDuration
to subtract- Returns:
- this
Duration
minus 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 theString
representation of thisDuration
in days, hours, minutes, seconds or milliseconds, as appropriate. Uses the defaultLocale
.
-
toString
public String toString(Locale locale)
Deprecated.Retrieves theString
representation of thisDuration
in days, hours, minutes, seconds or milliseconds, as appropriate.- Parameters:
locale
- aLocale
- Returns:
- a
String
representation
-
toJavaDuration
public Duration toJavaDuration()
Deprecated.- Returns:
- returns a
Duration
-
getMilliseconds
public final long getMilliseconds()
Deprecated.Retrieves the number of milliseconds in thisTime
value.- Returns:
- the number of milliseconds in this
Time
value
-
-