@@ -31,6 +31,9 @@ enum Type {
3131
3232 boolean ended ();
3333
34+ boolean allowOverride ();
35+ SlotIterator allowOverride (boolean override );
36+
3437
3538 class Impl implements SlotIterator {
3639
@@ -39,6 +42,7 @@ class Impl implements SlotIterator {
3942
4043 private Type type ;
4144 private int row , column ;
45+ private boolean allowOverride ;
4246
4347 private Set <Pair <Integer , Integer >> blacklisted = new HashSet <>();
4448
@@ -96,7 +100,8 @@ public SlotIterator previous() {
96100 break ;
97101 }
98102 }
99- while ((row != 0 || column != 0 ) && blacklisted .contains (Pair .of (row , column )));
103+ while ((row != 0 || column != 0 ) && blacklisted .contains (Pair .of (row , column ))
104+ && (allowOverride || !this .get ().isPresent ()));
100105
101106 return this ;
102107 }
@@ -122,7 +127,8 @@ public SlotIterator next() {
122127 break ;
123128 }
124129 }
125- while (!ended () && blacklisted .contains (Pair .of (row , column )));
130+ while (!ended () && blacklisted .contains (Pair .of (row , column ))
131+ && (allowOverride || !this .get ().isPresent ()));
126132
127133 return this ;
128134 }
@@ -157,6 +163,14 @@ public boolean ended() {
157163 && column == inv .getColumns () - 1 ;
158164 }
159165
166+ @ Override
167+ public boolean allowOverride () { return allowOverride ; }
168+
169+ @ Override
170+ public SlotIterator allowOverride (boolean override ) {
171+ this .allowOverride = override ;
172+ return this ;
173+ }
160174 }
161175
162176}
0 commit comments