Record Class BoardDimensions

java.lang.Object
java.lang.Record
megamek.common.board.BoardDimensions
All Implemented Interfaces:
Serializable, Comparable<BoardDimensions>

public record BoardDimensions(int w, int h) extends Record implements Serializable, Comparable<BoardDimensions>
Type-safe, immutable, dimensions class for handling board sizes.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    BoardDimensions(int w, int h)
    Construct a new BoardDimensions object.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares BoardDimensions based on width, falling back on height if the widths are equal
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    h()
    Returns the value of the h record component.
    final int
    Returns a hash code value for this object.
    int
     
    long
     
    Returns a string representation of this record class.
    int
    w()
    Returns the value of the w record component.
    int
     

    Methods inherited from class java.lang.Object

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

    • BoardDimensions

      public BoardDimensions(int w, int h)
      Construct a new BoardDimensions object.
      Parameters:
      w - The width
      h - The height
      Throws:
      IllegalArgumentException - If either width or height is less than 1.
  • Method Details

    • width

      public int width()
      Returns:
      The board width.
    • height

      public int height()
      Returns:
      The board height.
    • numHexes

      public long numHexes()
      Returns:
      The total number of hexes in the board.
    • equals

      public boolean equals(Object obj)
      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:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      @Nonnull 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
    • compareTo

      public int compareTo(BoardDimensions o)
      Compares BoardDimensions based on width, falling back on height if the widths are equal
      Specified by:
      compareTo in interface Comparable<BoardDimensions>
    • 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
    • w

      public int w()
      Returns the value of the w record component.
      Returns:
      the value of the w record component
    • h

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