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
;
10 public abstract class AbstractRectangularPuzzle
<T
> extends AbstractPuzzle
{
12 final protected int width
;
13 final protected int height
;
14 final protected T puzzle
[][];
15 final protected T correctPuzzle
[][];
17 protected AbstractRectangularPuzzle(T
[][] puzzle
, Difficulty difficulty
) {
18 super(Matrices
.getWidth(puzzle
) * Matrices
.getHeight(puzzle
), 0,
20 this.width
= Matrices
.getWidth(puzzle
);
21 this.height
= Matrices
.getHeight(puzzle
);
23 this.correctPuzzle
= makeCorrectPuzzle();
26 protected AbstractRectangularPuzzle(
27 AbstractRectangularPuzzle
<T
> rectangularPuzzle
) {
28 super(rectangularPuzzle
);
29 this.width
= rectangularPuzzle
.width
;
30 this.height
= rectangularPuzzle
.height
;
31 this.puzzle
= (T
[][]) Matrices
.copyOf(rectangularPuzzle
.puzzle
);
32 this.correctPuzzle
= makeCorrectPuzzle();
35 public T
[][] getCorrectPuzzle() {
36 return Matrices
.copyOf(correctPuzzle
);
42 * @return the width of the puzzle.
44 public final int getWidth() {
48 abstract public T
[][] makeCorrectPuzzle();
53 * @return the height of the puzzle.
55 public final int getHeight() {
62 * @return the puzzle matrix.
64 public final T
[][] getPuzzle() {
65 return Matrices
.copyOf(puzzle
);
72 * @see java.lang.Object#hashCode()
75 public int hashCode() {
77 int result
= super.hashCode();
78 result
= prime
* result
+ height
;
79 result
= prime
* result
+ Arrays
.hashCode(puzzle
);
80 result
= prime
* result
+ width
;
87 * @see java.lang.Object#equals(java.lang.Object)
90 @SuppressWarnings("rawtypes")
91 public boolean equals(Object obj
) {
95 if (!super.equals(obj
)) {
98 if (getClass() != obj
.getClass()) {
101 AbstractRectangularPuzzle other
= (AbstractRectangularPuzzle
) obj
;
102 if (height
!= other
.height
) {
105 if (!Arrays
.deepEquals(puzzle
, other
.puzzle
)) {
108 if (width
!= other
.width
) {
117 * @see java.lang.Object#toString()
120 public String
toString() {
121 return "AbstractRectangularPuzzle [width=" + width
+ ", height="
122 + height
+ ", puzzle=" + Arrays
.toString(puzzle
) + "]";