public enum DurationUnit extends Enum<DurationUnit>
Enum Constant and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
double |
fromMilliSeconds(long duration)
Converts the specified duration in milliseconds to this unit.
|
long |
getDuration()
Get the number of milliseconds that this unit represents.
|
String |
getLongName()
Get the long name of this unit.
|
String |
getShortName()
Get the abbreviated name of this unit.
|
static DurationUnit |
getUnit(String s)
Get the unit corresponding to the provided unit name.
|
static long |
parseValue(String s)
Parse the provided duration string and return its equivalent duration in
milliseconds.
|
static long |
parseValue(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.
|
String |
toString() |
static String |
toString(long duration)
Returns a string representation of the provided duration.
|
static DurationUnit |
valueOf(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.
|
public static final DurationUnit DAYS
public static final DurationUnit HOURS
public static final DurationUnit MILLI_SECONDS
public static final DurationUnit MINUTES
public static final DurationUnit SECONDS
public static final DurationUnit WEEKS
public static DurationUnit[] values()
for (DurationUnit c : DurationUnit.values()) System.out.println(c);
public static DurationUnit valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static DurationUnit getUnit(String s)
s
- The name of the unit. Can be the abbreviated or long name and
can contain white space and mixed case characters.IllegalArgumentException
- If the provided name did not correspond to a known duration
unit.public static long parseValue(String s)
toString(long)
method. Therefore, a duration can comprise of
multiple duration specifiers, for example 1d15m25s
.s
- The duration string to be parsed.NumberFormatException
- If the provided duration string could not be parsed.toString(long)
public static long parseValue(String s, DurationUnit defaultUnit)
toString(long)
method. Therefore, a duration
can comprise of multiple duration specifiers, for example
1d15m25s
.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.NumberFormatException
- If the provided duration string could not be parsed.toString(long)
public static String toString(long duration)
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
duration
- The duration in milliseconds.IllegalArgumentException
- If the provided duration is negative.parseValue(String)
,
parseValue(String, DurationUnit)
public double fromMilliSeconds(long duration)
duration
- The duration in milliseconds.public long getDuration()
public String getLongName()
public String getShortName()
public long toMilliSeconds(double duration)
duration
- The duration as a quantity of this unit.public String toString()
This implementation returns the abbreviated name of this duration unit.
toString
in class Enum<DurationUnit>
Copyright 2010-2018 ForgeRock AS.