Enum Class TimeScale

java.lang.Object
java.lang.Enum<TimeScale>
io.aiven.commons.collections.TimeScale
All Implemented Interfaces:
Serializable, Comparable<TimeScale>, Constable

public enum TimeScale extends Enum<TimeScale>
Scales milliseconds into standard human time units and standard human time units into milliseconds. Also provides formatting for the same.
  • Enum Constant Details

    • MILLISECONDS

      public static final TimeScale MILLISECONDS
      milliseconds
    • SECONDS

      public static final TimeScale SECONDS
      seconds
    • MINUTES

      public static final TimeScale MINUTES
      minutes
    • HOURS

      public static final TimeScale HOURS
      hours
    • DAYS

      public static final TimeScale DAYS
      days
  • Field Details

    • milliseconds

      public final long milliseconds
      The number of milliseconds in one TimeUnit.
  • Method Details

    • values

      public static TimeScale[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TimeScale valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • displayValue

      public String displayValue(long milliseconds)
      Format the number of milliseconds in this TimeScale along with the number of Milliseconds. For example "3.5 minutes (210000 milliseconds)". If the Timescale is MILLISECONDS then the parenthetical portion is not displayed.
      Parameters:
      milliseconds - the number of milliseconds to format.
      Returns:
      the String representation of the number and TimeUnit as well as the number of milliseconds.
    • unitName

      public String unitName()
      Gets the name of the units for this TimeScale.
      Returns:
      the name of the units.
    • format

      public String format(long milliseconds)
      Format the number of milliseconds into this TimeScale.
      Parameters:
      milliseconds - the number of milliseconds.
      Returns:
      a formatted string representation.
    • units

      public String units(int unitCount)
      Format the number of units of this TimeScale for output.
      Parameters:
      unitCount - the number of TimeScale units.
      Returns:
      the formatted string.
    • asMilliseconds

      public long asMilliseconds(double unitCount)
      Gets the number of milliseconds in the unitcount number of TimeUnits.
      Parameters:
      unitCount - the number of TimeUnits
      Returns:
      the number of milliseconds.
    • scaleOf

      public static TimeScale scaleOf(long milliseconds)
      Returns the largest TimeScale that will represent milliseconds with at least 1 unit.
      Parameters:
      milliseconds - the number of milliseconds
      Returns:
      the TimeScale for the milliseconds.
    • size

      public static String size(int milliseconds)
      Formats the milliseconds into a TimeScale that best fits the number of milliseconds.
      Parameters:
      milliseconds - the number of milliseconds.
      Returns:
      the String representation.
      See Also: