473 |
} |
} |
474 |
|
|
475 |
/** |
/** |
476 |
|
* Remove from this list all elements contained in the given collection. |
477 |
|
* This is not public, due to Sun's API, but this performs in linear |
478 |
|
* time while the default behavior of AbstractList would be quadratic. |
479 |
|
* |
480 |
|
* @param c the collection to filter out |
481 |
|
* @return true if this list changed |
482 |
|
* @throws NullPointerException if c is null |
483 |
|
*/ |
484 |
|
boolean removeAllInternal(Collection c) |
485 |
|
{ |
486 |
|
int i; |
487 |
|
int j; |
488 |
|
for (i = 0; i < size; i++) |
489 |
|
if (c.contains(data[i])) |
490 |
|
break; |
491 |
|
if (i == size) |
492 |
|
return false; |
493 |
|
|
494 |
|
modCount++; |
495 |
|
for (j = i++; i < size; i++) |
496 |
|
if (! c.contains(data[i])) |
497 |
|
data[j++] = data[i]; |
498 |
|
size -= i - j; |
499 |
|
return true; |
500 |
|
} |
501 |
|
|
502 |
|
/** |
503 |
|
* Retain in this vector only the elements contained in the given collection. |
504 |
|
* This is not public, due to Sun's API, but this performs in linear |
505 |
|
* time while the default behavior of AbstractList would be quadratic. |
506 |
|
* |
507 |
|
* @param c the collection to filter by |
508 |
|
* @return true if this vector changed |
509 |
|
* @throws NullPointerException if c is null |
510 |
|
* @since 1.2 |
511 |
|
*/ |
512 |
|
boolean retainAllInternal(Collection c) |
513 |
|
{ |
514 |
|
int i; |
515 |
|
int j; |
516 |
|
for (i = 0; i < size; i++) |
517 |
|
if (! c.contains(data[i])) |
518 |
|
break; |
519 |
|
if (i == size) |
520 |
|
return false; |
521 |
|
|
522 |
|
modCount++; |
523 |
|
for (j = i++; i < size; i++) |
524 |
|
if (c.contains(data[i])) |
525 |
|
data[j++] = data[i]; |
526 |
|
size -= i - j; |
527 |
|
return true; |
528 |
|
} |
529 |
|
|
530 |
|
/** |
531 |
* Serializes this object to the given stream. |
* Serializes this object to the given stream. |
532 |
* |
* |
533 |
* @param out the stream to write to |
* @param out the stream to write to |
535 |
* @serialData the size field (int), the length of the backing array |
* @serialData the size field (int), the length of the backing array |
536 |
* (int), followed by its elements (Objects) in proper order. |
* (int), followed by its elements (Objects) in proper order. |
537 |
*/ |
*/ |
538 |
private void writeObject(ObjectOutputStream out) throws IOException |
private void writeObject(ObjectOutputStream s) throws IOException |
539 |
{ |
{ |
|
int len = data.length; |
|
|
|
|
540 |
// The 'size' field. |
// The 'size' field. |
541 |
out.defaultWriteObject(); |
s.defaultWriteObject(); |
|
|
|
542 |
// We serialize unused list entries to preserve capacity. |
// We serialize unused list entries to preserve capacity. |
543 |
out.writeInt(len); |
int len = data.length; |
544 |
|
s.writeInt(len); |
545 |
for (int i = 0; i < len; i++) |
for (int i = 0; i < len; i++) |
546 |
out.writeObject(data[i]); |
s.writeObject(data[i]); |
547 |
} |
} |
548 |
|
|
549 |
/** |
/** |
555 |
* @serialData the size field (int), the length of the backing array |
* @serialData the size field (int), the length of the backing array |
556 |
* (int), followed by its elements (Objects) in proper order. |
* (int), followed by its elements (Objects) in proper order. |
557 |
*/ |
*/ |
558 |
private void readObject(ObjectInputStream in) |
private void readObject(ObjectInputStream s) |
559 |
throws IOException, ClassNotFoundException |
throws IOException, ClassNotFoundException |
560 |
{ |
{ |
561 |
// the `size' field. |
// the `size' field. |
562 |
in.defaultReadObject(); |
s.defaultReadObject(); |
563 |
|
int capacity = s.readInt(); |
|
int capacity = in.readInt(); |
|
564 |
data = new Object[capacity]; |
data = new Object[capacity]; |
|
|
|
565 |
for (int i = 0; i < capacity; i++) |
for (int i = 0; i < capacity; i++) |
566 |
data[i] = in.readObject(); |
data[i] = s.readObject(); |
567 |
} |
} |
568 |
} |
} |