|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.util.AbstractCollection
|
+--edu.stanford.nlp.io.FileSequentialCollection
A FileSequentialCollection maintains a read-only
collection of Files. (It's a list, but we don't
make it a List or else one needs an iterator that can go backwards.)
It is built from a Collection of paths, or just from a single path.
Optionally one can also provide a FileFilter which is
applied over the files in a recursive traversal, or else
an extension and whether to do recursive traversal, which are used to
construct a filter.
Note that the Collection argument constructor will behave 'normally'
iff none of the Collection elements are directories. If they are
directories they will be recursed and files in them added. To get the
behavior of putting just directories in the collection one needs to
use the constructor
FileSequentialCollection(c, failFilt, true),
where failFilt
is a user-supplied FileFilter that accepts no files.
The FileSequentialCollection builds from these
constructor arguments a collection of Files, which can be
iterated over, etc. This class does runtime expansion of paths.
That is, it is optimized for iteration and not for random access.
It is also an unmodifiable Collection.
The class provides some additional constructors beyond the two recommended
by the Collections package, to allow specifying a FileFilter
and similar options. Nevertheless, so as to avoid overburdening the
the API, not every possibly useful constructor has been provided where
these can be easily synthesized using standard Collections package
facilities. Useful idioms to know are:
FileSequentialCollection from an array of
Files or Strings arr:FileSequentialCollection fcollect = new FileSequentialCollection(Arrays.asList(arr));
FileSequentialCollection from a single
File or String fi:FileSequentialCollection fcollect =
new FileSequentialCollection(Collections.singletonList(fi));IllegalArgumentException if there
are things that are not existing Files or String paths to existing files
in the input collection (from the Iterator).
FileArrayList| Constructor Summary | |
FileSequentialCollection()
Creates an empty FileSequentialCollection, with no Files
in it. |
|
FileSequentialCollection(Collection c)
Creates a FileSequentialCollection from the passed in
Collection. |
|
FileSequentialCollection(Collection c,
FileFilter filt)
Creates a FileSequentialCollection from the passed in
Collection. |
|
FileSequentialCollection(Collection c,
FileFilter filt,
boolean includeDirs)
Creates a FileSequentialCollection from the passed in
Collection. |
|
FileSequentialCollection(Collection c,
String suffix,
boolean recursively)
Creates a FileSequentialCollection from the passed in
Collection. |
|
FileSequentialCollection(File path,
String suffix,
boolean recursively)
Creates a FileSequentialCollection from the passed in
File path. |
|
| Method Summary | |
Iterator |
iterator()
Return an Iterator over files in the collection. |
static void |
main(String[] args)
This is simply a debugging aid that tests the functionality of the class. |
int |
size()
Returns the size of the FileSequentialCollection. |
| Methods inherited from class java.util.AbstractCollection |
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
equals, hashCode |
| Constructor Detail |
public FileSequentialCollection()
FileSequentialCollection, with no Files
in it. Since a FileSequentialCollection is not
modifiable, this is
largely useless (except if you want an empty one).
public FileSequentialCollection(Collection c)
FileSequentialCollection from the passed in
Collection. The constructor iterates through the
collection. For each element, if it is a File or
String, then this file path is traversed for addition
to the collection. If the argument is of some other type, an
IllegalArgumentException is thrown.
For each File or String, if they
do not correspond to directories, then they are added to the
collection; if they do, they are recursively explored and all
non-directories within them are added to the collection.
c - The collection to build the
FileSequentialCollection from
public FileSequentialCollection(File path,
String suffix,
boolean recursively)
FileSequentialCollection from the passed in
File path. If the File
does not correspond to a directory, then it is added to the
collection; if it does, it is explored. Files
that match the extension, and files in subfolders that match, if
appropriate, are added to the collection.
This is an additional convenience constructor.
path - file or directory to load fromsuffix - suffix (normally "File extension") of files to loadrecursively - true means descend into subdirectories as well
public FileSequentialCollection(Collection c,
String suffix,
boolean recursively)
FileSequentialCollection from the passed in
Collection. The constructor iterates through the
collection. For each element, if it is a File, then the
File is added to the collection, if it is a
String, then a File corresponding to this
String as a file path is added to the collection, and
if the argument is of some other type, an
IllegalArgumentException is thrown. For the files
thus specified, they are included in the collection only if they
match an extension filter as specified by the other arguments.
c - Collection of files or directories as Files or Stringssuffix - suffix (normally "File extension") of files to loadrecursively - true means descend into subdirectories as well
public FileSequentialCollection(Collection c,
FileFilter filt)
FileSequentialCollection from the passed in
Collection. The constructor iterates through the
collection. For each element, if it is a File or
String then these file paths are processed as
explained below.
If the argument is of some other type, an
IllegalArgumentException is thrown. For the files
specified, if they are not directories, they are included in the
collection. If they are directories, files inside them are
included iff they match the FileFilter. This will
include recursive directory descent iff the FileFilter
accepts directories.
If the path is a directory then only
files within the directory (perhaps recursively) that satisfy the
filter are processed. If the pathis a file, then
that file is processed regardless of whether it satisfies the
filter. (This semantics was adopted, since otherwise there was no
easy way to go through all the files in a directory without
descending recursively via the specification of a
FileFilter.)
c - The collection of file or directory to load fromfilt - A FileFilter of files to load. This may be
null, in which case all files are accepted.
public FileSequentialCollection(Collection c,
FileFilter filt,
boolean includeDirs)
FileSequentialCollection from the passed in
Collection. The constructor iterates through the
collection. For each element, if it is a File or
String then these file paths are processed as
explained below.
If the argument is of some other type, an
IllegalArgumentException is thrown. For the files
specified, if they are not directories, they are included in the
collection. If they are directories, files inside them are
included iff they match the FileFilter. This will
include recursive directory descent iff the FileFilter
accepts directories.
If the path is a directory then only
files within the directory (perhaps recursively) that satisfy the
filter are processed. If the pathis a file, then
that file is processed regardless of whether it satisfies the
filter. (This semantics was adopted, since otherwise there was no
easy way to go through all the files in a directory without
descending recursively via the specification of a
FileFilter.)
c - The collection of file or directory to load from. An
argument of null is interpreted like an
empty collection.filt - A FileFilter of files to load. This may be
null, in which case all files are acceptedincludeDirs - Whether to include director names in the file list| Method Detail |
public int size()
size in interface Collectionsize in class AbstractCollectionpublic Iterator iterator()
iterator in interface Collectioniterator in class AbstractCollectionpublic static void main(String[] args)
Collection, and passed to the
FileSequentialCollection constructor.
An iterator is then used to print the names of all the files
(but not directories) in the collection.
args - A list of file paths
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||