Class MemSize

java.lang.Object
io.activej.common.MemSize
All Implemented Interfaces:
Comparable<MemSize>

public final class MemSize extends Object implements Comparable<MemSize>
Encapsulates a size in bytes as a convenient abstraction
  • Field Details

  • Method Details

    • of

      @NotNull public static @NotNull MemSize of(long bytes)
      Creates a MemSize of n bytes
      Parameters:
      bytes - a number of bytes
      Returns:
      a new instance of MemSize of n bytes
    • bytes

      @NotNull public static @NotNull MemSize bytes(long bytes)
      Creates a MemSize of n bytes
      Parameters:
      bytes - a number of bytes
      Returns:
      a new instance of MemSize of n bytes
      See Also:
    • kilobytes

      @NotNull public static @NotNull MemSize kilobytes(long kilobytes)
      Creates a MemSize of n kilobytes
      Parameters:
      kilobytes - a number of kilobytes
      Returns:
      a new instance of MemSize of n kilobytes
    • megabytes

      @NotNull public static @NotNull MemSize megabytes(long megabytes)
      Creates a MemSize of n megabytes
      Parameters:
      megabytes - a number of megabytes
      Returns:
      a new instance of MemSize of n megabytes
    • gigabytes

      @NotNull public static @NotNull MemSize gigabytes(long gigabytes)
      Creates a MemSize of n gigabytes
      Parameters:
      gigabytes - a number of gigabytes
      Returns:
      a new instance of MemSize of n gigabytes
    • terabytes

      @NotNull public static @NotNull MemSize terabytes(long terabytes)
      Creates a MemSize of n terabytes
      Parameters:
      terabytes - a number of terabytes
      Returns:
      a new instance of MemSize of n terabytes
    • toLong

      public long toLong()
      Returns a number of bytes is this MemSize
    • toInt

      public int toInt()
      Returns a number of bytes is this MemSize as int
      Throws:
      IllegalStateException - if number of bytes is greater than Integer.MAX_VALUE
    • map

      @NotNull public @NotNull MemSize map(@NotNull @NotNull LongUnaryOperator fn)
      Returns a new MemSize which has a number of bytes equal to the result of a mapping function applied to the number of bytes of this MemSize
      Parameters:
      fn - a mapping function that maps current size to a new one
      Returns:
      a new MemSize with mapped number of bytes
    • valueOf

      @NotNull public static @NotNull MemSize valueOf(@NotNull @NotNull String string)
      Creates a new MemSize out of a given String
      Parameters:
      string - a string to be parsed
      Returns:
      a parsed MemSize
      Throws:
      IllegalArgumentException - on malformed string
      See Also:
    • format

      @NotNull public @NotNull String format()
      Formats this MemSize as a string

      A string format is the same as valueOf(String) method parses

      Returns:
      a string that represents a MemSize
      See Also:
    • compareTo

      public int compareTo(@NotNull @NotNull MemSize o)
      Specified by:
      compareTo in interface Comparable<MemSize>
    • equals

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

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

      @NotNull public @NotNull String toString()
      Overrides:
      toString in class Object