10
10
import java .util .NoSuchElementException ;
11
11
12
12
import net .lecousin .framework .application .LCCore ;
13
+ import net .lecousin .framework .concurrent .CancelException ;
13
14
import net .lecousin .framework .concurrent .Task ;
14
15
import net .lecousin .framework .exception .NoException ;
15
16
@@ -296,6 +297,10 @@ private void increase() {
296
297
}
297
298
298
299
private void increase (int newSize ) {
300
+ if (decreaseTask != null ) {
301
+ decreaseTask .cancel (new CancelException ("TurnArray increase again" ));
302
+ decreaseTask = null ;
303
+ }
299
304
Object [] a = new Object [newSize ];
300
305
if (end == -1 ) {
301
306
System .arraycopy (array , start , a , 0 , array .length - start );
@@ -328,19 +333,20 @@ private void decrease() {
328
333
if (newSize < minSize ) newSize = minSize ;
329
334
if (newSize >= array .length ) return ;
330
335
if (size () >= newSize ) return ;
336
+ if (end == -1 ) return ;
331
337
Object [] a = new Object [newSize ];
332
338
if (end > start ) {
333
339
System .arraycopy (array , start , a , 0 , end - start );
334
340
end = end - start ;
335
- if (end == newSize ) end = -1 ;
336
341
start = 0 ;
337
342
} else if (end < start ) {
338
343
System .arraycopy (array , start , a , 0 , array .length - start );
339
344
if (end > 0 )
340
345
System .arraycopy (array , 0 , a , array .length - start , end );
341
346
end = array .length - start + end ;
342
- if (end == newSize ) end = -1 ;
343
347
start = 0 ;
348
+ } else {
349
+ start = end = 0 ;
344
350
}
345
351
array = a ;
346
352
}
@@ -354,6 +360,7 @@ public DecreaseTask() {
354
360
@ Override
355
361
public Void run () {
356
362
synchronized (TurnArray .this ) {
363
+ if (isCancelling ()) return null ;
357
364
decreaseTask = null ;
358
365
decrease ();
359
366
}
0 commit comments