Enum Class DurationFormat.Unit
- All Implemented Interfaces:
Serializable
,Comparable<DurationFormat.Unit>
,Constable
- Enclosing class:
- DurationFormat
Duration format unit, which mirrors a subset of
ChronoUnit
and
allows conversion to and from a supported ChronoUnit
as well as
conversion from durations to longs.
The enum includes its corresponding suffix in the simple
Duration
format style.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionConvert thisDurationFormat.Unit
to itsChronoUnit
equivalent.asSuffix()
static DurationFormat.Unit
fromChronoUnit
(ChronoUnit chronoUnit) Get theUnit
corresponding to the givenChronoUnit
.static DurationFormat.Unit
fromSuffix
(String suffix) Get theUnit
corresponding to the givenString
suffix.long
Convert the givenDuration
to a long value in the resolution of this unit.Parse along
from aString
and interpret it to be aDuration
in the current unit.Print aDuration
as aString
, converting it to a long value using this unit's precision vialongValue(Duration)
and appending this unit's simplesuffix
.static DurationFormat.Unit
Returns the enum constant of this class with the specified name.static DurationFormat.Unit[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NANOS
Nanoseconds ("ns"
). -
MICROS
Microseconds ("us"
). -
MILLIS
Milliseconds ("ms"
). -
SECONDS
Seconds ("s"
). -
MINUTES
Minutes ("m"
). -
HOURS
Hours ("h"
). -
DAYS
Days ("d"
).
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified nameNullPointerException
- if the argument is null
-
asChronoUnit
Convert thisDurationFormat.Unit
to itsChronoUnit
equivalent. -
asSuffix
-
parse
Parse along
from aString
and interpret it to be aDuration
in the current unit.- Parameters:
value
- the String representation of the long- Returns:
- the corresponding
Duration
-
print
Print aDuration
as aString
, converting it to a long value using this unit's precision vialongValue(Duration)
and appending this unit's simplesuffix
.- Parameters:
value
- theDuration
to convert to a String- Returns:
- the String representation of the
Duration
in theSIMPLE
style
-
longValue
Convert the givenDuration
to a long value in the resolution of this unit. Note that this can be lossy if the current unit is bigger than the actual resolution of the duration.For example,
Duration.ofMillis(5).plusNanos(1234)
would get truncated to5
for unitMILLIS
.- Parameters:
value
- theDuration
to convert to a long- Returns:
- the long value for the
Duration
in thisUnit
-
fromChronoUnit
Get theUnit
corresponding to the givenChronoUnit
.- Throws:
IllegalArgumentException
- if the givenChronoUnit
is not supported
-
fromSuffix
Get theUnit
corresponding to the givenString
suffix.- Throws:
IllegalArgumentException
- if the given suffix is not supported
-