Enum MemoryUnit

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      B
      Bytes.
      GB
      Gigabytes.
      KB
      Kilobytes.
      MB
      Megabytes.
      PB
      Petabytes.
      TB
      Terabytes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int index
      the index of this unit
      private java.lang.String stringForm  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MemoryUnit​(java.lang.String stringForm, int index)
      Internal constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(long thisSize, long thatSize, ResourceUnit thatUnit)
      Compares thisSize in this unit to thatSize in thatUnit.
      long convert​(long quantity, MemoryUnit unit)
      Converts quantity in unit into this unit.
      private static long doConvert​(int delta, long amount)
      Computes
      long toBytes​(long quantity)
      Converts quantity in this unit to bytes.
      java.lang.String toString()
      static MemoryUnit valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static MemoryUnit[] 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, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • index

        private final int index
        the index of this unit
      • stringForm

        private final java.lang.String stringForm
    • Constructor Detail

      • MemoryUnit

        private MemoryUnit​(java.lang.String stringForm,
                           int index)
        Internal constructor
    • Method Detail

      • values

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

        public static MemoryUnit 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
      • doConvert

        private static long doConvert​(int delta,
                                      long amount)
                               throws java.lang.ArithmeticException
        Computes
        amount * 2^delta
        . The result is always rounded toward zero.
        Parameters:
        delta - log2(divisor)
        amount - dividend
        Throws:
        java.lang.ArithmeticException - if the result overflows
      • toBytes

        public long toBytes​(long quantity)
        Converts quantity in this unit to bytes.
        Parameters:
        quantity - the quantity
        Returns:
        the quantity in bytes
      • convert

        public long convert​(long quantity,
                            MemoryUnit unit)
        Converts quantity in unit into this unit.
        Parameters:
        quantity - quantity to convert
        unit - quantity's unit
        Returns:
        the quantity in this unit
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Enum<MemoryUnit>
      • compareTo

        public int compareTo​(long thisSize,
                             long thatSize,
                             ResourceUnit thatUnit)
                      throws java.lang.IllegalArgumentException
        Compares thisSize in this unit to thatSize in thatUnit.

        Returns 1, 0, or -1 if the thisSize of this is greater than, equal to, or less than thatSize of thatUnit respectively.

        Specified by:
        compareTo in interface ResourceUnit
        Parameters:
        thisSize - size in this unit
        thatSize - size in thatUnit
        thatUnit - other ResourceUnit
        Returns:
        as per the compareTo contract
        Throws:
        java.lang.IllegalArgumentException - if the units are not comparable