messif.objects.util
Class StreamsMetaObjectMapIterator

java.lang.Object
  extended by messif.objects.util.AbstractObjectIterator<E>
      extended by messif.objects.util.AbstractStreamObjectIterator<MetaObjectMap>
          extended by messif.objects.util.StreamsMetaObjectMapIterator
All Implemented Interfaces:
java.io.Closeable, java.util.Iterator<MetaObjectMap>, ObjectProvider<MetaObjectMap>

public class StreamsMetaObjectMapIterator
extends AbstractStreamObjectIterator<MetaObjectMap>

This class is to contruct MetaObjects from several simultaneously opened files (subObjectIterators). The iterator expects the files to store corresponding objects always in the same order alowing gaps - locators are always checked for actually "first" objects in the opened subObjectIterators. If more than one locator is at the top of the subObjectIterators, the majority of them is expected to be the right locator to be created at the moment and the other are not created.


Field Summary
protected  MetaObjectMap currentObject
          Instance of the current object
protected  MetaObjectMap nextObject
          Instance of a next object.
protected  boolean readingStarted
          Flag saying whether we have already started reading from the files or not yet.
protected  java.util.Map<java.lang.String,StreamGenericAbstractObjectIterator> subObjectIterators
          Particular iterators
 
Constructor Summary
StreamsMetaObjectMapIterator()
          The empty constructor.
 
Method Summary
<T extends LocalAbstractObject>
void
addObjectStream(java.lang.String name, java.lang.Class<? extends T> objClass, java.lang.String fileName)
          Add new object iterator given a name to be generated for this object in the MetaObjectMap.
 void addObjectStream(java.lang.String name, StreamGenericAbstractObjectIterator<? extends LocalAbstractObject> iterator)
          Add new object iterator given a name to be generated for this object in the MetaObjectMap.
 void close()
           
 MetaObjectMap getCurrentObject()
          Returns an object returned by the last call to Iterator.next().
 boolean hasNext()
           
 MetaObjectMap next()
           
 void remove()
           
 void reset()
          Reset the associated stream and restarts the iteration from beginning.
 void setConstructorParameter(int index, java.lang.Object paramValue)
          Sets the value of this stream's object constructor argument.
protected  void setNextObject()
          Internal method to read objects from the strems and construct new metaobject and set the new object to nextObject.
 void startReadingObjects()
          This method is internaly used to mark that the reading from the subObjectIterators started.
 
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

subObjectIterators

protected java.util.Map<java.lang.String,StreamGenericAbstractObjectIterator> subObjectIterators
Particular iterators


nextObject

protected MetaObjectMap nextObject
Instance of a next object. This is needed for implementing reading objects from a stream


currentObject

protected MetaObjectMap currentObject
Instance of the current object


readingStarted

protected boolean readingStarted
Flag saying whether we have already started reading from the files or not yet.

Constructor Detail

StreamsMetaObjectMapIterator

public StreamsMetaObjectMapIterator()
The empty constructor.

Method Detail

addObjectStream

public void addObjectStream(java.lang.String name,
                            StreamGenericAbstractObjectIterator<? extends LocalAbstractObject> iterator)
                     throws java.lang.IllegalStateException
Add new object iterator given a name to be generated for this object in the MetaObjectMap.

Parameters:
name - name to be generated for this object in the MetaObjectMap
iterator - object iterator
Throws:
java.lang.IllegalStateException - when trying to add a stream and reading from the other subObjectIterators already started

addObjectStream

public <T extends LocalAbstractObject> void addObjectStream(java.lang.String name,
                                                            java.lang.Class<? extends T> objClass,
                                                            java.lang.String fileName)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
Add new object iterator given a name to be generated for this object in the MetaObjectMap.

Type Parameters:
T - the type of the objects that are created from the file
Parameters:
name - name to be generated for this object in the MetaObjectMap
objClass - the type of the objects that are created from the file
fileName - file where the objects are stored
Throws:
java.lang.IllegalArgumentException - if the provided class does not have a proper "stream" constructor
java.io.IOException - if there was an error opening the file

getCurrentObject

public MetaObjectMap getCurrentObject()
                               throws java.util.NoSuchElementException
Description copied from class: AbstractObjectIterator
Returns an object returned by the last call to Iterator.next().

Specified by:
getCurrentObject in class AbstractObjectIterator<MetaObjectMap>
Returns:
an object returned by the last call to Iterator.next()
Throws:
java.util.NoSuchElementException - if Iterator.next() has not been called yet

hasNext

public boolean hasNext()

next

public MetaObjectMap next()

remove

public void remove()

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

startReadingObjects

public void startReadingObjects()
                         throws java.lang.IllegalStateException,
                                java.io.IOException
This method is internaly used to mark that the reading from the subObjectIterators started.

Throws:
java.lang.IllegalStateException - if there is a gap in the files and there are two candidates for the next locator
java.io.IOException - error while closing stream iterator that reached its end

setNextObject

protected void setNextObject()
                      throws java.lang.IllegalStateException,
                             java.io.IOException
Internal method to read objects from the strems and construct new metaobject and set the new object to nextObject.

Throws:
java.lang.IllegalStateException - if there is a gap in the files and there are two candidates for the next locator
java.io.IOException - error while closing stream iterator that reached its end

setConstructorParameter

public void setConstructorParameter(int index,
                                    java.lang.Object paramValue)
                             throws java.lang.IndexOutOfBoundsException,
                                    java.lang.IllegalArgumentException,
                                    java.lang.InstantiationException
Description copied from class: AbstractStreamObjectIterator
Sets the value of this stream's object constructor argument. This method can be used to change object passed to constructorArgs.

Specified by:
setConstructorParameter in class AbstractStreamObjectIterator<MetaObjectMap>
Parameters:
index - the parameter index to change (zero-based)
paramValue - the changed value to pass to the constructor
Throws:
java.lang.IndexOutOfBoundsException - if the index parameter is out of bounds (zero parameter cannot be changed)
java.lang.IllegalArgumentException - when the passed object is incompatible with the constructor's parameter
java.lang.InstantiationException - if the value passed is string that is not convertible to the constructor class

reset

public void reset()
           throws java.io.IOException
Description copied from class: AbstractStreamObjectIterator
Reset the associated stream and restarts the iteration from beginning.

Specified by:
reset in class AbstractStreamObjectIterator<MetaObjectMap>
Throws:
java.io.IOException - if there was an I/O error re-opening the file