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.
- Since:
- 6.2
- Author:
- Simon Baslé
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionConvert thisUnitto itsChronoUnitequivalent.asSuffix()static DurationFormat.UnitfromChronoUnit(@Nullable ChronoUnit chronoUnit) Get theDurationFormat.Unitcorresponding to the givenChronoUnit.static DurationFormat.UnitfromSuffix(String suffix) Get theDurationFormat.Unitcorresponding to the givenStringsuffix.longConvert the givenDurationto a long value in the resolution of this unit.Print the givenDurationas 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 thisUnitto itsChronoUnitequivalent. -
asSuffix
-
parse
-
print
Print the givenDurationas 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 aString- Returns:
- the
Stringrepresentation of theDurationin 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 theDurationFormat.Unitcorresponding to the givenChronoUnit.- Throws:
IllegalArgumentException- if the givenChronoUnitis not supported
-
fromSuffix
Get theDurationFormat.Unitcorresponding to the givenStringsuffix.- Throws:
IllegalArgumentException- if the given suffix is not supported
-