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:
- To make a
FileSequentialCollection
from an array of Files
or Strings
arr
:
FileSequentialCollection fcollect = new FileSequentialCollection(Arrays.asList(arr));
- To make a
FileSequentialCollection
from a single File
or String
fi:
FileSequentialCollection fcollect = new FileSequentialCollection(Collections.singletonList(fi));
This class will throw an
IllegalArgumentException
if there are things that are not existing Files or String paths to existing files in the input collection (from the Iterator).
@author Christopher Manning
@version 1.0, August 2002
@see FileArrayList