Enum DurationFormat

  • All Implemented Interfaces:
    Serializable, Comparable<DurationFormat>

    public enum DurationFormat
    extends Enum<DurationFormat>
    Enumerates different duration format styles, each one with particular characteristics.

    Examples:

    • DurationFormat.FULL: 0:00:03.200000000
    • DurationFormat.SHORT: 3.200000000 second(s)
    • DurationFormat.SHORTER: 3.2 second(s)
    • DurationFormat.ISO_8601: PT3.2S
    • DurationFormat.LINUX: 0m3.200s
    Since:
    2.2.0
    Author:
    oswaldo.bapvic.jr
    • Enum Constant Detail

      • FULL

        public static final DurationFormat FULL
        Formats a time duration in the following format: H:M:S.ns. For example: 1:59:59.987654321.
      • SHORT

        public static final DurationFormat SHORT
        Formats a time duration in any of the following formats: H:M:S.ns, M:S.ns, or S.ns, always choosing the shortest possible format.

        Examples:

        • 0.001000000 second(s)
        • 3.200000000 second(s)
        • 15:00.005890000 minute(s)
      • SHORTER

        public static final DurationFormat SHORTER
        Formats a time duration in any of the following formats: H:M:S.ns, M:S.ns, or S.ns, always choosing the shortest possible format and suppressing trailing zeros from the nanoseconds part.

        Examples:

        • 0.001 second(s)
        • 3.2 second(s)
        • 15:00.00589 minute(s)
      • ISO_8601

        public static final DurationFormat ISO_8601
        Formats a time duration using ISO-8601 seconds-based representation.

        For example: PT8H6M12.345S, where:

        • P is the duration designator (referred to as "period"), and is always placed at the beginning of the duration
        • T is the time designator that precedes the time components
        • H is the hour designator that follows the value for the number of hours
        • M is the minute designator that follows the value for the number of minutes
        • S is the second designator that follows the value for the number of seconds

        Additional examples:

        • PT0.001S
        • PT3.2S
        • PT15M0.00589S

        Note: The printLegend flag has no effect in this format style.

      • LINUX

        public static final DurationFormat LINUX
        Formats a time duration in Linux style, applying the form M'm':S.ms's'.

        Examples:

        • 0m0.125s
        • 0m4.999s
        • 3m12.038s

        Note: The printLegend flag has no effect in this format style.

        Since:
        2.4.0
    • Method Detail

      • values

        public static DurationFormat[] 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 (DurationFormat c : DurationFormat.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static DurationFormat 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
      • format

        public String format​(Duration duration,
                             boolean printLegend)
        Formats a given duration.
        Parameters:
        duration - the Duration to be formatted, not null
        printLegend - a flag indicating whether or not to include the legend in the generated string
        Returns:
        a string representing the specified duration, formatted
        Throws:
        NullPointerException - if the specified duration is null