Enum MemoryUnit

java.lang.Object
java.lang.Enum<MemoryUnit>
org.ehcache.config.units.MemoryUnit
All Implemented Interfaces:
Serializable, Comparable<MemoryUnit>, java.lang.constant.Constable, ResourceUnit

public enum MemoryUnit extends Enum<MemoryUnit> implements ResourceUnit
A ResourceUnit that designates memory quantity.
  • Enum Constant Details

  • Field Details

    • index

      private final int index
      the index of this unit
    • stringForm

      private final String stringForm
  • Constructor Details

    • MemoryUnit

      private MemoryUnit(String stringForm, int index)
      Internal constructor
  • 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
    • doConvert

      private static long doConvert(int delta, long amount) throws ArithmeticException
      Computes
      amount * 2^delta
      . The result is always rounded toward zero.
      Parameters:
      delta - log2(divisor)
      amount - dividend
      Throws:
      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 String toString()
      Overrides:
      toString in class Enum<MemoryUnit>
    • compareTo

      public int compareTo(long thisSize, long thatSize, ResourceUnit thatUnit) throws 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:
      IllegalArgumentException - if the units are not comparable