|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.tomgibara.pronto.util.Duration
public final class Duration
This class may be used to convert between a textual representation for a unit of time and its millisecond equivalent or vice versa. Instances are immutable and are safe for concurrent use.
The duration format parsable by this class consists of list of positively valued fields in descending order of unit magnitude. The recognized field units are:
Spaces may appear between fields but not between numbers and units. Unit plurality is inconsequential. A string containing no units (eg. the empty string) may be used to represent zero milliseconds.
Examples of valid durations:
4days 10hours
long units
10m2s500ms
short units
10m2s500ms
mixed units
2hour 1seconds
inconsequential plurality
1day 25hrs
value exceeding prior fieldTo convert a string into milliseconds:
new Duration(str).getTime(); to convert a time in milliseconds into a string:
new Duration(time).toString().
| Constructor Summary | |
|---|---|
Duration(long time)
Creates a duration from a number of milliseconds. |
|
Duration(java.lang.String string)
Creates a duration from its string representation. |
|
| Method Summary | |
|---|---|
int |
compareTo(java.lang.Object obj)
Durations ordered by time. |
boolean |
equals(java.lang.Object obj)
Equality is predicated on the millisecond time field. |
long |
getTime()
The time which was passed to the constructor, or in the case that a string was supplied, the number of milliseconds to which the string equates. |
int |
hashCode()
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Duration(java.lang.String string)
throws java.lang.IllegalArgumentException
string - the string representation of a duration
java.lang.IllegalArgumentException - if the string is null or does not match the required format.
public Duration(long time)
throws java.lang.IllegalArgumentException
time - a time in milliseconds
java.lang.IllegalArgumentException - if the supplied time is negative| Method Detail |
|---|
public long getTime()
public int compareTo(java.lang.Object obj)
compareTo in interface java.lang.Comparableobj - a duration object
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object to test for equality
public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||