Record Class MemorySize

java.lang.Object
java.lang.Record
org.apache.pulsar.client.api.v5.config.MemorySize
Record Components:
bytes - the size in bytes

public record MemorySize(long bytes) extends Record
A type-safe representation of a memory size in bytes.

Use the static factory methods to create instances from common units:


 MemorySize.ofMegabytes(64)   // 64 MB
 MemorySize.ofGigabytes(1)    // 1 GB
 MemorySize.ofKilobytes(512)  // 512 KB
 
  • Constructor Details

    • MemorySize

      public MemorySize(long bytes)
      Creates an instance of a MemorySize record class.
      Parameters:
      bytes - the value for the bytes record component
  • Method Details

    • ofBytes

      public static MemorySize ofBytes(long bytes)
      Create a memory size from a number of bytes.
      Parameters:
      bytes - the size in bytes
      Returns:
      a MemorySize representing the specified number of bytes
    • ofKilobytes

      public static MemorySize ofKilobytes(long kb)
      Create a memory size from a number of kilobytes.
      Parameters:
      kb - the size in kilobytes
      Returns:
      a MemorySize representing the specified number of kilobytes
    • ofMegabytes

      public static MemorySize ofMegabytes(long mb)
      Create a memory size from a number of megabytes.
      Parameters:
      mb - the size in megabytes
      Returns:
      a MemorySize representing the specified number of megabytes
    • ofGigabytes

      public static MemorySize ofGigabytes(long gb)
      Create a memory size from a number of gigabytes.
      Parameters:
      gb - the size in gigabytes
      Returns:
      a MemorySize representing the specified number of gigabytes
    • toString

      public String toString()
      Specified by:
      toString in class Record
      Returns:
      a human-readable string representation using the largest whole unit (GB, MB, KB, or bytes)
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • bytes

      public long bytes()
      Returns the value of the bytes record component.
      Returns:
      the value of the bytes record component