|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectat.molindo.thirdparty.org.apache.wicket.util.value.LongValue
at.molindo.thirdparty.org.apache.wicket.util.time.Duration
public class 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):
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.
| Field Summary | |
|---|---|
static Duration |
MAXIMUM
Constant for maximum duration. |
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 at.molindo.thirdparty.org.apache.wicket.util.value.LongValue |
|---|
value |
| Constructor Summary | |
|---|---|
protected |
Duration(long milliseconds)
Private constructor forces use of static factory methods. |
| Method Summary | |
|---|---|
Duration |
add(Duration duration)
Adds a given Duration to this Duration. |
static Duration |
benchmark(Runnable code)
Benchmark the given command. |
double |
days()
Retrieves the number of days of the current Duration. |
static Duration |
days(double days)
Retrieves the Duration based on days. |
static Duration |
days(int days)
Retrieves the Duration based on days. |
static Duration |
elapsed(Time start)
Calculates the amount of time elapsed since start time. |
long |
getMilliseconds()
Retrieves the number of milliseconds in this Time value. |
double |
hours()
Retrieves the number of hours of the current Duration. |
static Duration |
hours(double hours)
Retrieves the Duration based on hours. |
static Duration |
hours(int hours)
Retrieves the Duration based on hours. |
static Duration |
milliseconds(double milliseconds)
Retrieves the Duration based on milliseconds. |
static Duration |
milliseconds(long milliseconds)
Retrieves the Duration based on milliseconds. |
double |
minutes()
Retrieves the number of minutes of the current Duration. |
static Duration |
minutes(double minutes)
Retrieves the Duration based on minutes. |
static Duration |
minutes(int minutes)
Retrieves the Duration based on minutes. |
double |
seconds()
Retrieves the number of seconds of the current Duration. |
static Duration |
seconds(double seconds)
Retrieves the Duration based on seconds. |
static Duration |
seconds(int seconds)
Retrieves the Duration based on seconds. |
void |
sleep()
Sleeps for the current Duration. |
Duration |
subtract(Duration that)
Subtracts a given Duration from this Duration. |
String |
toString()
Retrieves the String representation of this
Duration in days, hours, minutes, seconds or milliseconds,
as appropriate. |
String |
toString(Locale locale)
Retrieves the String representation of this
Duration in days, hours, minutes, seconds or milliseconds,
as appropriate. |
static Duration |
valueOf(long time)
Retrieves the given long as a Duration. |
void |
wait(Object object)
Wait for this duration on the given monitor |
| Methods inherited from class at.molindo.thirdparty.org.apache.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 MAXIMUM
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
| Constructor Detail |
|---|
protected Duration(long milliseconds)
milliseconds - number of milliseconds in this Duration| Method Detail |
|---|
public static Duration benchmark(Runnable code)
code - a Runnable
Time value it took to run the codepublic static Duration days(double days)
Duration based on days.
days - days double value
Duration based on dayspublic static Duration days(int days)
Duration based on days.
days - days int value
Duration based on dayspublic static Duration elapsed(Time start)
start - the start Time
Duration
IllegalStateException - if start Time is in the futurepublic static Duration hours(double hours)
Duration based on hours.
hours - hours double value
Duration based on hourspublic static Duration hours(int hours)
Duration based on hours.
hours - hours int value
Duration based on hourspublic static Duration milliseconds(double milliseconds)
Duration based on milliseconds.
milliseconds - milliseconds double value
Duration based on millisecondspublic static Duration milliseconds(long milliseconds)
Duration based on milliseconds.
milliseconds - milliseconds long value
Duration based on millisecondspublic static Duration minutes(double minutes)
Duration based on minutes.
minutes - minutes double value
Duration based on minutespublic static Duration minutes(int minutes)
Duration based on minutes.
minutes - minutes int value
Duration based on minutespublic static Duration seconds(double seconds)
Duration based on seconds.
seconds - seconds double value
Duration based on secondspublic static Duration seconds(int seconds)
Duration based on seconds.
seconds - seconds int value
Duration based on secondspublic static Duration valueOf(long time)
long as a Duration.
time - the duration long value in milliseconds
Duration valuepublic Duration add(Duration duration)
Duration to this Duration.
duration - the Duration to add
Durationspublic final double days()
Duration.
Durationpublic final double hours()
Duration.
Durationpublic final double minutes()
Duration.
Durationpublic final double seconds()
Duration.
Durationpublic final void sleep()
Duration.
public Duration subtract(Duration that)
Duration from this Duration.
that - the Duration to subtract
Duration minus that Durationpublic void wait(Object object)
object - The monitor to wait onpublic String toString()
String representation of this
Duration in days, hours, minutes, seconds or milliseconds,
as appropriate. Uses the default Locale .
toString in class LongValueString representationpublic String toString(Locale locale)
String representation of this
Duration in days, hours, minutes, seconds or milliseconds,
as appropriate.
locale - a Locale
String representationpublic final long getMilliseconds()
Time value.
Time value
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||