/** * Gets an iterator that iterates through a collections of {@link Iterator}s * one after another. * * @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 Iterator chainedIterator(Collection iterators) { return new IteratorChain(iterators); }
/** * Returns <code>true</code> if any child iterator has remaining elements. * * @return true if this iterator has remaining elements */ public boolean hasNext() { start(); return anyValueSet(valueSet) || anyHasNext(iterators); }
/** * Gets an immutable version of an {@link Iterator}. The returned object * will always throw an {@link UnsupportedOperationException} for * the {@link Iterator#remove} method. * * @param iterator the iterator to make immutable * @return an immutable version of the iterator */ public static Iterator unmodifiableIterator(Iterator iterator) { return UnmodifiableIterator.decorate(iterator); }
public void testEmptyChain() { IteratorChain chain = new IteratorChain(); assertEquals(false, chain.hasNext()); try { chain.next(); fail(); } catch (NoSuchElementException ex) {} try { chain.remove(); fail(); } catch (IllegalStateException ex) {} }
/** * Returns an full iterator wrapped in a * FilterIterator that blocks all the elements * * @return "empty" FilterIterator */ public Iterator makeEmptyIterator() { return makeBlockAllFilter(new ArrayIterator(array)); }
public void testGetSetComparator() { CollatingIterator iter = new CollatingIterator(); assertNull(iter.getComparator()); iter.setComparator(comparator); assertSame(comparator,iter.getComparator()); iter.setComparator(null); assertNull(iter.getComparator()); }
public void testIteration_Transformed1() { Forest forest = new Forest(); Leaf l1 = forest.addTree().addBranch().addLeaf(); Iterator it = new ObjectGraphIterator(forest, new LeafFinder()); assertEquals(true, it.hasNext()); assertSame(l1, it.next()); assertEquals(false, it.hasNext()); try { it.next(); fail(); } catch (NoSuchElementException ex) { } }
private void verifyNoMoreElements() { assertTrue(!iterator.hasNext()); try { iterator.next(); fail("NoSuchElementException expected"); } catch (NoSuchElementException e) { // success } }
public void testIteration_RootNoTransformer() { Forest forest = new Forest(); Iterator it = new ObjectGraphIterator(forest, null); assertEquals(true, it.hasNext()); assertSame(forest, it.next()); assertEquals(false, it.hasNext()); try { it.next(); fail(); } catch (NoSuchElementException ex) { } }
/** * Tests constructor exception. */ public void testConstructorEx() throws Exception { try { new LoopingIterator(null); fail(); } catch (NullPointerException ex) { } }
public void testReset() { ArrayIterator it = (ArrayIterator) makeFullIterator(); it.next(); it.reset(); assertEquals("One", it.next()); }
public void testReset() { ObjectArrayIterator it = makeArrayIterator(testArray); it.next(); it.reset(); assertEquals("One", it.next()); }
/** * Tests constructor exception. */ public void testConstructorEx() throws Exception { try { new LoopingListIterator(null); fail(); } catch (NullPointerException ex) { } }
public void testRepeatedNext() { for (int i = 0; i < array.length; i++) iterator.next(); verifyNoMoreElements(); }
/** * Checks whether there are any more elements in the iteration to obtain. * * @return true if elements remain in the iteration */ public boolean hasNext() { updateCurrentIterator(); return hasNext; }
/** * Sets the {@link Comparator} by which collation occurs. * * @throws IllegalStateException if iteration has started */ public void setComparator(final Comparator comp) { checkNotStarted(); comparator = comp; }
public void testRepeatedHasNext() { for (int i = 0; i <= array.length; i++) { assertTrue(iterator.hasNext()); } }
/** * Returns a SingletonListIterator from which * the element has already been removed. */ public ListIterator makeEmptyListIterator() { SingletonListIterator iter = (SingletonListIterator)makeFullIterator(); iter.next(); iter.remove(); iter.reset(); return iter; }
/** * Returns a SingletonIterator from which * the element has already been removed. */ public Iterator makeEmptyIterator() { SingletonIterator iter = (SingletonIterator)makeFullIterator(); iter.next(); iter.remove(); iter.reset(); return iter; }
public void testDoubleSet() { ObjectArrayIterator it = makeArrayIterator(); it.setArray(new String[0]); try { it.setArray(new String[0]); fail(); } catch (IllegalStateException ex) { } }