public static <E> boolean addAll(final ObjCollection<E> collection, Collection<? extends E> another) { if (collection == another) throw new IllegalArgumentException(); long maxPossibleSize = collection.sizeAsLong() + Containers.sizeAsLong(another); collection.ensureCapacity(maxPossibleSize); if (another instanceof ObjCollection) { if (another instanceof InternalObjCollectionOps) { return ((InternalObjCollectionOps) another).reverseAddAllTo(collection); } else { class AddAll implements Consumer<E> { boolean collectionChanged = false; @Override public void accept(E value) { collectionChanged |= collection.add(value); } } AddAll addAll = new AddAll(); ((ObjCollection) another).forEach(addAll); return addAll.collectionChanged; } } else { boolean collectionChanged = false; for (E v : another) { collectionChanged |= collection.add(v); } return collectionChanged; } }
public static <E> boolean addAll(final ObjCollection<E> collection, Collection<? extends E> another) { if (collection == another) throw new IllegalArgumentException(); long maxPossibleSize = collection.sizeAsLong() + Containers.sizeAsLong(another); collection.ensureCapacity(maxPossibleSize); if (another instanceof ObjCollection) { if (another instanceof InternalObjCollectionOps) { return ((InternalObjCollectionOps) another).reverseAddAllTo(collection); } else { class AddAll implements Consumer<E> { boolean collectionChanged = false; @Override public void accept(E value) { collectionChanged |= collection.add(value); } } AddAll addAll = new AddAll(); ((ObjCollection) another).forEach(addAll); return addAll.collectionChanged; } } else { boolean collectionChanged = false; for (E v : another) { collectionChanged |= collection.add(v); } return collectionChanged; } }