Enum DecimalSizeUnit

java.lang.Object
java.lang.Enum<DecimalSizeUnit>
com.unboundid.util.DecimalSizeUnit
All Implemented Interfaces:
Serializable, Comparable<DecimalSizeUnit>, java.lang.constant.Constable

public enum DecimalSizeUnit extends Enum<DecimalSizeUnit>
This enum defines a set of size units that can be used to represent data sizes in varying units (bytes, kilobytes, megabytes, gigabytes, etc.). This class uses decimal-based values rather than binary-based values, so each unit is 1000 times larger than the previous (for example, one kilobyte is interpreted as 1000 bytes rather than 1024 bytes).
  • Enum Constant Details

    • BYTES

      public static final DecimalSizeUnit BYTES
      The size unit that represents bytes.
    • KILOBYTES

      public static final DecimalSizeUnit KILOBYTES
      The size unit that represents kilobytes. Each kilobyte is 1024 bytes.
    • MEGABYTES

      public static final DecimalSizeUnit MEGABYTES
      The size unit that represents megabytes. Each megabyte is 1024 kilobytes.
    • GIGABYTES

      public static final DecimalSizeUnit GIGABYTES
      The size unit that represents gigabytes. Each gigabyte is 1024 megabytes.
    • TERABYTES

      public static final DecimalSizeUnit TERABYTES
      The size unit that represents terabytes. Each terabyte is 1024 gigabytes.
    • PETABYTES

      public static final DecimalSizeUnit PETABYTES
      The size unit that represents petabyte. Each petabyte is 1024 terabytes.
    • EXABYTES

      public static final DecimalSizeUnit EXABYTES
      The size unit that represents exabytes. Each exabyte is 1024 petabytes.
    • ZETTABYTES

      public static final DecimalSizeUnit ZETTABYTES
      The size unit that represents zettabytes. Each zettabyte is 1024 exabytes.
    • YOTTABYTES

      public static final DecimalSizeUnit YOTTABYTES
      The size unit that represents yottabytes. Each yottabyte is 1024 zettabytes.
  • Method Details

    • values

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

      public static DecimalSizeUnit 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
    • getNumBytesPerUnit

      Retrieves the number of bytes per single instance of this size unit.
      Returns:
      The number of bytes per single instance of this size unit.
    • getSingularName

      Retrieves the singular name for this size unit.
      Returns:
      The singular name for this size unit.
    • getPluralName

      Retrieves the plural name for this size unit.
      Returns:
      The plural name for this size unit.
    • getAbbreviation

      Retrieves the abbreviation for this size unit.
      Returns:
      The abbreviation for this size unit.
    • toBytes

      @NotNull public BigInteger toBytes(long value)
      Retrieves the number of bytes in the specified number of instances of this size unit.
      Parameters:
      value - The number of instances of this unit to convert to bytes.
      Returns:
      The number of bytes in the specified number of instances of this size unit.
    • toBytes

      Retrieves the number of bytes in the specified number of instances of this size unit.
      Parameters:
      value - The number of instances of this unit to convert to bytes. It must not be null.
      Returns:
      The number of bytes in the specified number of instances of this size unit.
    • toBytes

      @NotNull public BigInteger toBytes(double value)
      Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.
      Parameters:
      value - The number of instances of this unit to convert to bytes.
      Returns:
      The number of bytes in the specified number of instances of this size unit.
    • toBytes

      Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.
      Parameters:
      value - The number of instances of this unit to convert to bytes. It must not be null.
      Returns:
      The number of bytes in the specified number of instances of this size unit.
    • fromBytes

      @NotNull public BigDecimal fromBytes(long numBytes)
      Retrieves the number of instances of this unit represented by the specified number of bytes.
      Parameters:
      numBytes - The number of bytes to use to make the determination.
      Returns:
      The number of instances of this unit represented by the specified number of bytes.
    • fromBytes

      Retrieves the number of instances of this unit represented by the specified number of bytes.
      Parameters:
      numBytes - The number of bytes to use to make the determination. It must not be null.
      Returns:
      The number of instances of this unit represented by the specified number of bytes.
    • bytesToHumanReadableSize

      @NotNull public static String bytesToHumanReadableSize(long numBytes)
      Retrieves a string that represents a human-readable representation of the specified number of bytes. The string representation will be constructed in accordance with the following rules:
      • The string representation will use the abbreviation for the unit (e.g., "b" instead of "bytes", "KB" instead of kilobytes, etc.)
      • If the provided value represents an exact multiple of the number of bytes for a given unit, then the string representation will be an integer followed by the abbreviation for the unit (e.g., a value of 123 will result in a string representation of "123b", a value of 524880 will result in a string representation of "5MB", a value of 7516192768 will result in a string representation of "7GB", etc.).
      • If the provided value does not represent an exact multiple of the number of bytes for the given unit, then the string representation will use a floating-point number with two digits behind the decimal point. It will select the unit so that when possible, there will be between 1 and 3 digits before the decimal point (e.g., a value of 12345 will result in a string representation of "12.06KB", a value of 9876543210 will result in a string representation of "9.20GB", etc.).
      Parameters:
      numBytes - The number of bytes to represent as a human-readable size. It must be greater than or equal to zero.
      Returns:
      A string that represents a human-readable representation of the specified number of bytes.
    • bytesToHumanReadableSize

      Retrieves a string that represents a human-readable representation of the specified number of bytes. The string representation will be constructed in accordance with the following rules:
      • The string representation will use the abbreviation for the unit (e.g., "B" instead of "bytes", "KB" instead of kilobytes, etc.)
      • The string representation The string representation will use the abbreviation for the unit (e.g., "B" instead of "bytes", "KB" instead of kilobytes, etc.)
      • If the provided value represents an exact multiple of the number of bytes for the selected unit, then the string representation will be an integer followed by the abbreviation for the unit (e.g., a value of 123 will result in a string representation of "123B", a value of 524880 will result in a string representation of "5MB", a value of 7516192768 will result in a string representation of "7GB", etc.).
      • If the provided value does not represent an exact multiple of the number of bytes for the selected unit, then the string representation will use a floating-point number with two digits behind the decimal point (e.g., a value of 12345 will result in a string representation of "12.06KB", a value of 9876543210 will result in a string representation of "9.20GB", etc.).
      Parameters:
      numBytes - The number of bytes to represent as a human-readable size. It must not be null, and it must represent a value that is greater than or equal to zero.
      Returns:
      A string that represents a human-readable representation of the specified number of bytes.
    • forName

      Retrieves the decimal size unit value that has the given name as either its singular name, plural name, or abbreviation, in a case-insensitive manner.
      Parameters:
      name - The name for which to retrieve the decimal size unit value. It must not be null.
      Returns:
      The decimal size unit value for the given name, or null if no value has a singular name, plural name, or abbreviation that matches the provided name in a case-insensitive manner.