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