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

public enum Scale extends Enum<Scale>
A collection of byte prefixes with conversions and formatting.
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    A byte.
    SI Scale Gigabttes
    IEC Scale Gigabytes (2 ^ 30)
    SI scale Kilobytes bytes
    IEC Scale Kilobytes (2 ^ 10).
    SI scale Megabytes
    IEC Scale Megabytes (2 ^ 20)
    SI Scale Petabytes
    IEC Scale Petabytes (2 ^ 50)
    SI Scale Terabytes
    IEC Scale Terabytes (2 ^ 40)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final long
    The number of bytes in a single unit of the scale.
    static final List<Scale>
    The International Electrotechnical Commission (IEC) standardized binary prefixes.
    static final List<Scale>
    The SI standardized prefix scales.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    asBytes(double unitCount)
    Gets the number of bytes found in the specified number of units.
    displayValue(long value)
    Creates a String using the scale. if the scale is not B then it is followed by the number of bytes within a set of parenthesis.
    format(long byteCount)
    Formats the byteCount at this scale.
    static Scale
    scaleOf(long byteCount, List<Scale> possibleScales)
    Determines the scale of the number of bytes.
    static String
    size(int byteCount, List<Scale> possibleScales)
    Creates a formatted string for the scale that most closely represents the byteCount.
    units(int unitCount)
    Formats the byteCount at this scale.
    static Scale
    Returns the enum constant of this class with the specified name.
    static Scale[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

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

    • B

      public static final Scale B
      A byte.
    • KB

      public static final Scale KB
      SI scale Kilobytes bytes
    • MB

      public static final Scale MB
      SI scale Megabytes
    • GB

      public static final Scale GB
      SI Scale Gigabttes
    • TB

      public static final Scale TB
      SI Scale Terabytes
    • PB

      public static final Scale PB
      SI Scale Petabytes
    • KiB

      public static final Scale KiB
      IEC Scale Kilobytes (2 ^ 10).
    • MiB

      public static final Scale MiB
      IEC Scale Megabytes (2 ^ 20)
    • GiB

      public static final Scale GiB
      IEC Scale Gigabytes (2 ^ 30)
    • TiB

      public static final Scale TiB
      IEC Scale Terabytes (2 ^ 40)
    • PiB

      public static final Scale PiB
      IEC Scale Petabytes (2 ^ 50)
  • Field Details

    • IEC

      public static final List<Scale> IEC
      The International Electrotechnical Commission (IEC) standardized binary prefixes. Developed by the IEC to avoid ambiguity through their similarity to the standard metric terms. These are based on powers of 2.
      See Also:
    • SI

      public static final List<Scale> SI
      The SI standardized prefix scales. These are the metric units, as such they are all powers of 10.
    • bytes

      public final long bytes
      The number of bytes in a single unit of the scale.
  • Method Details

    • values

      public static Scale[] 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 Scale 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
    • format

      public String format(long byteCount)
      Formats the byteCount at this scale.
      Parameters:
      byteCount - the number of bytes.
      Returns:
      A string representing the number of units that comprise the byteCount.
    • units

      public String units(int unitCount)
      Formats the byteCount at this scale.
      Parameters:
      unitCount - the number of units at this scale.
      Returns:
      A string representing the number of units at this scale.
    • asBytes

      public long asBytes(double unitCount)
      Gets the number of bytes found in the specified number of units.
      Parameters:
      unitCount - the number of units.
      Returns:
      the number of bytes in unitCount units of this scale.
    • scaleOf

      public static Scale scaleOf(long byteCount, List<Scale> possibleScales)
      Determines the scale of the number of bytes. The largest Scale for which byteCount represents at least 1 unit is returned. If no scale in the possible scales matches then bytes are returned. Negative number will return B.
      Parameters:
      byteCount - the number of bytes
      possibleScales - the list of possible scales.
      Returns:
      the first matching scale.
    • size

      public static String size(int byteCount, List<Scale> possibleScales)
      Creates a formatted string for the scale that most closely represents the byteCount.
      Parameters:
      byteCount - the number of bytes.
      possibleScales - the possible Scales.
      Returns:
      a formatted string representation of the byteCount in the best Scale representation.
      See Also:
    • displayValue

      public String displayValue(long value)
      Creates a String using the scale. if the scale is not B then it is followed by the number of bytes within a set of parenthesis.
      Parameters:
      value - the number of bytes.
      Returns:
      a String using the scale. if the scale is not B then it is followed by the number of bytes