Class MemorySize

java.lang.Object
ai.dat.core.configuration.MemorySize
All Implemented Interfaces:
Serializable, Comparable<MemorySize>

public class MemorySize extends Object implements Serializable, Comparable<MemorySize>
MemorySize is a representation of a number of bytes, viewable in different units.

Parsing

The size can be parsed from a text expression. If the expression is a pure number, the value will be interpreted as bytes.

See Also:
  • Field Details

  • Constructor Details

    • MemorySize

      public MemorySize(long bytes)
      Constructs a new MemorySize.
      Parameters:
      bytes - The size, in bytes. Must be zero or larger.
  • Method Details

    • ofMebiBytes

      public static MemorySize ofMebiBytes(long mebiBytes)
    • getKibiBytes

      public long getKibiBytes()
      Gets the memory size in Kibibytes (= 1024 bytes).
    • getMebiBytes

      public int getMebiBytes()
      Gets the memory size in Mebibytes (= 1024 Kibibytes).
    • getGibiBytes

      public long getGibiBytes()
      Gets the memory size in Gibibytes (= 1024 Mebibytes).
    • getTebiBytes

      public long getTebiBytes()
      Gets the memory size in Tebibytes (= 1024 Gibibytes).
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toHumanReadableString

      public String toHumanReadableString()
    • compareTo

      public int compareTo(MemorySize that)
      Specified by:
      compareTo in interface Comparable<MemorySize>
    • add

      public MemorySize add(MemorySize that)
    • subtract

      public MemorySize subtract(MemorySize that)
    • multiply

      public MemorySize multiply(double multiplier)
    • divide

      public MemorySize divide(long by)
    • parse

      public static MemorySize parse(String text) throws IllegalArgumentException
      Parses the given string as as MemorySize.
      Parameters:
      text - The string to parse
      Returns:
      The parsed MemorySize
      Throws:
      IllegalArgumentException - Thrown, if the expression cannot be parsed.
    • parse

      public static MemorySize parse(String text, MemorySize.MemoryUnit defaultUnit) throws IllegalArgumentException
      Parses the given string with a default unit.
      Parameters:
      text - The string to parse.
      defaultUnit - specify the default unit.
      Returns:
      The parsed MemorySize.
      Throws:
      IllegalArgumentException - Thrown, if the expression cannot be parsed.
    • parseBytes

      public static long parseBytes(String text) throws IllegalArgumentException
      Parses the given string as bytes. The supported expressions are listed under MemorySize.
      Parameters:
      text - The string to parse
      Returns:
      The parsed size, in bytes.
      Throws:
      IllegalArgumentException - Thrown, if the expression cannot be parsed.