MultiIterator
org.clapper.util.misc

Class MultiIterator<T>

  • All Implemented Interfaces:
    Iterable<T>, Iterator<T>


    public class MultiIterator<T>extends Objectimplements Iterator<T>, 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(Collection<Collection<T>> coll)
      Allocate a new MultiIterator object that will iterate, in turn, over the contents of each Collection in the supplied Collection
      MultiIterator(Collection<T>[] array)
      Allocate a new MultiIterator object that will iterate, in turn, over the contents of each Collection in the supplied array.
    • Constructor Detail

      • MultiIterator

        public MultiIterator()
        Allocate a new MultiIterator object.
      • MultiIterator

        public MultiIterator(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(Collection<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(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>)
      • addEnumeration

        public void addEnumeration(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.
        Specified by:
        hasNext in interface Iterator<T>
        Returns:
        true if and only if a call to nextElement() will return an element, false otherwise.
        See Also:
        next()
      • iterator

        public Iterator<T> iterator()
        Returns this iterator. Necessary for the Iterable interface.
        Specified by:
        iterator in interface Iterable<T>
        Returns:
        this object
      • 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:
        remove in interface Iterator<T>

SCaVis 2.0 © jWork.ORG