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