@@ -36,7 +36,7 @@ public Slot shift(Slot oldPos, int maxRows) {
36
36
oldRow ++;
37
37
}
38
38
39
- return new Slot (oldRow , oldCol );
39
+ return oldPos . setSlot (oldRow , oldCol );
40
40
}
41
41
},
42
42
@@ -58,73 +58,51 @@ public Slot shift(Slot oldPos, int maxRows) {
58
58
@ Override
59
59
public Slot shift (Slot oldPos , int maxRows ) {
60
60
int col = oldPos .col + 1 ;
61
- if (col > 9 ) {
62
- return Slot .NaS ;
63
- }
64
- return new Slot (oldPos .row , col );
61
+ return col > 9 ? Slot .NaS : oldPos .setSlot (oldPos .row , col );
65
62
}
66
63
},
67
64
68
65
LEFT_ONLY {
69
66
@ Override
70
67
public Slot shift (Slot oldPos , int maxRows ) {
71
68
int col = oldPos .col - 1 ;
72
- if (col < 0 ) {
73
- return Slot .NaS ;
74
- }
75
- return new Slot (oldPos .row , col );
69
+ return col < 0 ? Slot .NaS : oldPos .setSlot (oldPos .row , col );
76
70
}
77
71
},
78
72
79
73
RIGHT_UPWARDS_ONLY {
80
74
@ Override
81
75
public Slot shift (Slot oldPos , int maxRows ) {
82
76
Slot upwardSlot = UPWARDS_ONLY .shift (oldPos , maxRows );
83
- int row = upwardSlot .row ;
84
-
85
77
Slot rightSlot = RIGHT_ONLY .shift (oldPos , maxRows );
86
- int col = rightSlot .col ;
87
-
88
- return new Slot (row , col );
78
+ return oldPos .setSlot (upwardSlot .row , rightSlot .col );
89
79
}
90
80
},
91
81
92
82
RIGHT_DOWNWARDS_ONLY {
93
83
@ Override
94
84
public Slot shift (Slot oldPos , int maxRows ) {
95
85
Slot downwardSlot = DOWNWARDS_ONLY .shift (oldPos , maxRows );
96
- int row = downwardSlot .row ;
97
-
98
86
Slot rightSlot = RIGHT_ONLY .shift (oldPos , maxRows );
99
- int col = rightSlot .col ;
100
-
101
- return new Slot (row , col );
87
+ return oldPos .setSlot (downwardSlot .row , rightSlot .col );
102
88
}
103
89
},
104
90
105
91
LEFT_UPWARDS {
106
92
@ Override
107
93
public Slot shift (Slot oldPos , int maxRows ) {
108
94
Slot upwardSlot = UPWARDS_ONLY .shift (oldPos , maxRows );
109
- int row = upwardSlot .row ;
110
-
111
95
Slot leftSlot = LEFT_ONLY .shift (oldPos , maxRows );
112
- int col = leftSlot .col ;
113
-
114
- return new Slot (row , col );
96
+ return oldPos .setSlot (upwardSlot .row , leftSlot .col );
115
97
}
116
98
},
117
99
118
100
LEFT_DOWNWARDS {
119
101
@ Override
120
102
public Slot shift (Slot oldPos , int maxRows ) {
121
103
Slot downwardSlot = DOWNWARDS_ONLY .shift (oldPos , maxRows );
122
- int row = downwardSlot .row ;
123
-
124
104
Slot leftSlot = LEFT_ONLY .shift (oldPos , maxRows );
125
- int col = leftSlot .col ;
126
-
127
- return new Slot (row , col );
105
+ return oldPos .setSlot (downwardSlot .row , leftSlot .col );
128
106
}
129
107
},
130
108
@@ -141,7 +119,7 @@ public Slot shift(Slot oldPos, int maxRows) {
141
119
oldCol --;
142
120
}
143
121
144
- return new Slot (oldRow , oldCol );
122
+ return oldPos . setSlot (oldRow , oldCol );
145
123
}
146
124
},
147
125
@@ -158,7 +136,7 @@ public Slot shift(Slot oldPos, int maxRows) {
158
136
oldRow --;
159
137
}
160
138
161
- return new Slot (oldRow , oldCol );
139
+ return oldPos . setSlot (oldRow , oldCol );
162
140
}
163
141
};
164
142
0 commit comments