From af5dd4d71add2f707026ed1e68b142f3e22f2677 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 21 Nov 2002 23:08:27 +0000 Subject: [PATCH] Add LoopingIterator git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130868 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/collections/IteratorUtils.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/commons/collections/IteratorUtils.java b/src/java/org/apache/commons/collections/IteratorUtils.java index e619c1fed..6d8496d38 100644 --- a/src/java/org/apache/commons/collections/IteratorUtils.java +++ b/src/java/org/apache/commons/collections/IteratorUtils.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/IteratorUtils.java,v 1.4 2002/10/12 22:15:18 scolebourne Exp $ - * $Revision: 1.4 $ - * $Date: 2002/10/12 22:15:18 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/IteratorUtils.java,v 1.5 2002/11/21 23:08:27 scolebourne Exp $ + * $Revision: 1.5 $ + * $Date: 2002/11/21 23:08:27 $ * * ==================================================================== * @@ -81,6 +81,7 @@ import org.apache.commons.collections.iterators.FilterListIterator; import org.apache.commons.collections.iterators.IteratorChain; import org.apache.commons.collections.iterators.IteratorEnumeration; import org.apache.commons.collections.iterators.ListIteratorWrapper; +import org.apache.commons.collections.iterators.LoopingIterator; import org.apache.commons.collections.iterators.SingletonIterator; import org.apache.commons.collections.iterators.SingletonListIterator; import org.apache.commons.collections.iterators.TransformIterator; @@ -90,7 +91,7 @@ import org.apache.commons.collections.iterators.TransformIterator; * org.apache.commons.collections.iterators subpackage. * * @author Stephen Colebourne - * @version $Id: IteratorUtils.java,v 1.4 2002/10/12 22:15:18 scolebourne Exp $ + * @version $Id: IteratorUtils.java,v 1.5 2002/11/21 23:08:27 scolebourne Exp $ * @since 2.1 */ public class IteratorUtils { @@ -395,6 +396,23 @@ public class IteratorUtils { return new FilterListIterator(listIterator, predicate); } + /** + * Gets an iterator that loops continuously over the supplied collection. + *

+ * The iterator will only stop looping if the remove method is called + * enough times to empty the collection, or if the collection is empty + * to start with. + * + * @param coll the collection to iterate over, not null + * @throws NullPointerException if the collection is null + */ + public static Iterator loopingIterator(Collection coll) { + if (coll == null) { + throw new NullPointerException("Collection must not be null"); + } + return new LoopingIterator(coll); + } + /** * Gets an iterator that provides an iterator view of the given enumeration. *