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!
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
ConstructorsConstructorDescriptionFigureLocation
(int x, int y) Creates a newFigureLocation
with the given coordinates. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.static FigureLocation
fromString
(String location) Creates a newFigureLocation
from the given string.static List
<FigureLocation> Returns all the valid locations on the board.final int
hashCode()
Returns a hash code value for this object.static boolean
hasSameAxis
(FigureLocation locA, FigureLocation locB) 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.toString()
Returns a string representation of this record class.int
x()
Returns the value of thex
record component.int
y()
Returns the value of they
record component.
-
Constructor Details
-
FigureLocation
public FigureLocation(int x, int y) Creates a newFigureLocation
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
Creates a newFigureLocation
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
Returns all the valid locations on the board.- Returns:
- the list of all valid locations.
-
hasSameAxis
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
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. -
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. -
equals
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 '=='. -
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
-