Enum DurationFormat

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<DurationFormat>

    public enum DurationFormat
    extends java.lang.Enum<DurationFormat>

    A simple class to provide various formatting options for durations represented in milliseconds. The durations are displayed in terms of hours, minutes, seconds, and milliseconds.

    Since:
    2.0
    Version:
    2.0
    Author:
    Evren Sirin
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      FULL
      Format duration in full format.
      LONG
      Format duration in long format.
      MEDIUM
      Format duration in medium format (no milliseconds).
      SHORT
      Format duration in short format (no hours or milliseconds).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String format​(long durationInMilliseconds)
      Format the given duration in milliseconds according to the style defined by this DurationFormat class.
      static DurationFormat valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static DurationFormat[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • FULL

        public static final DurationFormat FULL
        Format duration in full format. Example: 0 hour(s) 2 minute(s) 13 second(s) 572 milliseconds(s)
      • LONG

        public static final DurationFormat LONG
        Format duration in long format. Example: 00:02:13.572
      • MEDIUM

        public static final DurationFormat MEDIUM
        Format duration in medium format (no milliseconds). Example: 00:02:13
      • SHORT

        public static final DurationFormat SHORT
        Format duration in short format (no hours or milliseconds). Example: 00:02
    • 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​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • format

        public java.lang.String format​(long durationInMilliseconds)
        Format the given duration in milliseconds according to the style defined by this DurationFormat class.
        Parameters:
        durationInMilliseconds - duration represented in milliseconds
        Returns:
        duration formatted as a string