@@ -96,7 +96,7 @@ public boolean isBeforeFirst()
9696 return result ;
9797 }
9898
99- public boolean hasPrevious ()
99+ public boolean hasPrevious ()
100100 {
101101 boolean result = false ;
102102 if (position > 1 && position <= elements .size () + 1 )
@@ -110,35 +110,35 @@ public boolean hasPrevious()
110110 }
111111
112112
113- public int nextIndex ()
113+ public int nextIndex ()
114114 {
115115 int result = 0 ;
116116 result = position + 1 ;
117117 return result ;
118118 }
119119
120120
121- public int previousIndex ()
121+ public int previousIndex ()
122122 {
123123 int result = 0 ;
124124 result = position - 1 ;
125125 return result ;
126126 }
127127
128128
129- public void moveForward ()
129+ public void moveForward ()
130130 {
131131 position = position + 1 ;
132132 }
133133
134134
135- public void moveBackward ()
135+ public void moveBackward ()
136136 {
137137 position = position - 1 ;
138138 }
139139
140140
141- public void moveTo ( int i )
141+ public void moveTo ( int i )
142142 {
143143 position = i ;
144144 }
@@ -158,29 +158,29 @@ public void movePosition(int i)
158158 position = i + position ;
159159 }
160160
161- public void moveToMarkedPosition ()
161+ public void moveToMarkedPosition ()
162162 {
163163 position = markedPosition ;
164164 }
165165
166- public void moveToFirst ()
166+ public void moveToFirst ()
167167 {
168168 position = 1 ;
169169 }
170170
171- public void moveToLast ()
171+ public void moveToLast ()
172172 {
173173 position = elements .size ();
174174 }
175175
176176
177- public void moveToStart ()
177+ public void moveToStart ()
178178 {
179179 position = 0 ;
180180 }
181181
182182
183- public void moveToEnd ()
183+ public void moveToEnd ()
184184 {
185185 position = elements .size () + 1 ;
186186 }
@@ -230,6 +230,13 @@ public static OclIterator newOclIterator_Function(Function<Integer,Object> f)
230230 return ot ;
231231 }
232232
233+ public OclIterator trySplit ()
234+ { ArrayList firstpart = Ocl .subrange (elements ,1 ,position -1 );
235+ elements = Ocl .subrange (elements , position );
236+ position = 0 ;
237+ markedPosition = 0 ;
238+ return OclIterator .newOclIterator_Sequence (firstpart );
239+ }
233240
234241 public Object getCurrent ()
235242 {
@@ -240,19 +247,35 @@ public Object getCurrent()
240247 }
241248
242249
243- public void set (Object x )
250+ public void set (Object x )
244251 {
245252 elements .set (position - 1 ,x );
246253 }
247254
248255
249- public void insert (Object x )
256+ public void insert (Object x )
250257 { elements .add (position -1 ,x ); }
251258
252259
253- public void remove ()
260+ public void remove ()
254261 { elements .remove (position - 1 ); }
255262
263+ public boolean tryAdvance (Function <Object ,Object > f )
264+ { if (position + 1 <= elements .size ())
265+ { Object x = this .next ();
266+ f .apply (x );
267+ return true ;
268+ }
269+ return false ;
270+ }
271+
272+ public void forEachRemaining (Function <Object ,Object > f )
273+ { ArrayList remainingElements = Ocl .subrange (elements , position );
274+ for (Object x : remainingElements )
275+ { f .apply (x ); }
276+ }
277+
278+
256279 public OclIteratorResult nextResult ()
257280 { if (generatorFunction == null )
258281 { Object v = next ();
@@ -331,6 +354,21 @@ public void close()
331354 elements = (new ArrayList ());
332355 columnNames = new ArrayList <String >();
333356 }
357+
358+ /*
359+ public static void main(String[] args)
360+ { ArrayList lst = new ArrayList();
361+ lst.add(1); lst.add(2); lst.add(3); lst.add(4); lst.add(5);
362+ OclIterator iter1 = OclIterator.newOclIterator_Sequence(lst);
363+ System.out.println(iter1.elements);
364+ iter1.setPosition(3);
365+ OclIterator iter2 = iter1.trySplit();
366+ System.out.println(iter1.elements);
367+ System.out.println(iter2.elements);
368+
369+ Function<Object,Object> ff = (y)->{ System.out.println(y); return y; };
370+ iter1.forEachRemaining(ff);
371+ } */
334372
335373}
336374
0 commit comments