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 aPlace
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 thex
record component.int
y()
Returns the value of they
record component.
-
Field Details
-
Constructor Details
-
Place
public Place(int x, int y)Creates an instance of aPlace
record.- Parameters:
x
- the value for thex
record componenty
- the value for they
record component
-
-
Method Details
-
clone
- Overrides:
clone
in 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:
toString
in 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:
hashCode
in 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:
equals
in classjava.lang.Record
- Parameters:
o
- the object with which to compare- Returns:
true
if this object is the same as theo
argument;false
otherwise.
-
x
public int x()Returns the value of thex
record component.- Returns:
- the value of the
x
record component
-
y
public int y()Returns the value of they
record component.- Returns:
- the value of the
y
record component
-