Package net.obvj.performetrics
Enum ConversionMode
- java.lang.Object
-
- java.lang.Enum<ConversionMode>
-
- net.obvj.performetrics.ConversionMode
-
- All Implemented Interfaces:
Serializable,Comparable<ConversionMode>
public enum ConversionMode extends Enum<ConversionMode>
Defines supported conversion modes.- Since:
- 2.0.0
- Author:
- oswaldo.bapvic.jr
-
-
Enum Constant Summary
Enum Constants Enum Constant Description DOUBLE_PRECISIONThis mode implements a more robust conversion logic that avoids truncation from finer to coarser granularities.FASTA fast conversion mode uses Java-standardTimeUnitclass to convert a given duration to a different time unit.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract doubleconvert(long sourceDuration, TimeUnit sourceTimeUnit, TimeUnit targetTimeUnit)Converts the given duration and time unit into another time unit.static ConversionModevalueOf(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.
-
-
-
Enum Constant Detail
-
FAST
public static final ConversionMode FAST
A fast conversion mode uses Java-standardTimeUnitclass 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.
-
DOUBLE_PRECISION
public static final ConversionMode DOUBLE_PRECISION
This mode implements a more robust conversion logic that avoids truncation from finer to coarser granularities.For example, converting 999 milliseconds to seconds results in 0.999.
-
-
Method Detail
-
values
public static ConversionMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ConversionMode c : ConversionMode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ConversionMode valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException- if the argument is null
-
convert
public abstract double convert(long sourceDuration, TimeUnit sourceTimeUnit, TimeUnit targetTimeUnit)Converts the given duration and time unit into another time unit.For example, to convert 10 minutes to milliseconds, use:
TimeUnitConverter.convert(10L, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
- Parameters:
sourceDuration- the time duration in the given sourceUnitsourceTimeUnit- the unit of the sourceDuration argument, not nulltargetTimeUnit- the target time unit, not null- Returns:
- the converted duration, as double
- Throws:
NullPointerException- if any of the specified time units is null
-
-