edu.stanford.nlp.objectbank
Class ReaderIteratorFactory

java.lang.Object
  extended by edu.stanford.nlp.objectbank.ReaderIteratorFactory
All Implemented Interfaces:
java.lang.Iterable<java.io.Reader>

public class ReaderIteratorFactory
extends java.lang.Object
implements java.lang.Iterable<java.io.Reader>

A ReaderIteratorFactory provides a means of getting an Iterator which returns java.util.Readers over a Collection of input sources. Currently supported input sources are: Files, Strings, URLs and Readers. A ReaderIteratorFactory may take a Collection on construction and new sources may be added either individually (via the add(Object) method) or as a Collection (via the addAll(Collection method). The implementation automatically determines the type of input and produces a java.util.Reader accordingly. If you wish to add support for a new kind of input, refer the the setNextObject() method of the nested class ReaderIterator.

The Readers returned by this class are not closed by the class when you move to the next element (nor at any other time). So, if you want the files closed, then the caller needs to close them. The caller can only do this if they pass in Readers. Otherwise, this class should probably close them but currently doesn't.

TODO: Have this class close the files that it opens.

Author:
Jenny Finkel

Field Summary
protected  java.util.Collection<java.lang.Object> c
          The underlying Collection of input sources.
protected  java.lang.String enc
          The encoding for file input.
 
Constructor Summary
ReaderIteratorFactory()
           
ReaderIteratorFactory(java.util.Collection<?> c)
          Constructs a ReaderIteratorFactory from the input sources contained in the Collection.
ReaderIteratorFactory(java.util.Collection<?> c, java.lang.String encoding)
           
ReaderIteratorFactory(java.lang.Object o)
          Convenience constructor to construct a ReaderIteratorFactory from a single input source.
ReaderIteratorFactory(java.lang.Object o, java.lang.String encoding)
           
 
Method Summary
 boolean add(java.lang.Object o)
          Adds an Object to the underlying Collection of input sources.
 boolean addAll(java.util.Collection<?> c)
          Adds all Objects in Collection c to the underlying Collection of input sources.
 java.util.Iterator<java.io.Reader> iterator()
          Returns an Iterator over the input sources in the underlying Collection.
 boolean remove(java.lang.Object o)
          Removes an Object from the underlying Collection of input sources.
 boolean removeAll(java.util.Collection<?> c)
          Removes all Objects in Collection c from the underlying Collection of input sources.
 boolean retainAll(java.util.Collection<?> c)
          Removes all Objects from the underlying Collection of input sources except those in Collection c
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

c

protected java.util.Collection<java.lang.Object> c
The underlying Collection of input sources. Currently supported input sources are: Files, Strings, URLs and Readers. The implementation automatically determines the type of input and produces a java.util.Reader accordingly.


enc

protected java.lang.String enc
The encoding for file input. This is defaulted to "utf-8" only applies when c is of type File .

Constructor Detail

ReaderIteratorFactory

public ReaderIteratorFactory(java.util.Collection<?> c)
Constructs a ReaderIteratorFactory from the input sources contained in the Collection. The Collection should contain Objects of type File, String, URL and Reader. See class description for details.

Parameters:
c - Collection of input sources.

ReaderIteratorFactory

public ReaderIteratorFactory(java.util.Collection<?> c,
                             java.lang.String encoding)

ReaderIteratorFactory

public ReaderIteratorFactory(java.lang.Object o)
Convenience constructor to construct a ReaderIteratorFactory from a single input source. The Object should be of type File, String, URL and Reader. See class description for details.

Parameters:
o - an input source that can be converted into a Reader

ReaderIteratorFactory

public ReaderIteratorFactory(java.lang.Object o,
                             java.lang.String encoding)

ReaderIteratorFactory

public ReaderIteratorFactory()
Method Detail

iterator

public java.util.Iterator<java.io.Reader> iterator()
Returns an Iterator over the input sources in the underlying Collection.

Specified by:
iterator in interface java.lang.Iterable<java.io.Reader>
Returns:
an Iterator over the input sources in the underlying Collection.

add

public boolean add(java.lang.Object o)
Adds an Object to the underlying Collection of input sources.

Parameters:
o - Input source to be added to the underlying Collection.

remove

public boolean remove(java.lang.Object o)
Removes an Object from the underlying Collection of input sources.

Parameters:
o - Input source to be removed from the underlying Collection.

addAll

public boolean addAll(java.util.Collection<?> c)
Adds all Objects in Collection c to the underlying Collection of input sources.

Parameters:
c - Collection of input sources to be added to the underlying Collection.

removeAll

public boolean removeAll(java.util.Collection<?> c)
Removes all Objects in Collection c from the underlying Collection of input sources.

Parameters:
c - Collection of input sources to be removed from the underlying Collection.

retainAll

public boolean retainAll(java.util.Collection<?> c)
Removes all Objects from the underlying Collection of input sources except those in Collection c

Parameters:
c - Collection of input sources to be retained in the underlying Collection.


Stanford NLP Group