/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }
/** * Tests the reset() method on a LoopingIterator wrapped ArrayList. * @throws Exception If something unexpected occurs. */ public void testReset() throws Exception { List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" })); LoopingIterator loop = new LoopingIterator(list); assertEquals("a", loop.next()); assertEquals("b", loop.next()); loop.reset(); assertEquals("a", loop.next()); loop.reset(); assertEquals("a", loop.next()); assertEquals("b", loop.next()); assertEquals("c", loop.next()); loop.reset(); assertEquals("a", loop.next()); assertEquals("b", loop.next()); assertEquals("c", loop.next()); }
/** * Tests the size() method on a LoopingIterator wrapped ArrayList. * @throws Exception If something unexpected occurs. */ public void testSize() throws Exception { List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" })); LoopingIterator loop = new LoopingIterator(list); assertEquals(3, loop.size()); loop.next(); loop.next(); assertEquals(3, loop.size()); loop.reset(); assertEquals(3, loop.size()); loop.next(); loop.remove(); assertEquals(2, loop.size()); }
/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Constructor that wraps a collection. * <p> * There is no way to reset an Iterator instance without recreating it from * the original source, so the Collection must be passed in. * * @param coll the collection to wrap * @throws NullPointerException if the collection is null */ public LoopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } collection = coll; reset(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }
/** * Returns the next object in the collection. * <p> * If at the end of the collection, return the first element. * * @throws NoSuchElementException if there are no elements * at all. Use {@link #hasNext} to avoid this error. */ public Object next() { if (collection.size() == 0) { throw new NoSuchElementException("There are no elements for this iterator to loop on"); } if (iterator.hasNext() == false) { reset(); } return iterator.next(); }