@@ -90,31 +90,19 @@ public boolean isBeforeFirst()
9090
9191 public boolean hasPrevious ()
9292 {
93- boolean result = false ;
94- if (position > 1 && position <= elements .length + 1 )
95- {
96- result = true ;
97- }
98- else {
99- result = false ;
100- }
101- return result ;
93+ return (position > 1 && position <= elements .length + 1 );
10294 }
10395
10496
10597 public int nextIndex ()
10698 {
107- int result = 0 ;
108- result = position + 1 ;
109- return result ;
99+ return position + 1 ;
110100 }
111101
112102
113103 public int previousIndex ()
114104 {
115- int result = 0 ;
116- result = position - 1 ;
117- return result ;
105+ return position - 1 ;
118106 }
119107
120108
@@ -236,15 +224,20 @@ public static OclIterator newOclIterator_Function(Function<Integer,Object> f)
236224 ot.generatorFunction = f;
237225 ot.position = 0;
238226 return ot;
239- }
227+ } */
240228
241229 public OclIterator trySplit ()
242- { ArrayList firstpart = Ocl.subrange(elements,1,position-1);
243- elements = Ocl.subrange(elements, position);
230+ { ArrayList firstpart = new ArrayList ();
231+ for (int i = 0 ; i < position ; i ++)
232+ { firstpart .add (elements [i ]); }
233+ Object [] newelements = new Object [elements .length - position ];
234+ for (int i = 0 ; i + position < elements .length ; i ++)
235+ { newelements [i ] = elements [i + position ]; }
236+ elements = newelements ;
244237 position = 0 ;
245238 markedPosition = 0 ;
246239 return OclIterator .newOclIterator_Sequence (firstpart );
247- } */
240+ }
248241
249242 public Object getCurrent ()
250243 {
@@ -264,12 +257,11 @@ public void set(Object x)
264257 /* public void insert(Object x)
265258 { elements.add(position-1,x); }
266259
267-
268260 public void remove()
269- { elements.remove(position - 1); }
261+ { elements.remove(position - 1); } */
270262
271263 public boolean tryAdvance (Function <Object ,Object > f )
272- { if (position + 1 <= elements.size() )
264+ { if (position + 1 <= elements .length )
273265 { Object x = this .next ();
274266 f .apply (x );
275267 return true ;
@@ -278,12 +270,14 @@ public boolean tryAdvance(Function<Object,Object> f)
278270 }
279271
280272 public void forEachRemaining (Function <Object ,Object > f )
281- { ArrayList remainingElements = Ocl.subrange(elements, position);
282- for (Object x : remainingElements)
283- { f.apply(x); }
273+ { // ArrayList remainingElements = Ocl.subrange(elements, position);
274+ for (int i = position ; i < elements .length ; i ++)
275+ { Object x = elements [i ];
276+ f .apply (x );
277+ }
284278 }
285279
286-
280+ /*
287281 public OclIteratorResult nextResult()
288282 { if (generatorFunction == null)
289283 { Object v = next();
@@ -363,7 +357,7 @@ public void close()
363357
364358
365359 public static void main (String [] args )
366- { ArrayList lst = new ArrayList ();
360+ { /* ArrayList lst = new ArrayList();
367361 for (int i = 0; i < 100000; i++)
368362 { lst.add(i); }
369363 OclIterator iter1 = OclIterator.newOclIterator_Sequence(lst);
@@ -377,7 +371,25 @@ public static void main(String[] args)
377371
378372 java.util.Date d2 = new java.util.Date();
379373 long t2 = d2.getTime();
380- System .out .println (t2 -t1 );
374+ System.out.println(t2-t1); */
375+
376+ Function <Object ,Object > ff = (y )->{ System .out .println (y ); return y ; };
377+
378+ ArrayList lst = new ArrayList ();
379+ lst .add (1 ); lst .add (2 ); lst .add (3 ); lst .add (4 ); lst .add (5 );
380+ OclIterator iter1 = OclIterator .newOclIterator_Sequence (lst );
381+ iter1 .forEachRemaining (ff );
382+ System .out .println ();
383+ // System.out.println(iter1.elements);
384+ iter1 .setPosition (3 );
385+ OclIterator iter2 = iter1 .trySplit ();
386+ // System.out.println(iter1.elements);
387+ // System.out.println(iter2.elements);
388+
389+ iter1 .forEachRemaining (ff );
390+ System .out .println ();
391+ iter2 .forEachRemaining (ff );
392+
381393 }
382394
383395}
0 commit comments