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
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionConvert thisDurationFormat.Unitto itsChronoUnitequivalent.asSuffix()static DurationFormat.UnitfromChronoUnit(ChronoUnit chronoUnit) Get theUnitcorresponding to the givenChronoUnit.static DurationFormat.UnitfromSuffix(String suffix) Get theUnitcorresponding to the givenStringsuffix.longConvert the givenDurationto a long value in the resolution of this unit.Parse alongfrom aStringand interpret it to be aDurationin the current unit.Print aDurationas aString, converting it to a long value using this unit's precision vialongValue(Duration)and appending this unit's simplesuffix.static DurationFormat.UnitReturns 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.Unitto itsChronoUnitequivalent. -
asSuffix
-
parse
Parse alongfrom aStringand interpret it to be aDurationin the current unit.- Parameters:
value- the String representation of the long- Returns:
- the corresponding
Duration
-
print
Print aDurationas aString, converting it to a long value using this unit's precision vialongValue(Duration)and appending this unit's simplesuffix.- Parameters:
value- theDurationto convert to a String- Returns:
- the String representation of the
Durationin theSIMPLEstyle
-
longValue
Convert the givenDurationto 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 to5for unitMILLIS.- Parameters:
value- theDurationto convert to a long- Returns:
- the long value for the
Durationin thisUnit
-
fromChronoUnit
Get theUnitcorresponding to the givenChronoUnit.- Throws:
IllegalArgumentException- if the givenChronoUnitis not supported
-
fromSuffix
Get theUnitcorresponding to the givenStringsuffix.- Throws:
IllegalArgumentException- if the given suffix is not supported
-