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.
Iterator
,
Enumeration
,
Collection
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
Collection
|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addCollection(java.util.Collection<T> collection)
Add a Collection to the end of the list of composite
objects being iterated over.
|
void |
addEnumeration(java.util.Enumeration<T> enumeration)
Add an Enumeration to the end of the list of composite
objects being iterated over.
|
void |
addIterator(java.util.Iterator<T> iterator)
Add an Iterator to the end of the list of composite objects
being iterated over.
|
boolean |
hasNext()
Determine whether the underlying Iterator has more
elements.
|
java.util.Iterator<T> |
iterator()
Returns this iterator.
|
T |
next()
Get the next element from the underlying array.
|
void |
remove()
Remove the object most recently extracted from the iterator.
|
public MultiIterator()
public MultiIterator(java.util.Collection<T>[] array)
array
- The Collections over which to iterateaddCollection(Collection)
public MultiIterator(java.util.Collection<java.util.Collection<T>> coll)
coll
- A Collection of Collection objectsaddCollection(Collection)
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());
collection
- The Collection to add.addIterator(java.util.Iterator<T>)
,
addEnumeration(java.util.Enumeration<T>)
public void addIterator(java.util.Iterator<T> iterator)
iterator
- The Iterator to add.addCollection(java.util.Collection<T>)
,
addEnumeration(java.util.Enumeration<T>)
public void addEnumeration(java.util.Enumeration<T> enumeration)
Note: This method is simply shorthand for:
addIterator (new EnumerationIterator<T> (enumeration));
enumeration
- The Enumeration to add.addCollection(java.util.Collection<T>)
,
addIterator(java.util.Iterator<T>)
,
EnumerationIterator
public boolean hasNext()
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public T next() throws java.util.NoSuchElementException
next
in interface java.util.Iterator<T>
java.util.NoSuchElementException
- No more elements existIterator.next()
public void remove()
remove
in interface java.util.Iterator<T>