|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractList | +--java.util.ArrayList | +--edu.stanford.nlp.io.FileArrayList
A FileArrayList
maintains a collection of Files
.
It's really just an ArrayList
except that it has some
fancier constructors that traverse paths, so as to build up the
FileArrayList
.
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 either
call addAll(Collection)
or else use the constructor
FileArrayList(c, failFilt, true)
, where failFilt
is a user-supplied FileFilter
that accepts no files.
The FileArrayList
builds from these
constructor arguments a collection of Files
, which can be
iterated over, etc. Note that a FileArrayList
stores the
full expanded list of files in memory. This has the advantage
that the list can be easily modified, as per a standard collection,
but the disadvantage that it may take up a lot of space.
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:
FileArrayList
from an array of
Files
or Strings
arr
:FileArrayList fcollect = new FileArrayList(Arrays.asList(arr));
FileArrayList
from a single
File
or String
fi
:FileArrayList fcollect =
new FileArrayList(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 Constructor).
FileSequentialCollection
,
Serialized FormField Summary |
Fields inherited from class java.util.AbstractList |
modCount |
Constructor Summary | |
FileArrayList()
Creates an empty FileArrayList , with no Files in it. |
|
FileArrayList(Collection c)
Creates a FileArrayList from the passed in
Collection . |
|
FileArrayList(Collection c,
FileFilter filt)
Creates a FileArrayList from the passed in
Collection . |
|
FileArrayList(Collection c,
FileFilter filt,
boolean includeDirs)
Creates a FileArrayList from the passed in
Collection . |
|
FileArrayList(Collection c,
String suffix,
boolean recursively)
Creates a FileArrayList from the passed in
Collection . |
|
FileArrayList(File path,
String suffix,
boolean recursively)
Creates a FileArrayList from the passed in
File path. |
Method Summary | |
static void |
main(String[] args)
This is simply a debugging aid that tests the functionality of the class. |
Methods inherited from class java.util.ArrayList |
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, removeRange, set, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
containsAll, remove, removeAll, retainAll, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList |
Constructor Detail |
public FileArrayList()
FileArrayList
, with no Files in it.
public FileArrayList(Collection c)
FileArrayList
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 FileArrayList
frompublic FileArrayList(File path, String suffix, boolean recursively)
FileArrayList
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 wellpublic FileArrayList(Collection c, String suffix, boolean recursively)
FileArrayList
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.
Note that if a collection member is a directory, this code
will always look at the members of this directory. This
variable controls whether subdirectories fo the directory are
examined.public FileArrayList(Collection c, FileFilter filt)
FileArrayList
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 path
is 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 FileArrayList(Collection c, FileFilter filt, boolean includeDirs)
FileArrayList
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 path
is 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 accepted.includeDirs
- Whether to include director names in the file listMethod Detail |
public static void main(String[] args)
Collection
, and passed to the
FileArrayList
constructor. An iterator is then used
to print the names of all the files 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 |