2 * Rectangular puzzles should inherit this class.
4 package com
.github
.puzzles
.core
;
6 import java
.util
.Arrays
;
8 import com
.github
.puzzles
.util
.Matrices
;
9 import java
.util
.Random
;
11 public abstract class AbstractRectangularPuzzle
<T
> extends AbstractPuzzle
{
17 protected AbstractRectangularPuzzle(T
[][] puzzle
, int width
, int height
, Difficulty difficulty
) {
18 super(width
* height
, 0, difficulty
);
24 @SuppressWarnings("unchecked")
25 protected AbstractRectangularPuzzle(AbstractRectangularPuzzle rectangularPuzzle
){
26 super(rectangularPuzzle
);
27 this.width
= rectangularPuzzle
.width
;
28 this.height
= rectangularPuzzle
.height
;
29 this.puzzle
= (T
[][])Matrices
.copyOf(rectangularPuzzle
.puzzle
);
34 * @return the width of the puzzle.
36 public final int getWidth() {
43 * @return the height of the puzzle.
45 public final int getHeight() {
52 * @return the puzzle matrix.
54 public final T
[][] getPuzzle() {
55 return Matrices
.copyOf(puzzle
);
60 * @see java.lang.Object#hashCode()
63 public int hashCode() {
65 int result
= super.hashCode();
66 result
= prime
* result
+ height
;
67 result
= prime
* result
+ Arrays
.hashCode(puzzle
);
68 result
= prime
* result
+ width
;
73 * @see java.lang.Object#equals(java.lang.Object)
76 public boolean equals(Object obj
) {
80 if (!super.equals(obj
)) {
83 if (getClass() != obj
.getClass()) {
86 AbstractRectangularPuzzle other
= (AbstractRectangularPuzzle
) obj
;
87 if (height
!= other
.height
) {
90 if (!Arrays
.deepEquals(puzzle
, other
.puzzle
)) {
93 if (width
!= other
.width
) {
100 * @see java.lang.Object#toString()
103 public String
toString() {
104 return "AbstractRectangularPuzzle [width=" + width
+ ", height="
105 + height
+ ", puzzle=" + Arrays
.toString(puzzle
) + "]";