Package org.forgerock.opendj.config
Enum DurationUnit
- java.lang.Object
-
- java.lang.Enum<DurationUnit>
-
- org.forgerock.opendj.config.DurationUnit
-
- All Implemented Interfaces:
Serializable,Comparable<DurationUnit>
public enum DurationUnit extends Enum<DurationUnit>
This enumeration defines various duration units.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublefromMilliSeconds(long duration)Converts the specified duration in milliseconds to this unit.longgetDuration()Get the number of milliseconds that this unit represents.StringgetLongName()Get the long name of this unit.StringgetShortName()Get the abbreviated name of this unit.static DurationUnitgetUnit(String s)Get the unit corresponding to the provided unit name.static longparseValue(String s)Parse the provided duration string and return its equivalent duration in milliseconds.static longparseValue(String s, DurationUnit defaultUnit)Parse the provided duration string and return its equivalent duration in milliseconds.longtoMilliSeconds(double duration)Converts the specified duration in this unit to milliseconds.StringtoString()static StringtoString(long duration)Returns a string representation of the provided duration.static DurationUnitvalueOf(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.
-
-
-
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(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:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getUnit
public static DurationUnit getUnit(String s)
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:
IllegalArgumentException- If the provided name did not correspond to a known duration unit.
-
parseValue
public static long parseValue(String s)
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 thetoString(long)method. Therefore, a duration can comprise of multiple duration specifiers, for example1d15m25s.- Parameters:
s- The duration string to be parsed.- Returns:
- Returns the parsed duration in milliseconds.
- Throws:
NumberFormatException- If the provided duration string could not be parsed.- See Also:
toString(long)
-
parseValue
public static long parseValue(String s, DurationUnit defaultUnit)
Parse the provided duration string and return its equivalent duration in milliseconds. This method will parse duration string representations produced from thetoString(long)method. Therefore, a duration can comprise of multiple duration specifiers, for example1d15m25s.- Parameters:
s- The duration string to be parsed.defaultUnit- The default unit to use if there is no unit specified in the duration string, ornullif the string must always contain a unit.- Returns:
- Returns the parsed duration in milliseconds.
- Throws:
NumberFormatException- If the provided duration string could not be parsed.- See Also:
toString(long)
-
toString
public static String toString(long duration)
Returns a string representation of the provided duration. The string representation can be parsed using theparseValue(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:
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 String getLongName()
Get the long name of this unit.- Returns:
- Returns the long name of this unit.
-
getShortName
public 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 String toString()
This implementation returns the abbreviated name of this duration unit.
- Overrides:
toStringin classEnum<DurationUnit>
-
-