@@ -90,31 +90,19 @@ public boolean isBeforeFirst()
90
90
91
91
public boolean hasPrevious ()
92
92
{
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 );
102
94
}
103
95
104
96
105
97
public int nextIndex ()
106
98
{
107
- int result = 0 ;
108
- result = position + 1 ;
109
- return result ;
99
+ return position + 1 ;
110
100
}
111
101
112
102
113
103
public int previousIndex ()
114
104
{
115
- int result = 0 ;
116
- result = position - 1 ;
117
- return result ;
105
+ return position - 1 ;
118
106
}
119
107
120
108
@@ -236,15 +224,20 @@ public static OclIterator newOclIterator_Function(Function<Integer,Object> f)
236
224
ot.generatorFunction = f;
237
225
ot.position = 0;
238
226
return ot;
239
- }
227
+ } */
240
228
241
229
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 ;
244
237
position = 0 ;
245
238
markedPosition = 0 ;
246
239
return OclIterator .newOclIterator_Sequence (firstpart );
247
- } */
240
+ }
248
241
249
242
public Object getCurrent ()
250
243
{
@@ -264,12 +257,11 @@ public void set(Object x)
264
257
/* public void insert(Object x)
265
258
{ elements.add(position-1,x); }
266
259
267
-
268
260
public void remove()
269
- { elements.remove(position - 1); }
261
+ { elements.remove(position - 1); } */
270
262
271
263
public boolean tryAdvance (Function <Object ,Object > f )
272
- { if (position + 1 <= elements.size() )
264
+ { if (position + 1 <= elements .length )
273
265
{ Object x = this .next ();
274
266
f .apply (x );
275
267
return true ;
@@ -278,12 +270,14 @@ public boolean tryAdvance(Function<Object,Object> f)
278
270
}
279
271
280
272
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
+ }
284
278
}
285
279
286
-
280
+ /*
287
281
public OclIteratorResult nextResult()
288
282
{ if (generatorFunction == null)
289
283
{ Object v = next();
@@ -363,7 +357,7 @@ public void close()
363
357
364
358
365
359
public static void main (String [] args )
366
- { ArrayList lst = new ArrayList ();
360
+ { /* ArrayList lst = new ArrayList();
367
361
for (int i = 0; i < 100000; i++)
368
362
{ lst.add(i); }
369
363
OclIterator iter1 = OclIterator.newOclIterator_Sequence(lst);
@@ -377,7 +371,25 @@ public static void main(String[] args)
377
371
378
372
java.util.Date d2 = new java.util.Date();
379
373
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
+
381
393
}
382
394
383
395
}
0 commit comments