Class Capacity

java.lang.Object
com.hazelcast.memory.Capacity
Direct Known Subclasses:
MemorySize

public class Capacity extends Object
Capacity represents a memory capacity with given value and MemoryUnit. This class is immutable.
Since:
5.1
See Also:
  • Constructor Details

    • Capacity

      public Capacity(long value)
    • Capacity

      public Capacity(long value, MemoryUnit unit)
  • Method Details

    • getValue

      public long getValue()
      Returns value of the capacity in its original unit.
      Returns:
      capacity in its original unit
    • getUnit

      public MemoryUnit getUnit()
      Returns unit of the capacity
      Returns:
      unit of capacity
    • bytes

      public long bytes()
      Returns value of the capacity in bytes.
      Returns:
      capacity in bytes
    • kiloBytes

      public long kiloBytes()
      Returns value of the capacity in kilo-bytes.
      Returns:
      capacity in kilo-bytes
    • megaBytes

      public long megaBytes()
      Returns value of the capacity in mega-bytes.
      Returns:
      capacity in mega-bytes
    • gigaBytes

      public long gigaBytes()
      Returns value of the capacity in giga-bytes.
      Returns:
      capacity in giga-bytes
    • of

      public static Capacity of(long value, MemoryUnit unit)
      Returns an instance of Capacity.
      Parameters:
      value - value of the capacity
      unit - unit of the capacity
      Returns:
      a Capacity instance
    • parse

      public static Capacity parse(String value)
      Parses string representation of a capacity. Value may end with one of suffixes;
      • 'k' or 'K' for 'kilo',
      • 'm' or 'M' for 'mega',
      • 'g' or 'G' for 'giga'.

      Default unit is bytes.

      Examples: 12345, 12345m, 12345K, 123456G

    • parse

      public static Capacity parse(String value, MemoryUnit defaultUnit)
      Parses string representation of a capacity. Value may end with one of suffixes;
      • 'k' or 'K' for 'kilo',
      • 'm' or 'M' for 'mega',
      • 'g' or 'G' for 'giga'.

      Uses default unit if value does not contain unit information.

      Examples: 12345, 12345m, 12345K, 123456G

    • toPrettyString

      public String toPrettyString()
      Returns a pretty format String representation of this capacity.
      Returns:
      a pretty format representation of this capacity
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • toPrettyString

      public static String toPrettyString(long capacity)
      Utility method to create a pretty format representation of given capacity in bytes.
      Parameters:
      capacity - capacity in bytes
      Returns:
      pretty format representation of given capacity
    • toPrettyString

      public static String toPrettyString(long capacity, MemoryUnit unit)
      Utility method to create a pretty format representation of given capacity with a specified unit.
      Parameters:
      capacity - capacity
      unit - unit
      Returns:
      pretty format representation of given capacity
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object