I have deleted some warnings :)
[puzzles.git] / src / com / github / puzzles / core / AbstractRectangularPuzzle.java
blobc1321ebe6c5de2828c8e0d34bda2d349c0daf512
1 /**
2 * Rectangular puzzles should inherit this class.
3 */
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,
19 difficulty);
20 this.width = Matrices.getWidth(puzzle);
21 this.height = Matrices.getHeight(puzzle);
22 this.puzzle = 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);
39 /**
40 * Getter.
42 * @return the width of the puzzle.
44 public final int getWidth() {
45 return width;
48 abstract public T[][] makeCorrectPuzzle();
50 /**
51 * Getter.
53 * @return the height of the puzzle.
55 public final int getHeight() {
56 return height;
59 /**
60 * Getter.
62 * @return the puzzle matrix.
64 public final T[][] getPuzzle() {
65 return Matrices.copyOf(puzzle);
66 // return puzzle;
70 * (non-Javadoc)
72 * @see java.lang.Object#hashCode()
74 @Override
75 public int hashCode() {
76 final int prime = 31;
77 int result = super.hashCode();
78 result = prime * result + height;
79 result = prime * result + Arrays.hashCode(puzzle);
80 result = prime * result + width;
81 return result;
85 * (non-Javadoc)
87 * @see java.lang.Object#equals(java.lang.Object)
89 @Override
90 @SuppressWarnings("rawtypes")
91 public boolean equals(Object obj) {
92 if (this == obj) {
93 return true;
95 if (!super.equals(obj)) {
96 return false;
98 if (getClass() != obj.getClass()) {
99 return false;
101 AbstractRectangularPuzzle other = (AbstractRectangularPuzzle) obj;
102 if (height != other.height) {
103 return false;
105 if (!Arrays.deepEquals(puzzle, other.puzzle)) {
106 return false;
108 if (width != other.width) {
109 return false;
111 return true;
115 * (non-Javadoc)
117 * @see java.lang.Object#toString()
119 @Override
120 public String toString() {
121 return "AbstractRectangularPuzzle [width=" + width + ", height="
122 + height + ", puzzle=" + Arrays.toString(puzzle) + "]";