Record Class FigureLocation

java.lang.Object
java.lang.Record
dev.laszlomocsy.tzaar.logic.figure.FigureLocation
Record Components:
x - the x coordinate of the figure. Must be between one and 9!
y - the y coordinate of the figure. Must be between one and 9!

public record FigureLocation(int x, int y) extends Record
The location of a Figure on the Board.

The x is representing the letters of the board, while the y is representing the numbers of the board. The available letters are from 'A' to 'I', while the available numbers are from 1 to 9. There are only 60 valid locations on the board.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FigureLocation(int x, int y)
    Creates a new FigureLocation with the given coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    fromString(String location)
    Creates a new FigureLocation from the given string.
    Returns all the valid locations on the board.
    final int
    Returns a hash code value for this object.
    static boolean
    Checks if the given locations are on the same axis.
    static boolean
    isValid(int x, int y)
    Checks if the given location coordinates are valid.
    Returns a string representation of this record class.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

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

    • FigureLocation

      public FigureLocation(int x, int y)
      Creates a new FigureLocation with the given coordinates.
      Parameters:
      x - the x coordinate of the figure. Must be between one and 9!
      y - the y coordinate of the figure. Must be between one and 9!
  • Method Details

    • fromString

      public static FigureLocation fromString(String location)
      Creates a new FigureLocation from the given string.
      Parameters:
      location - the location of the figure. Must not be null and valid!
      Returns:
      the new FigureLocation.
    • isValid

      public static boolean isValid(int x, int y)
      Checks if the given location coordinates are valid.
      Parameters:
      x - the x coordinate of the figure. Must be between one and 9!
      y - the y coordinate of the figure. Must be between one and 9!
      Returns:
      true if the location is valid, false otherwise.
    • getAllLocation

      public static List<FigureLocation> getAllLocation()
      Returns all the valid locations on the board.
      Returns:
      the list of all valid locations.
    • hasSameAxis

      public static boolean hasSameAxis(FigureLocation locA, FigureLocation locB)
      Checks if the given locations are on the same axis.
      Parameters:
      locA - the first location.
      locB - the second location.
      Returns:
      true if the locations are on the same axis, false otherwise.
    • 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
    • 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.
    • x

      public int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

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