com.isti.util
Class TimeUnits

java.lang.Object
  extended by com.isti.util.TimeUnits
All Implemented Interfaces:
TimeConstants

public class TimeUnits
extends java.lang.Object
implements TimeConstants

Time Units (millisecond, second, minute, hour, day)


Field Summary
static TimeUnits DAY
          Day
static TimeUnits HOUR
          Hour
static TimeUnits MILLISECOND
          Millisecond
static TimeUnits MINUTE
          Minute
static TimeUnits SECOND
          Second
static TimeUnits[] TIME_UNITS
          Time units array
 
Fields inherited from interface com.isti.util.TimeConstants
HOURS_PER_DAY, MINUTES_PER_DAY, MINUTES_PER_HOUR, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, SECONDS_PER_DAY, SECONDS_PER_MINUTE
 
Constructor Summary
  TimeUnits(java.lang.String unitsText)
          Find the time units for the specified units text.
protected TimeUnits(java.lang.String text, long msPerUnit)
          Create the time units.
 
Method Summary
static long getMilliseconds(java.lang.String s, TimeUnits timeUnits)
          Get the number of milliseconds represented by the text and may include text for the time units.
 long getMsPerUnit()
          Get the number of milliseconds per unit.
static java.lang.String getTextValueWithTimeUnits(java.lang.String s, TimeUnits defaultValue, long minimumValue)
          Gets the text value with time units.
 java.lang.String getTextWithValue(long value)
          Get the text for the value and time units.
protected static java.lang.String getTextWithValue(long value, java.lang.String unitsText)
          Get the text for the value and time units text.
protected static java.lang.String getTextWithValue(long value, TimeUnits timeUnits)
          Get the text for the value and time units text.
 java.lang.String getTextWithValue(java.lang.String valueText)
          Get the text for the value and time units.
protected static java.lang.String getTextWithValue(java.lang.String valueText, java.lang.String unitsText)
          Get the text for the value and time units text.
protected static TimeUnits parseTimeUnits(java.lang.String unitsText, TimeUnits defaultValue)
          Parse the units text.
 java.lang.String toString()
          The singular text for the time units.
 java.lang.String toString(boolean pluralFlag)
          The text for the time units.
 java.lang.String toString(long value)
          The text for the time units.
static TimeUnits valueOf(java.lang.String s)
          Gets the time units for the specified text.
static TimeUnits valueOf(java.lang.String s, TimeUnits defaultValue)
          Gets the time units for the specified text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MILLISECOND

public static final TimeUnits MILLISECOND
Millisecond


SECOND

public static final TimeUnits SECOND
Second


MINUTE

public static final TimeUnits MINUTE
Minute


HOUR

public static final TimeUnits HOUR
Hour


DAY

public static final TimeUnits DAY
Day


TIME_UNITS

public static final TimeUnits[] TIME_UNITS
Time units array

Constructor Detail

TimeUnits

public TimeUnits(java.lang.String unitsText)
Find the time units for the specified units text.

Parameters:
unitsText - the units text.
Throws:
java.lang.IllegalArgumentException - if the time unites could not be found.

TimeUnits

protected TimeUnits(java.lang.String text,
                    long msPerUnit)
Create the time units.

Parameters:
text - the units text (singular.)
msPerUnit - the number of milliseconds per unit.
Method Detail

getMsPerUnit

public long getMsPerUnit()
Get the number of milliseconds per unit.

Returns:
the number of milliseconds per unit.

getTextWithValue

public java.lang.String getTextWithValue(long value)
Get the text for the value and time units.

Parameters:
value - the number of time units.
Returns:
the text for the value and time units.

getTextWithValue

public java.lang.String getTextWithValue(java.lang.String valueText)
Get the text for the value and time units.

Parameters:
valueText - the text for the number of time units.
Returns:
the text for the value and time units.

toString

public java.lang.String toString()
The singular text for the time units.

Overrides:
toString in class java.lang.Object
Returns:
the text for the time units.

toString

public java.lang.String toString(boolean pluralFlag)
The text for the time units.

Parameters:
pluralFlag - true for plural, false for singular.
Returns:
the text for the time units.

toString

public java.lang.String toString(long value)
The text for the time units. If the value is 1 the singular text is used.

Parameters:
value - the number of time units.
Returns:
the text for the time units.

getMilliseconds

public static long getMilliseconds(java.lang.String s,
                                   TimeUnits timeUnits)
Get the number of milliseconds represented by the text and may include text for the time units.

Parameters:
s - the text.
timeUnits - the time units to use if not specified in the text.
Returns:
the number of milliseconds or 0 if the value could not be determined.

getTextValueWithTimeUnits

public static java.lang.String getTextValueWithTimeUnits(java.lang.String s,
                                                         TimeUnits defaultValue,
                                                         long minimumValue)
Gets the text value with time units.

Parameters:
s - the text which may include text for the time units.
defaultValue - the time units to add if not already specified.
minimumValue - the minimum value.
Returns:
the text value with time units or null if the value could not be determined or is not greater than or equal to the minimum value.

getTextWithValue

protected static java.lang.String getTextWithValue(long value,
                                                   java.lang.String unitsText)
Get the text for the value and time units text.

Parameters:
value - the number of time units.
unitsText - the time units text.
Returns:
the text.

getTextWithValue

protected static java.lang.String getTextWithValue(long value,
                                                   TimeUnits timeUnits)
Get the text for the value and time units text.

Parameters:
value - the number of time units.
unitsText - the time units text.
Returns:
the text.

getTextWithValue

protected static java.lang.String getTextWithValue(java.lang.String valueText,
                                                   java.lang.String unitsText)
Get the text for the value and time units text.

Parameters:
valueText - the text for the number of time units.
unitsText - the time units text.
Returns:
the text.

parseTimeUnits

protected static TimeUnits parseTimeUnits(java.lang.String unitsText,
                                          TimeUnits defaultValue)
Parse the units text.

Parameters:
unitsText - the units text.
defaultValue - the default time units.
Returns:
the time units from the specified units text or the default value.

valueOf

public static TimeUnits valueOf(java.lang.String s)
Gets the time units for the specified text.

Parameters:
s - the text or null if none.
Returns:
the time units or null if none.

valueOf

public static TimeUnits valueOf(java.lang.String s,
                                TimeUnits defaultValue)
Gets the time units for the specified text. If the text contains any space the text after the space is used.

Parameters:
s - the text or null if none.
defaultValue - the default value if no time units found.
Returns:
the time units or the default value if none.