org.opends.server.admin
Enum DurationUnit

java.lang.Object
  extended by java.lang.Enum<DurationUnit>
      extended by org.opends.server.admin.DurationUnit
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<DurationUnit>

public enum DurationUnit
extends java.lang.Enum<DurationUnit>

This enumeration defines various duration units.


Enum Constant Summary
DAYS
          A day unit.
HOURS
          An hour unit.
MILLI_SECONDS
          A millisecond unit.
MINUTES
          A minute unit.
SECONDS
          A second unit.
WEEKS
          A week unit.
 
Method Summary
 double fromMilliSeconds(long duration)
          Converts the specified duration in milliseconds to this unit.
 long getDuration()
          Get the number of milliseconds that this unit represents.
 java.lang.String getLongName()
          Get the long name of this unit.
 java.lang.String getShortName()
          Get the abbreviated name of this unit.
static DurationUnit getUnit(java.lang.String s)
          Get the unit corresponding to the provided unit name.
static long parseValue(java.lang.String s)
          Parse the provided duration string and return its equivalent duration in milliseconds.
static long parseValue(java.lang.String s, DurationUnit defaultUnit)
          Parse the provided duration string and return its equivalent duration in milliseconds.
 long toMilliSeconds(double duration)
          Converts the specified duration in this unit to milliseconds.
 java.lang.String toString()
          
static java.lang.String toString(long duration)
          Returns a string representation of the provided duration.
static DurationUnit valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static DurationUnit[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

DAYS

public static final DurationUnit DAYS
A day unit.


HOURS

public static final DurationUnit HOURS
An hour unit.


MILLI_SECONDS

public static final DurationUnit MILLI_SECONDS
A millisecond unit.


MINUTES

public static final DurationUnit MINUTES
A minute unit.


SECONDS

public static final DurationUnit SECONDS
A second unit.


WEEKS

public static final DurationUnit WEEKS
A week unit.

Method Detail

values

public static DurationUnit[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (DurationUnit c : DurationUnit.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static DurationUnit valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null

getUnit

public static DurationUnit getUnit(java.lang.String s)
                            throws java.lang.IllegalArgumentException
Get the unit corresponding to the provided unit name.

Parameters:
s - The name of the unit. Can be the abbreviated or long name and can contain white space and mixed case characters.
Returns:
Returns the unit corresponding to the provided unit name.
Throws:
java.lang.IllegalArgumentException - If the provided name did not correspond to a known duration unit.

parseValue

public static long parseValue(java.lang.String s)
                       throws java.lang.NumberFormatException
Parse the provided duration string and return its equivalent duration in milliseconds. The duration string must specify the unit e.g. "10s". This method will parse duration string representations produced from the toString(long) method. Therefore, a duration can comprise of multiple duration specifiers, for example 1d15m25s.

Parameters:
s - The duration string to be parsed.
Returns:
Returns the parsed duration in milliseconds.
Throws:
java.lang.NumberFormatException - If the provided duration string could not be parsed.
See Also:
toString(long)

parseValue

public static long parseValue(java.lang.String s,
                              DurationUnit defaultUnit)
                       throws java.lang.NumberFormatException
Parse the provided duration string and return its equivalent duration in milliseconds. This method will parse duration string representations produced from the toString(long) method. Therefore, a duration can comprise of multiple duration specifiers, for example 1d15m25s.

Parameters:
s - The duration string to be parsed.
defaultUnit - The default unit to use if there is no unit specified in the duration string, or null if the string must always contain a unit.
Returns:
Returns the parsed duration in milliseconds.
Throws:
java.lang.NumberFormatException - If the provided duration string could not be parsed.
See Also:
toString(long)

toString

public static java.lang.String toString(long duration)
                                 throws java.lang.IllegalArgumentException
Returns a string representation of the provided duration. The string representation can be parsed using the parseValue(String) method. The string representation is comprised of one or more of the number of weeks, days, hours, minutes, seconds, and milliseconds. Here are some examples:
 toString(0)       // 0 ms
 toString(999)     // 999 ms
 toString(1000)    // 1 s
 toString(1500)    // 1 s 500 ms
 toString(3650000) // 1 h 50 s
 toString(3700000) // 1 h 1 m 40 s
 

Parameters:
duration - The duration in milliseconds.
Returns:
Returns a string representation of the provided duration.
Throws:
java.lang.IllegalArgumentException - If the provided duration is negative.
See Also:
parseValue(String), parseValue(String, DurationUnit)

fromMilliSeconds

public double fromMilliSeconds(long duration)
Converts the specified duration in milliseconds to this unit.

Parameters:
duration - The duration in milliseconds.
Returns:
Returns milliseconds in this unit.

getDuration

public long getDuration()
Get the number of milliseconds that this unit represents.

Returns:
Returns the number of milliseconds that this unit represents.

getLongName

public java.lang.String getLongName()
Get the long name of this unit.

Returns:
Returns the long name of this unit.

getShortName

public java.lang.String getShortName()
Get the abbreviated name of this unit.

Returns:
Returns the abbreviated name of this unit.

toMilliSeconds

public long toMilliSeconds(double duration)
Converts the specified duration in this unit to milliseconds.

Parameters:
duration - The duration as a quantity of this unit.
Returns:
Returns the number of milliseconds that the duration represents.

toString

public java.lang.String toString()

This implementation returns the abbreviated name of this duration unit.

Overrides:
toString in class java.lang.Enum<DurationUnit>