public enum ConversionMode extends Enum<ConversionMode>
| Enum Constant and Description |
|---|
DOUBLE_PRECISION
This mode implements a more robust conversion logic that avoids truncation from finer
to coarser granularities.
|
FAST
A fast conversion mode uses Java-standard
TimeUnit class to convert a given
duration to a different time unit. |
| Modifier and Type | Method and Description |
|---|---|
abstract double |
convert(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit)
Converts the given duration and time unit into another time unit.
|
static ConversionMode |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static ConversionMode[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final ConversionMode FAST
TimeUnit class to convert a given
duration to a different time unit. In this mode, conversions from finer to coarser
granularities truncate, so lose precision.
For example, converting 999 milliseconds to seconds results in 0.
public static final ConversionMode DOUBLE_PRECISION
For example, converting 999 milliseconds to seconds results in 0.999.
public static ConversionMode[] values()
for (ConversionMode c : ConversionMode.values()) System.out.println(c);
public static ConversionMode 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 abstract double convert(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit)
For example, to convert 10 minutes to milliseconds, use:
TimeUnitConverter.convert(10L, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
sourceDuration - the time duration in the given sourceUnitsourceTimeUnit - the unit of the sourceDuration argument, not nulltargetTimeUnit - the target time unit, not nullNullPointerException - if any of the specified time units is nullCopyright © 2021. All rights reserved.