/** * Pours an iterator, returning a type-specific list. * * <p> * This method iterates over the given type-specific iterator and returns a list * containing the returned elements. Iteration on the returned list is * guaranteed to produce the elements in the same order in which they appeared * in the iterator. * * @param i * a type-specific iterator. * @return a type-specific list containing the returned elements. */ public static <K> ObjectList<K> pour(final Iterator<K> i) { return pour(i, Integer.MAX_VALUE); } private static class IteratorWrapper<K> implements ObjectIterator<K> {
/** * Pours an iterator into a type-specific collection. * * <p> * This method iterates over the given type-specific iterator and adds the * returned elements to the given collection. * * @param i * a type-specific iterator. * @param s * a type-specific collection. * @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) { return pour(i, s, Integer.MAX_VALUE); } /**
/** * Pours an iterator, returning a type-specific list, with a limit on the number * of elements. * * <p> * This method iterates over the given type-specific iterator and returns a * type-specific list containing the returned elements (up to {@code max}). * Iteration on the returned list is guaranteed to produce the elements in the * same order in which they appeared in the iterator. * * * @param i * a type-specific iterator. * @param max * the maximum number of elements to be poured. * @return a type-specific list containing the returned elements, up to * {@code max}. */ public static <K> ObjectList<K> pour(final Iterator<K> i, int max) { final ObjectArrayList<K> l = new ObjectArrayList<>(); pour(i, l, max); l.trim(); return l; } /**
ObjectIterators.pour( intervalIterator, intervals );
ObjectIterators.pour( intervalIterator, intervals );