/** * 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; }
/** * Add an Iterator to the end of the chain * * @param iterator Iterator to add * @throws IllegalStateException if I've already started iterating * @throws NullPointerException if the iterator is null */ public void addIterator(final Iterator<? extends E> iterator) { checkLocked(); if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } iteratorChain.add(iterator); }
/** * Return true if any Iterator in the IteratorChain has a remaining element. * * @return true if elements remain */ @Override public boolean hasNext() { lockChain(); updateCurrentIterator(); lastUsedIterator = currentIterator; return currentIterator.hasNext(); }
/** * Gets an iterator that iterates through an array of {@link Iterator}s * one after another. * * @param <E> the element type * @param iterators the iterators to use, not null or empty or contain nulls * @return a combination iterator over the iterators * @throws NullPointerException if iterators array is null or contains a null */ public static <E> Iterator<E> chainedIterator(final Iterator<? extends E>... iterators) { return new IteratorChain<>(iterators); }
IteratorChain chain = new IteratorChain(); if ( realChildren != null ) { chain.addIterator(realChildren); chain.addIterator(providerList.iterator()); chain.addIterator(syntheticList.iterator()); if ( chain.size() == 0 ) { return Collections.EMPTY_LIST.iterator();
/** * 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); } }
@Override public Node nextNode() { Node node = (Node) iterators.next(); position++; return node; } }
@Override public boolean hasNext() { return iterators.hasNext(); }
/** * Gets an iterator that iterates through a collections of {@link Iterator}s * one after another. * * @param <E> the element type * @param iterators the iterators to use, not null or empty or contain nulls * @return a combination iterator over the iterators * @throws NullPointerException if iterators collection is null or contains a null * @throws ClassCastException if the iterators collection contains the wrong object type */ public static <E> Iterator<E> chainedIterator(final Collection<Iterator<? extends E>> iterators) { return new IteratorChain<>(iterators); }
/** * 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); }
/** * 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; }
/** * Gets an iterator that iterates through two {@link Iterator}s * one after another. * * @param <E> the element type * @param iterator1 the first iterator to use, not null * @param iterator2 the second iterator to use, not null * @return a combination iterator over the iterators * @throws NullPointerException if either iterator is null */ public static <E> Iterator<E> chainedIterator(final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { // keep a version with two iterators to avoid the following warning in client code (Java 5 & 6) // "A generic array of E is created for a varargs parameter" return new IteratorChain<>(iterator1, iterator2); }
/** * 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); }
/** * Returns the next Object of the current Iterator * * @return Object from the current Iterator * @throws java.util.NoSuchElementException if all the Iterators are * exhausted */ @Override public E next() { lockChain(); updateCurrentIterator(); lastUsedIterator = currentIterator; return currentIterator.next(); }
@Override public Iterator<T> iterator() { IteratorChain<T> iterator = new IteratorChain<>(); for (IterableResult<T> result : this.results) { iterator.addIterator(result.iterator()); } return iterator; }
@Override public Iterator<E> iterator() { return UnmodifiableIterator.decorate(new IteratorChain(Arrays.asList(used.iterator(),unused.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); } }
/** * Removes from the underlying collection the last element returned by the * Iterator. As with next() and hasNext(), this method calls remove() on the * underlying Iterator. Therefore, this method may throw an * UnsupportedOperationException if the underlying Iterator does not support * this method. * * @throws UnsupportedOperationException if the remove operator is not * supported by the underlying Iterator * @throws IllegalStateException if the next method has not yet been called, * or the remove method has already been called after the last call to the * next method. */ @Override public void remove() { lockChain(); if (currentIterator == null) { updateCurrentIterator(); } lastUsedIterator.remove(); }
/** * @inheritDoc */ public Enumeration getAttributeNames() { Set<String> nonPortableAttributeNames = m_nonPortalSession.getAllAttributes().keySet(); IteratorChain ic = new IteratorChain(m_attributes.keySet().iterator(),nonPortableAttributeNames.iterator()); return new IteratorEnumeration(ic); }
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; } } } }