@Override public boolean add(final K k) { synchronized (sync) { return collection.add(k); } } @Override
/** * Unwraps an iterator into a type-specific collection. * * <p> * This method iterates over the given type-specific iterator and stores the * elements returned in the given type-specific collection. The returned count * on the number unwrapped elements is a long, so that it will work also with * very large collections. * * @param i * a type-specific iterator. * @param c * a type-specific collection to contain the output of the iterator. * @return the number of elements unwrapped. Note that this is the number of * elements returned by the iterator, which is not necessarily the * number of elements that have been added to the collection (because of * duplicates). */ public static <K> long unwrap(final Iterator<K> i, final ObjectCollection<? super K> c) { long n = 0; while (i.hasNext()) { c.add(i.next()); n++; } return n; } /**
/** * Pours an iterator into a type-specific collection, with a limit on the number * of elements. * * <p> * This method iterates over the given type-specific iterator and adds the * returned elements to the given collection (up to {@code max}). * * @param i * a type-specific iterator. * @param s * a type-specific collection. * @param max * the maximum number of elements to be poured. * @return the number of elements poured. Note that this is the number of * elements returned by the iterator, which is not necessarily the * number of elements that have been added to the collection (because of * duplicates). */ public static <K> int pour(final Iterator<K> i, final ObjectCollection<? super K> s, final int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); int j = max; while (j-- != 0 && i.hasNext()) s.add(i.next()); return max - j - 1; } /**
int j = max; while (j-- != 0 && i.hasNext()) c.add(i.next()); return max - j - 1;