messif.objects.util
Class ObjectProvidersIterator<E extends AbstractObject>

java.lang.Object
  extended by messif.objects.util.AbstractObjectIterator<E>
      extended by messif.objects.util.ObjectProvidersIterator<E>
Type Parameters:
E - the class of the iterated objects
All Implemented Interfaces:
java.util.Iterator<E>, ObjectProvider<E>

public class ObjectProvidersIterator<E extends AbstractObject>
extends AbstractObjectIterator<E>

This class allows iterating over multiple ObjectProviders. Providers are accessed in the same order as they were passed in the collection. If actualy iterated provider has no next object, next provider (that has object) is selected until whole list of providers is scanned.


Field Summary
protected  AbstractObjectIterator<? extends E> currentIterator
          Iterator from current provider
protected  E currentObject
          Stored instance of object returned by the last call to next()
protected  java.util.Queue<ObjectProvider<? extends E>> providers
          Queue of providers that are waiting to be scanned
 
Constructor Summary
ObjectProvidersIterator(java.util.Collection<ObjectProvider<? extends E>> objectProviders)
          Creates a new instance of ObjectProvidersIterator
 
Method Summary
 E getCurrentObject()
          Returns an instance of object returned by the last call to next().
 boolean hasNext()
          Returns true if the iteration has more elements.
 E next()
          Returns the next element in the iteration.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (optional operation).
 
Methods inherited from class messif.objects.util.AbstractObjectIterator
getCurrentObjectID, getMatchingObjects, getMatchingObjects, getMatchingObjects, getMatchingObjects, getObjectByAnyLocator, getObjectByData, getObjectByID, getObjectByLocator, getObjectByPosition, getRandomObject, getRandomObjects, nextObjectID, provideObjects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

providers

protected final java.util.Queue<ObjectProvider<? extends E extends AbstractObject>> providers
Queue of providers that are waiting to be scanned


currentIterator

protected AbstractObjectIterator<? extends E extends AbstractObject> currentIterator
Iterator from current provider


currentObject

protected E extends AbstractObject currentObject
Stored instance of object returned by the last call to next()

Constructor Detail

ObjectProvidersIterator

public ObjectProvidersIterator(java.util.Collection<ObjectProvider<? extends E>> objectProviders)
Creates a new instance of ObjectProvidersIterator

Parameters:
objectProviders - The source ObjectProviders that will provide objects
Method Detail

getCurrentObject

public E getCurrentObject()
                                          throws java.util.NoSuchElementException
Returns an instance of object returned by the last call to next().

Specified by:
getCurrentObject in class AbstractObjectIterator<E extends AbstractObject>
Returns:
Returns an instance of object returned by the last call to next()
Throws:
java.util.NoSuchElementException - Exception NoSuchElementException is thrown if next() has not been called yet.

hasNext

public boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:
true if the iterator has more elements.

next

public E next()
                              throws java.util.NoSuchElementException
Returns the next element in the iteration.

Returns:
the next element in the iteration.
Throws:
java.util.NoSuchElementException - iteration has no more elements.

remove

public void remove()
            throws java.lang.UnsupportedOperationException,
                   java.lang.IllegalStateException
Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
java.lang.UnsupportedOperationException - if the remove operation is not supported by this Iterator.
java.lang.IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.