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
-
Constructor Summary
Constructors Constructor Description Place(int x, int y)Creates an instance of aPlacerecord. -
Method Summary
Modifier and Type Method Description Placeclone()booleanequals(java.lang.Object o)Indicates whether some other object is "equal to" this one.inthashCode()Returns a hash code value for this object.java.lang.StringtoString()Returns a string representation of this record.intx()Returns the value of thexrecord component.inty()Returns the value of theyrecord component.
-
Field Details
-
Constructor Details
-
Place
public Place(int x, int y)Creates an instance of aPlacerecord.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord component
-
-
Method Details
-
clone
- Overrides:
clonein classjava.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:
toStringin classjava.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:
hashCodein classjava.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:
equalsin classjava.lang.Record- Parameters:
o- the object with which to compare- Returns:
trueif this object is the same as theoargument;falseotherwise.
-
x
public int x()Returns the value of thexrecord component.- Returns:
- the value of the
xrecord component
-
y
public int y()Returns the value of theyrecord component.- Returns:
- the value of the
yrecord component
-