|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectwicket.util.value.LongValue
wicket.util.time.AbstractTimeValue
wicket.util.time.Duration
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):
or double precision floating point values like days(3.2):
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 milliseconds() 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:
Values can be added and subtracted using the add() and subtract() 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.
| Field Summary | |
static Duration |
NONE
Constant for no duration. |
static Duration |
ONE_DAY
Constant for one day. |
static Duration |
ONE_HOUR
Constant for one hour. |
static Duration |
ONE_MINUTE
Constant for on minute. |
static Duration |
ONE_SECOND
Constant for one second. |
static Duration |
ONE_WEEK
Constant for one week. |
| Fields inherited from class wicket.util.value.LongValue |
value |
| Method Summary | |
Duration |
add(Duration duration)
Adds a given duration to this duration. |
static Duration |
benchmark(ICode code,
org.apache.commons.logging.Log log)
|
static Duration |
benchmark(java.lang.Runnable code)
Benchmark the given command. |
double |
days()
Gets number of days of the current duration. |
static Duration |
days(double days)
Gets the duration based on days. |
static Duration |
days(int days)
Gets the duration based on days. |
static Duration |
elapsed(Time start)
The amount of time elapsed since start time |
long |
getMilliseconds()
|
double |
hours()
Gets number of hours of the current duration. |
static Duration |
hours(double hours)
Gets the duration based on hours. |
static Duration |
hours(int hours)
Gets the duration based on hours. |
static Duration |
milliseconds(double milliseconds)
Gets the duration based on milliseconds. |
static Duration |
milliseconds(long milliseconds)
Gets the duration based on miliseconds. |
double |
minutes()
Gets number of minutes of the current duration. |
static Duration |
minutes(double minutes)
Gets the duration based on minutes. |
static Duration |
minutes(int minutes)
Gets the duration based on minutes. |
double |
seconds()
Gets number of seconds of the current duration. |
static Duration |
seconds(double seconds)
Gets the duration based on seconds. |
static Duration |
seconds(int seconds)
Gets the duration based on seconds. |
void |
sleep()
Sleep for the current duration. |
Duration |
subtract(Duration that)
Subtract a given duration from this duration. |
java.lang.String |
toString()
Gets the string representation of this duration in days, hours, minutes, seconds or milliseconds, as appropriate. |
java.lang.String |
toString(java.util.Locale locale)
Gets the string representation of this duration in days, hours, minutes, seconds or milliseconds, as appropriate. |
static Duration |
valueOf(long time)
Gets the given long as a duration. |
static Duration |
valueOf(java.lang.String string)
Converts the given string to a new duration object. |
static Duration |
valueOf(java.lang.String string,
java.util.Locale locale)
Converts the given string to a new Duration object. |
| Methods inherited from class wicket.util.value.LongValue |
compareTo, equals, greaterThan, greaterThan, hashCode, lessThan, lessThan |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final Duration NONE
public static final Duration ONE_DAY
public static final Duration ONE_HOUR
public static final Duration ONE_MINUTE
public static final Duration ONE_SECOND
public static final Duration ONE_WEEK
| Method Detail |
public static Duration benchmark(ICode code,
org.apache.commons.logging.Log log)
code - The codelog - Optional log to use with errors and exceptions
public static Duration benchmark(java.lang.Runnable code)
code - The code
public static Duration days(double days)
days -
public static Duration days(int days)
days -
public static Duration elapsed(Time start)
start - The start time
public static Duration hours(double hours)
hours -
public static Duration hours(int hours)
hours -
public static Duration milliseconds(double milliseconds)
milliseconds -
public static Duration milliseconds(long milliseconds)
milliseconds -
public static Duration minutes(double minutes)
minutes -
public static Duration minutes(int minutes)
minutes -
public static Duration seconds(double seconds)
seconds -
public static Duration seconds(int seconds)
seconds -
public static Duration valueOf(long time)
time - The duration value in milliseconds
public static Duration valueOf(java.lang.String string)
throws StringValueConversionException
string - The string to parse
StringValueConversionException
public static Duration valueOf(java.lang.String string,
java.util.Locale locale)
throws StringValueConversionException
string - The string to parselocale - Locale used for parsing
StringValueConversionExceptionpublic Duration add(Duration duration)
duration - The duration to add
public final double days()
public final double hours()
public final double minutes()
public final double seconds()
public final void sleep()
public Duration subtract(Duration that)
that - The duration to subtract
public java.lang.String toString()
toString in class LongValuepublic java.lang.String toString(java.util.Locale locale)
locale - the locale
public final long getMilliseconds()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||