/** * Constructs a new <code>IteratorChain</code> over the array of iterators. * <p> * This method takes an array of iterators. The newly constructed iterator * will iterate through each one of the input iterators in turn. * * @param iteratorChain the array of iterators, not null * @throws NullPointerException if iterators array is or contains null */ public IteratorChain(final Iterator<? extends E>... iteratorChain) { super(); for (final Iterator<? extends E> element : iteratorChain) { addIterator(element); } }
/** * Constructs a new <code>IteratorChain</code> over the two given iterators. * <p> * This method takes two iterators. The newly constructed iterator will * iterate through each one of the input iterators in turn. * * @param first the first child iterator in the IteratorChain, not null * @param second the second child iterator in the IteratorChain, not null * @throws NullPointerException if either iterator is null */ public IteratorChain(final Iterator<? extends E> first, final Iterator<? extends E> second) { super(); addIterator(first); addIterator(second); }
/** * Construct an IteratorChain with a single Iterator. * <p> * This method takes one iterator. The newly constructed iterator will * iterate through that iterator. Thus calling this constructor on its own * will have no effect other than decorating the input iterator. * <p> * You will normally use {@link #addIterator(Iterator)} to add some more * iterators after using this constructor. * * @param iterator the first child iterator in the IteratorChain, not null * @throws NullPointerException if the iterator is null */ public IteratorChain(final Iterator<? extends E> iterator) { super(); addIterator(iterator); }
/** * Constructs a new <code>IteratorChain</code> over the collection of * iterators. * <p> * This method takes a collection of iterators. The newly constructed * iterator will iterate through each one of the input iterators in turn. * * @param iteratorChain the collection of iterators, not null * @throws NullPointerException if iterators collection is or contains null * @throws ClassCastException if iterators collection doesn't contain an * iterator */ public IteratorChain(final Collection<Iterator<? extends E>> iteratorChain) { super(); for (final Iterator<? extends E> iterator : iteratorChain) { addIterator(iterator); } }
/** * Gets an iterator over all the sets in this composite. * <p> * This implementation uses an <code>IteratorChain</code>. * * @return an <code>IteratorChain</code> instance which supports * <code>remove()</code>. Iteration occurs over contained collections in * the order they were added, but this behavior should not be relied upon. * @see IteratorChain */ @Override public Iterator<E> iterator() { if (all.isEmpty()) { return EmptyIterator.<E>emptyIterator(); } final IteratorChain<E> chain = new IteratorChain<>(); for (final Set<E> item : all) { chain.addIterator(item.iterator()); } return chain; }
/** * Gets an iterator over all the collections in this composite. * <p> * This implementation uses an <code>IteratorChain</code>. * * @return an <code>IteratorChain</code> instance which supports * <code>remove()</code>. Iteration occurs over contained collections in * the order they were added, but this behavior should not be relied upon. * @see IteratorChain */ @Override public Iterator<E> iterator() { if (all.isEmpty()) { return EmptyIterator.<E>emptyIterator(); } final IteratorChain<E> chain = new IteratorChain<>(); for (final Collection<E> item : all) { chain.addIterator(item.iterator()); } return chain; }
public ChainedNodeIterator(List<NodeIterator> iterators) { for (NodeIterator it : iterators) { this.iterators.addIterator(it); // If any of the iterators returns -1 the we must also return -1 long s = it.getSize(); if (size != -1) { if (s == -1) { size = -1; } else { size += s; } } } }
@Override public Iterator<T> iterator() { IteratorChain<T> iterator = new IteratorChain<>(); for (IterableResult<T> result : this.results) { iterator.addIterator(result.iterator()); } return iterator; }
chain.addIterator(realChildren); chain.addIterator(providerList.iterator()); chain.addIterator(syntheticList.iterator());