Enum MemoryUnit

java.lang.Object
java.lang.Enum<MemoryUnit>
org.refcodes.data.MemoryUnit
All Implemented Interfaces:
Serializable, Comparable<MemoryUnit>, java.lang.constant.Constable

public enum MemoryUnit extends Enum<MemoryUnit>
The MemoryUnit provides enumerations for common memory units alongside conversions to and from memory size specified in bytes.
  • Enum Constant Details

    • BYTE

      public static final MemoryUnit BYTE
    • KILOBYTE

      public static final MemoryUnit KILOBYTE
    • MEGABYTE

      public static final MemoryUnit MEGABYTE
    • GIGABYTE

      public static final MemoryUnit GIGABYTE
    • TERABYTE

      public static final MemoryUnit TERABYTE
    • PETABYTE

      public static final MemoryUnit PETABYTE
    • EXABYTE

      public static final MemoryUnit EXABYTE
    • ZETTABYTE

      public static final MemoryUnit ZETTABYTE
    • YOTTABYTE

      public static final MemoryUnit YOTTABYTE
  • Method Details

    • values

      public static MemoryUnit[] 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 MemoryUnit 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
    • getUnit

      public String getUnit()
      Returns the name of the memory unit, e.g. "KB" for kilobyte or "MB" for megabyte.
      Returns:
      The name (abbreviation) of the unit.
    • getBytes

      public BigDecimal getBytes()
      Returns the number of bytes representing a unit, e.g. 1024 for KILOBYTE.
      Returns:
      The number of bytes per unit.
    • toBytes

      public BigDecimal toBytes(double aUnitValue)
      Calculates the number of bytes for the given value provided for the according MemoryUnit.
      Parameters:
      aUnitValue - The value to be converted.
      Returns:
      The converted value in bytes.
    • toBytes

      public BigDecimal toBytes(BigDecimal aUnitValue)
      Calculates the number of bytes for the given value provided for the according MemoryUnit.
      Parameters:
      aUnitValue - The value to be converted.
      Returns:
      The converted value in bytes.
    • toBytes

      public BigDecimal toBytes(long aUnitValue)
      Calculates the number of bytes for the given value provided for the according MemoryUnit.
      Parameters:
      aUnitValue - The value to be converted.
      Returns:
      The converted value in bytes.
    • fromBytes

      public BigDecimal fromBytes(long aBytes)
      Calculates the number of bytes for the given value provided for the according MemoryUnit.
      Parameters:
      aBytes - the bytes
      Returns:
      The converted value in bytes.
    • fromBytes

      public BigDecimal fromBytes(BigDecimal aBytes)
      Calculates the number of bytes for the given value provided for the according MemoryUnit.
      Parameters:
      aBytes - the bytes
      Returns:
      The converted value in bytes.
    • toSuitableUnit

      public static MemoryUnit toSuitableUnit(long aBytes)
      Determines the best fitting unit to represent the given number of bytes in terms of "which memory unit is the biggest memory unit of which one unit is smaller than the given amount of bytes".
      Parameters:
      aBytes - The number of bytes for which to determine the most suitable MemoryUnit
      Returns:
      The according MemoryUnit;
    • toSuitableUnit

      public static MemoryUnit toSuitableUnit(BigDecimal aBytes)
      Determines the best fitting unit to represent the given number of bytes in terms of "which memory unit is the biggest memory unit of which one unit is smaller than the given amount of bytes".
      Parameters:
      aBytes - The number of bytes for which to determine the most suitable MemoryUnit
      Returns:
      The according MemoryUnit;