Enum DecimalSizeUnit

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

    public enum DecimalSizeUnit
    extends java.lang.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 Summary

      Enum Constants 
      Enum Constant Description
      BYTES
      The size unit that represents bytes.
      EXABYTES
      The size unit that represents exabytes.
      GIGABYTES
      The size unit that represents gigabytes.
      KILOBYTES
      The size unit that represents kilobytes.
      MEGABYTES
      The size unit that represents megabytes.
      PETABYTES
      The size unit that represents petabyte.
      TERABYTES
      The size unit that represents terabytes.
      YOTTABYTES
      The size unit that represents yottabytes.
      ZETTABYTES
      The size unit that represents zettabytes.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String bytesToHumanReadableSize​(long numBytes)
      Retrieves a string that represents a human-readable representation of the specified number of bytes.
      static java.lang.String bytesToHumanReadableSize​(java.math.BigInteger numBytes)
      Retrieves a string that represents a human-readable representation of the specified number of bytes.
      static DecimalSizeUnit forName​(java.lang.String name)
      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.
      java.math.BigDecimal fromBytes​(long numBytes)
      Retrieves the number of instances of this unit represented by the specified number of bytes.
      java.math.BigDecimal fromBytes​(java.math.BigInteger numBytes)
      Retrieves the number of instances of this unit represented by the specified number of bytes.
      java.lang.String getAbbreviation()
      Retrieves the abbreviation for this size unit.
      java.math.BigInteger getNumBytesPerUnit()
      Retrieves the number of bytes per single instance of this size unit.
      java.lang.String getPluralName()
      Retrieves the plural name for this size unit.
      java.lang.String getSingularName()
      Retrieves the singular name for this size unit.
      java.math.BigInteger toBytes​(double value)
      Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.
      java.math.BigInteger toBytes​(long value)
      Retrieves the number of bytes in the specified number of instances of this size unit.
      java.math.BigInteger toBytes​(java.math.BigDecimal value)
      Retrieves the number of bytes in the specified number of instances of this size unit, rounded to the nearest integer.
      java.math.BigInteger toBytes​(java.math.BigInteger value)
      Retrieves the number of bytes in the specified number of instances of this size unit.
      static DecimalSizeUnit valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static DecimalSizeUnit[] 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

      • 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 Detail

      • values

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

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

        @NotNull
        public java.math.BigInteger 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

        @NotNull
        public java.lang.String getSingularName()
        Retrieves the singular name for this size unit.
        Returns:
        The singular name for this size unit.
      • getPluralName

        @NotNull
        public java.lang.String getPluralName()
        Retrieves the plural name for this size unit.
        Returns:
        The plural name for this size unit.
      • getAbbreviation

        @NotNull
        public java.lang.String getAbbreviation()
        Retrieves the abbreviation for this size unit.
        Returns:
        The abbreviation for this size unit.
      • toBytes

        @NotNull
        public java.math.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

        @NotNull
        public java.math.BigInteger toBytes​(@NotNull
                                            java.math.BigInteger 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. It must not be null.
        Returns:
        The number of bytes in the specified number of instances of this size unit.
      • toBytes

        @NotNull
        public java.math.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

        @NotNull
        public java.math.BigInteger toBytes​(@NotNull
                                            java.math.BigDecimal 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. It must not be null.
        Returns:
        The number of bytes in the specified number of instances of this size unit.
      • fromBytes

        @NotNull
        public java.math.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

        @NotNull
        public java.math.BigDecimal fromBytes​(@NotNull
                                              java.math.BigInteger 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. It must not be null.
        Returns:
        The number of instances of this unit represented by the specified number of bytes.
      • bytesToHumanReadableSize

        @NotNull
        public static java.lang.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

        @NotNull
        public static java.lang.String bytesToHumanReadableSize​(@NotNull
                                                                java.math.BigInteger 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.)
        • 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

        @Nullable
        public static DecimalSizeUnit forName​(@NotNull
                                              java.lang.String name)
        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.