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 supported ChronoUnit as well as
converting 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()Convert thisDurationFormat.Unitto a simpleStringsuffix, suitable for theDurationFormat.Style.SIMPLEstyle.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
Convert thisDurationFormat.Unitto a simpleStringsuffix, suitable for theDurationFormat.Style.SIMPLEstyle. -
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 String- Returns:
- the String representation of the
Durationin theSIMPLE style
-
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 long- Returns:
- the long value for the Duration in this Unit
-
fromChronoUnit
Get theUnitcorresponding to the givenChronoUnit.- Throws:
IllegalArgumentException- if that particular ChronoUnit isn't supported
-
fromSuffix
Get theUnitcorresponding to the givenStringsuffix.- Throws:
IllegalArgumentException- if that particular suffix is unknown
-