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