Package com.day.util

Class CompoundIterator

java.lang.Object
com.day.util.CompoundIterator
All Implemented Interfaces:
Iterator

public class CompoundIterator extends Object implements Iterator
Implements the Iterator interface and combines two Iterator objects into one single Iterator.

The constructor takes two Iterator arguments: parent and child. Calling next() on this Iterator will first try to return an element from the parent Iterator and once the parent Iterator does not have any more elements it will return elements from the child Iterator.

Since:
fennec Audience wad
  • Constructor Details

    • CompoundIterator

      public CompoundIterator(Iterator parent, Iterator child)
      Creates a CompoundIterator based on parent and child. This CompountIterator will first return elements from parent and then elements from child.
      Parameters:
      parent - the Iterator from where to return the elements first.
      child - the Iterator from where to return the elements after parent does not have elements any more.
  • Method Details

    • hasNext

      public boolean hasNext()
      Returns true if either parent or child iterator has a next element; false otherwise.
      Specified by:
      hasNext in interface Iterator
      Returns:
      true if either parent or child iterator has a next element; false otherwise.
    • next

      public Object next()
      Returns the next element from the parent or the child iterator object.
      Specified by:
      next in interface Iterator
      Returns:
      the next element from the parent or the child iterator object.
    • remove

      public void remove() throws UnsupportedOperationException
      Always throws UnsupportedOperationException
      Specified by:
      remove in interface Iterator
      Throws:
      UnsupportedOperationException - always!