Enum Class MemoryUtils

java.lang.Object
java.lang.Enum<MemoryUtils>
me.remigio07.chatplugin.api.common.util.MemoryUtils
All Implemented Interfaces:
Serializable, Comparable<MemoryUtils>, Constable

public enum MemoryUtils extends Enum<MemoryUtils>
Util class that contains methods to convert memory units of measure.
  • Enum Constant Details

    • TERABYTE

      public static final MemoryUtils TERABYTE
      Represents a terabyte (1024 * 1024 * 1024 * 1024 bytes).
    • GIGABYTE

      public static final MemoryUtils GIGABYTE
      Represents a gigabyte (1024 * 1024 * 1024 bytes).
    • MEGABYTE

      public static final MemoryUtils MEGABYTE
      Represents a megabyte (1024 * 1024 bytes).
    • KILOBYTE

      public static final MemoryUtils KILOBYTE
      Represents a kilobyte (1024 bytes).
    • BYTE

      public static final MemoryUtils BYTE
      Represents a byte.
  • Method Details

    • values

      public static MemoryUtils[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static MemoryUtils valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - if the argument is null
    • getToBytesRatio

      public int getToBytesRatio()
      Gets this unit's to bytes ratio.
      Returns:
      To bytes ratio
    • getUnit

      public String getUnit()
      Gets this unit's string representation.

      Example: MEGABYTE ➝ "MB"

      Returns:
      Unit's string representation
    • getDisplayedUnit

      public static MemoryUtils getDisplayedUnit()
      Gets the default displayed memory unit.

      Found at: "settings.displayed-memory.unit" in ConfigurationType.CONFIG

      Returns:
      Displayed memory unit
    • formatMemory

      public static String formatMemory(long bytes)
      Formats the given bytes amount using getDisplayedUnit() and truncating to the decimals places specified at "settings.displayed-memory.decimals" in ConfigurationType.CONFIG.
      Parameters:
      bytes - Bytes amount
      Returns:
      Formatted memory
    • formatMemory

      public static String formatMemory(long bytes, MemoryUtils scale)
      Formats the given bytes amount using the specified scale.
      Parameters:
      bytes - Bytes amount
      scale - Scale to use
      Returns:
      Formatted memory