Record Class PartitionAssignment

java.lang.Object
java.lang.Record
com.loomcache.server.sharding.PartitionAssignment
Record Components:
numPartitions - the total number of partitions (must be > 0)
numGroups - the total number of Raft groups (must be > 0)
partitionToGroup - mapping from partitionId (index) to raftGroupId (value), defensively copied

public record PartitionAssignment(int numPartitions, int numGroups, int[] partitionToGroup) extends Record
Immutable snapshot of the current partition-to-group mapping.

This record captures a point-in-time view of how partitions are distributed across Raft groups. The partitionToGroup array is defensively copied on construction to guarantee immutability.

Since:
2.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    PartitionAssignment(int numPartitions, int numGroups, int[] partitionToGroup)
    Compact constructor with validation and defensive copy.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    Returns a hash code value for this object.
    int
    Returns the value of the numGroups record component.
    int
    Returns the value of the numPartitions record component.
    int[]
    Returns a defensive copy of the partition-to-group mapping.
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PartitionAssignment

      public PartitionAssignment(int numPartitions, int numGroups, int[] partitionToGroup)
      Compact constructor with validation and defensive copy.
  • Method Details

    • partitionToGroup

      public int[] partitionToGroup()
      Returns a defensive copy of the partition-to-group mapping.
      Returns:
      copy of the mapping array (never null)
    • equals

      public 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • hashCode

      public 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
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • numPartitions

      public int numPartitions()
      Returns the value of the numPartitions record component.
      Returns:
      the value of the numPartitions record component
    • numGroups

      public int numGroups()
      Returns the value of the numGroups record component.
      Returns:
      the value of the numGroups record component