|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.objects.util.AbstractObjectIterator<E>
messif.objects.util.AbstractStreamObjectIterator<E>
messif.objects.util.StreamGenericAbstractObjectIterator<E>
E
- the class of objects provided by this stream iterator (must be descendant of LocalAbstractObject
)public class StreamGenericAbstractObjectIterator<E extends LocalAbstractObject>
This class represents an iterator on LocalAbstractObject
s that are read from a file.
The objects are instantiated one by one every time the next
method is called.
The file should be created using LocalAbstractObject.write(java.io.OutputStream)
method.
Field Summary | |
---|---|
protected java.lang.reflect.Constructor<? extends E> |
constructor
Class instance of objects of type E needed for instantiating objects read from a stream |
protected java.lang.Object[] |
constructorArgs
Arguments for the constructor (first will always be the stream) |
protected E |
currentObject
Instance of the current object |
protected java.lang.String |
fileName
Remembered name of opened file to provide reset capability |
protected E |
nextObject
Instance of a next object. |
protected int |
objectsRead
Number of objects read from the stream |
protected java.io.BufferedReader |
stream
An input stream for reading objects of this iterator from |
Constructor Summary | |
---|---|
StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass,
java.io.BufferedReader stream)
Creates a new instance of StreamGenericAbstractObjectIterator. |
|
StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass,
java.io.BufferedReader stream,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.util.Collection<?> constructorArgs)
Creates a new instance of StreamGenericAbstractObjectIterator. |
|
StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass,
java.lang.String fileName)
Creates a new instance of StreamGenericAbstractObjectIterator. |
|
StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass,
java.lang.String fileName,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.util.Collection<?> constructorArgs)
Creates a new instance of StreamGenericAbstractObjectIterator. |
|
StreamGenericAbstractObjectIterator(java.lang.reflect.Constructor<? extends E> constructor,
java.lang.Object[] constructorArgs)
Creates a new instance of StreamGenericAbstractObjectIterator. |
Method Summary | |
---|---|
void |
close()
Close the associated stream. |
E |
getCurrentObject()
Returns an instance of object returned by the last call to next(). |
java.lang.String |
getFileName()
Returns the name of the file opened by this stream. |
boolean |
hasNext()
Returns true if the iteration has more elements. |
E |
next()
Returns the next object instance from the stream. |
protected E |
nextStreamObject()
Returns an instance of object which would be returned by next call to next(). |
void |
remove()
Removes from the underlying collection the last element returned by the iterator. |
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. |
java.lang.String |
toString()
|
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, wait, wait, wait |
Field Detail |
---|
protected java.io.BufferedReader stream
protected java.lang.String fileName
protected E extends LocalAbstractObject nextObject
protected E extends LocalAbstractObject currentObject
protected int objectsRead
protected final java.lang.reflect.Constructor<? extends E extends LocalAbstractObject> constructor
protected final java.lang.Object[] constructorArgs
Constructor Detail |
---|
public StreamGenericAbstractObjectIterator(java.lang.reflect.Constructor<? extends E> constructor, java.lang.Object[] constructorArgs)
BufferedReader
.
constructor
- the constructor used to create instances of objects in this streamconstructorArgs
- constructor argumentspublic StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass, java.io.BufferedReader stream, java.util.Map<java.lang.String,java.lang.Object> namedInstances, java.util.Collection<?> constructorArgs) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
objClass
that acceps BufferedReader
as the first argument and all the arguments from the constructorArgs
is used to read objects from the stream.
objClass
- the class used to create the instances of objects in this streamstream
- stream from which objects are read and instantiatednamedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the mapconstructorArgs
- additional constructor arguments
java.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructor
java.lang.IllegalStateException
- if there was an error reading from the streampublic StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass, java.lang.String fileName, java.util.Map<java.lang.String,java.lang.Object> namedInstances, java.util.Collection<?> constructorArgs) throws java.lang.IllegalArgumentException, java.io.IOException
fileName
is empty, null or dash, standard input is used.
objClass
- the class used to create the instances of objects in this streamfileName
- the path to a file from which objects are read;
if it is a directory, all files that match the glob pattern are loaded
(see DirectoryInputStream
for more informations)namedInstances
- map of named instances - an instance from this map is returned if the string
matches a key in the mapconstructorArgs
- additional constructor arguments
java.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructor
java.io.IOException
- if there was an error opening the filepublic StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass, java.lang.String fileName) throws java.lang.IllegalArgumentException, java.io.IOException
fileName
is empty, null or dash, standard input is used.
objClass
- the class used to create the instances of objects in this streamfileName
- the path to a file from which objects are read
java.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructor
java.io.IOException
- if there was an error opening the filepublic StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass, java.io.BufferedReader stream) throws java.lang.IllegalArgumentException
objClass
- the class used to create the instances of objects in this streamstream
- stream from which objects are read and instantiated
java.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorMethod Detail |
---|
public void setConstructorParameter(int index, java.lang.Object paramValue) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException, java.lang.InstantiationException
constructorArgs
.
setConstructorParameter
in class AbstractStreamObjectIterator<E extends LocalAbstractObject>
index
- the parameter index to change (zero-based)paramValue
- the changed value to pass to the constructor
java.lang.IllegalArgumentException
- when the passed object is incompatible with the constructor's parameter
java.lang.IndexOutOfBoundsException
- if the index parameter is out of bounds (zero parameter cannot be changed)
java.lang.InstantiationException
- if the value passed is string that is not convertible to the constructor classpublic java.lang.String getFileName()
public java.lang.String toString()
toString
in class java.lang.Object
public E next() throws java.util.NoSuchElementException, java.lang.IllegalArgumentException, java.lang.IllegalStateException
java.util.NoSuchElementException
- if the end-of-file was reached
java.lang.IllegalArgumentException
- if there was an error creating a new instance of the object
java.lang.IllegalStateException
- if there was an error reading from the streampublic E getCurrentObject() throws java.util.NoSuchElementException
getCurrentObject
in class AbstractObjectIterator<E extends LocalAbstractObject>
java.util.NoSuchElementException
- if next()
has not been called yetpublic boolean hasNext()
public void remove()
protected E nextStreamObject() throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
java.lang.IllegalArgumentException
- if there was an error creating a new instance of the object
java.lang.IllegalStateException
- if there was an error reading from the streampublic void close() throws java.io.IOException
java.io.IOException
- if there was an I/O error closing the filepublic void reset() throws java.io.IOException
reset
in class AbstractStreamObjectIterator<E extends LocalAbstractObject>
java.io.IOException
- if there was an I/O error re-opening the file
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |