Enum ConversionMode

    • Enum Constant Detail

      • FAST

        public static final ConversionMode FAST
        A fast conversion mode uses Java-standard 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.

      • 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 name
        NullPointerException - 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 sourceUnit
        sourceTimeUnit - the unit of the sourceDuration argument, not null
        targetTimeUnit - the target time unit, not null
        Returns:
        the converted duration, as double
        Throws:
        NullPointerException - if any of the specified time units is null