E
- the class of objects provided by this stream iterator (must be descendant of LocalAbstractObject
)public class StreamGenericAbstractObjectIterator<E extends LocalAbstractObject> extends AbstractStreamObjectIterator<E>
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.Modifier and Type | Field and Description |
---|---|
protected E |
currentObject
Instance of the current object
|
protected LocalAbstractObject.TextStreamFactory<? extends E> |
factory
Factory for instantiating objects read from a stream
|
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 and Description |
---|
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.io.BufferedReader stream,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.lang.Object... 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.Class<? extends E> objClass,
java.lang.String fileName,
java.util.Map<java.lang.String,java.lang.Object> namedInstances,
java.lang.Object... constructorArgs)
Creates a new instance of StreamGenericAbstractObjectIterator.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
setConstructorParameterFromString(int index,
java.lang.String paramValue,
java.util.Map<java.lang.String,java.lang.Object> namedInstances)
Sets the value of this stream's object constructor argument from a string value.
|
java.lang.String |
toString() |
emptyIterator, getIterator, getMatchingObjects, getMatchingObjects, getMatchingObjects, getMatchingObjects, getObjectByAnyLocator, getObjectByData, getObjectByLocator, getObjectByLocator, getObjectByLocatorRegexp, getObjectByPosition, getRandomObject, getRandomObjects, provideObjects, singleton, skip
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 LocalAbstractObject.TextStreamFactory<? extends E extends LocalAbstractObject> factory
public StreamGenericAbstractObjectIterator(java.lang.Class<? extends E> objClass, java.io.BufferedReader stream, java.util.Map<java.lang.String,java.lang.Object> namedInstances, java.lang.Object... constructorArgs) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
objClass
that accepts 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 argumentsjava.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorjava.lang.IllegalStateException
- if there was an error reading from the streampublic 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 argumentsjava.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorjava.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.lang.Object... 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 argumentsjava.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorjava.io.IOException
- if there was an error opening the filepublic 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 argumentsjava.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorjava.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 readjava.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorjava.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 instantiatedjava.lang.IllegalArgumentException
- if the provided class does not have a proper "stream" constructorpublic void setConstructorParameter(int index, java.lang.Object paramValue) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
AbstractStreamObjectIterator
constructorArgs
.setConstructorParameter
in class AbstractStreamObjectIterator<E extends LocalAbstractObject>
index
- the parameter index to change (zero-based)paramValue
- the changed value to pass to the constructorjava.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 parameterpublic void setConstructorParameterFromString(int index, java.lang.String paramValue, java.util.Map<java.lang.String,java.lang.Object> namedInstances) throws java.lang.IndexOutOfBoundsException, java.lang.InstantiationException
AbstractStreamObjectIterator
constructorArgs
.setConstructorParameterFromString
in class AbstractStreamObjectIterator<E extends LocalAbstractObject>
index
- the parameter index to change (zero-based)paramValue
- the changed value to pass to the constructornamedInstances
- map of named instances for the Convert.stringToType(java.lang.String, java.lang.Class<E>, java.util.Map<java.lang.String, ? extends java.lang.Object>)
conversionjava.lang.IndexOutOfBoundsException
- if the index parameter is out of boundsjava.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 reachedjava.lang.IllegalArgumentException
- if there was an error creating a new instance of the objectjava.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 final E nextStreamObject() throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
java.lang.IllegalArgumentException
- if there was an error creating a new instance of the objectjava.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