Class MultiIterator<T>
- java.lang.Object
-
- org.clapper.util.misc.MultiIterator<T>
-
- All Implemented Interfaces:
- java.lang.Iterable<T>, java.util.Iterator<T>
public class MultiIterator<T> extends java.lang.Object implements java.util.Iterator<T>, java.lang.Iterable<T>The MultiIterator class provides a way to iterate over multiple Collection, Enumeration and Iterator objects at once. You instantiate a MultiIterator object and add one or more Collection, Enumeration or Iterator objects to it; when you use the iterator, it iterates over the contents of each contained composite object, one by one, in the order they were added to the MultiIterator. When the iterator reaches the end of one object's contents, it moves on to the next object, until no more composite objects are left.
- See Also:
Iterator,Enumeration,Collection
-
-
Constructor Summary
Constructors Constructor and Description MultiIterator()Allocate a new MultiIterator object.MultiIterator(java.util.Collection<java.util.Collection<T>> coll)Allocate a new MultiIterator object that will iterate, in turn, over the contents of each Collection in the supplied CollectionMultiIterator(java.util.Collection<T>[] array)Allocate a new MultiIterator object that will iterate, in turn, over the contents of each Collection in the supplied array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddCollection(java.util.Collection<T> collection)Add a Collection to the end of the list of composite objects being iterated over.voidaddEnumeration(java.util.Enumeration<T> enumeration)Add an Enumeration to the end of the list of composite objects being iterated over.voidaddIterator(java.util.Iterator<T> iterator)Add an Iterator to the end of the list of composite objects being iterated over.booleanhasNext()Determine whether the underlying Iterator has more elements.java.util.Iterator<T>iterator()Returns this iterator.Tnext()Get the next element from the underlying array.voidremove()Remove the object most recently extracted from the iterator.
-
-
-
Constructor Detail
-
MultiIterator
public MultiIterator()
Allocate a new MultiIterator object.
-
MultiIterator
public MultiIterator(java.util.Collection<T>[] array)
Allocate a new MultiIterator object that will iterate, in turn, over the contents of each Collection in the supplied array.- Parameters:
array- The Collections over which to iterate- See Also:
addCollection(Collection)
-
MultiIterator
public MultiIterator(java.util.Collection<java.util.Collection<T>> coll)
Allocate a new MultiIterator object that will iterate, in turn, over the contents of each Collection in the supplied Collection- Parameters:
coll- A Collection of Collection objects- See Also:
addCollection(Collection)
-
-
Method Detail
-
addCollection
public void addCollection(java.util.Collection<T> collection)
Add a Collection to the end of the list of composite objects being iterated over. It's safe to call this method while iterating, as long as you haven't reached the end of the last composite object currently in the iterator.
Note: This method is simply shorthand for:
addIterator (collection.iterator());
- Parameters:
collection- The Collection to add.- See Also:
addIterator(java.util.Iterator<T>),addEnumeration(java.util.Enumeration<T>)
-
addIterator
public void addIterator(java.util.Iterator<T> iterator)
Add an Iterator to the end of the list of composite objects being iterated over. It's safe to call this method while iterating, as long as you haven't reached the end of the last composite object currently in the iterator.- Parameters:
iterator- The Iterator to add.- See Also:
addCollection(java.util.Collection<T>),addEnumeration(java.util.Enumeration<T>)
-
addEnumeration
public void addEnumeration(java.util.Enumeration<T> enumeration)
Add an Enumeration to the end of the list of composite objects being iterated over. It's safe to call this method while iterating, as long as you haven't reached the end of the last composite object currently in the iterator.Note: This method is simply shorthand for:
addIterator (new EnumerationIterator
(enumeration)); - Parameters:
enumeration- The Enumeration to add.- See Also:
addCollection(java.util.Collection<T>),addIterator(java.util.Iterator<T>),EnumerationIterator
-
hasNext
public boolean hasNext()
Determine whether the underlying Iterator has more elements.
-
iterator
public java.util.Iterator<T> iterator()
Returns this iterator. Necessary for the Iterable interface.- Specified by:
iteratorin interfacejava.lang.Iterable<T>- Returns:
- this object
-
next
public T next() throws java.util.NoSuchElementException
Get the next element from the underlying array.- Specified by:
nextin interfacejava.util.Iterator<T>- Returns:
- the next element from the underlying array
- Throws:
java.util.NoSuchElementException- No more elements exist- See Also:
Iterator.next()
-
remove
public void remove()
Remove the object most recently extracted from the iterator. The object is removed from whatever underlying Collection is currently being traversed.- Specified by:
removein interfacejava.util.Iterator<T>
-
-
DMelt 3.0 © DataMelt by jWork.ORG