|
7 | 7 | public final class Slot {
|
8 | 8 | int row, slot, col;
|
9 | 9 |
|
10 |
| - public static final Slot FIRST = new Slot(1, 1); |
11 |
| - public static final Slot NaS = new Slot(8, 1); |
| 10 | + /** |
| 11 | + * First as in row 1, col 1. |
| 12 | + * Slot = 1 (always) |
| 13 | + */ |
| 14 | + public static final Slot FIRST = getFirst(); |
| 15 | + |
| 16 | + /** |
| 17 | + * Not A Slot; a purposeful invalid slot to save performance and memory. |
| 18 | + */ |
| 19 | + public static final Slot NaS = getNaS(); |
12 | 20 |
|
13 | 21 | public Slot(final int row, final int col) {
|
14 | 22 | this.row = row;
|
@@ -57,7 +65,9 @@ public Slot setSlot(final int row, final int col) {
|
57 | 65 | public Slot setSlot(@NotNull final Slot slot) {
|
58 | 66 | this.row = slot.row;
|
59 | 67 | this.col = slot.col;
|
60 |
| - this.slot = slot.slot; |
| 68 | + |
| 69 | + int preSlot = slot.slot; |
| 70 | + this.slot = preSlot >= 54 ? -1 : preSlot; |
61 | 71 | return this;
|
62 | 72 | }
|
63 | 73 |
|
@@ -119,4 +129,20 @@ public int getSlot() {
|
119 | 129 | public boolean isSlot() {
|
120 | 130 | return slot != -1;
|
121 | 131 | }
|
| 132 | + |
| 133 | + // faster NaS (Not A Slot) alternative to creating a Slot like new Slot(8, 1); |
| 134 | + @NotNull |
| 135 | + private static Slot getNaS() { |
| 136 | + Slot slot = new Slot(-1, -1, true); |
| 137 | + slot.slot = -1; |
| 138 | + return slot; |
| 139 | + } |
| 140 | + |
| 141 | + // faster FIRST slot compared to doing "new Slot(1, 1)" |
| 142 | + @NotNull |
| 143 | + private static Slot getFirst() { |
| 144 | + Slot slot = new Slot(1, 1, true); |
| 145 | + slot.slot = 1; |
| 146 | + return slot; |
| 147 | + } |
122 | 148 | }
|
0 commit comments