Record Place

java.lang.Object
java.lang.Record
castle.comp3021.assignment.protocol.Place
All Implemented Interfaces:
java.lang.Cloneable

public record Place(int x, int y)
extends java.lang.Record
implements java.lang.Cloneable
A square (position, place) in the gameboard. Represented by coordinates a 2-D coordinate system.

x and y coordinates of a place on gameboard are two fields of this class.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    private int x
    The field for the x record component.
    private int y
    The field for the y record component.
  • Constructor Summary

    Constructors 
    Constructor Description
    Place​(int x, int y)
    Creates an instance of a Place record.
  • Method Summary

    Modifier and Type Method Description
    Place clone()  
    boolean equals​(java.lang.Object o)
    Indicates whether some other object is "equal to" this one.
    int hashCode()
    Returns a hash code value for this object.
    java.lang.String toString()
    Returns a string representation of this record.
    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

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      private final int x
      The field for the x record component.
    • y

      private final int y
      The field for the y record component.
  • Constructor Details

    • Place

      public Place​(int x, int y)
      Creates an instance of a Place record.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
  • Method Details

    • clone

      public Place clone() throws java.lang.CloneNotSupportedException
      Overrides:
      clone in class java.lang.Object
      Throws:
      java.lang.CloneNotSupportedException
    • toString

      public java.lang.String toString()
      Returns a string representation of this record. The representation contains the name of the type, followed by the name and value of each of the record components.
      Specified by:
      toString in class java.lang.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 java.lang.Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals​(java.lang.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 are compared with '=='.
      Specified by:
      equals in class java.lang.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