All Packages Class Hierarchy This Package Previous Next Index
Class kmy.util.match.FileMatchingPattern
kmy.util.match.FileMatchingPattern
- public class FileMatchingPattern
This class defines a file matching pattern as in UNIX csh
command interpreter with some exceptions. The pattern can
be represented as string and normally contains some of the
special matching constructs:
- *
- matches any (perhaps empty) sequence of characters
- /
- matches any single character
- [charset]
- charset should be a sequence of characters
or character ranges (for example a-z represents al lowercase
letters). Character ^ appearing in the beginning
of charset reverses its meaning.
A pattern may contain arbitrarily nested folders, for example
java/n*t/S*.java . The differences between this class and csh
file substitution are the following:
- csh requires leading . to be matched explicitly, this
implementation does not.
- csh allowes matching for the special files . and .. , but
this implementation will never match them.
- csh does username substitution, this class does not. This
can be implemented by pattern preprocessing.
- csh expands constructs like {a,b}c into list ac bc, this
class only provides a means to implement this feature as
pattern preprocessing (see expand).
- no sorting of output is performed.
- there might be some othe differences (or bugs) that I
overlooked.
Normally one just creates FileMatchingPattern using its constructor
and then calls method list. If you want to implement {} constructs
you have to call static method expand to to pattern preprocessing
and then create FileMatchingPattern for every string in the array
it returns. You also might want to perform ~user construct
substitution in between.
-
FileMatchingPattern(String)
- Constructor allows one to create FileMatchingPattern from
a String that is normally used to represent it.
-
expand(String)
- Expands {} constructs.
-
list(File, Vector)
- Produce a list of files that match this pattern.
FileMatchingPattern
public FileMatchingPattern(String pattern)
- Constructor allows one to create FileMatchingPattern from
a String that is normally used to represent it. Note that
it works with / as a file separator, not File.separator.
list
public void list(File dir,
Vector flist)
- Produce a list of files that match this pattern. Matching
files will be added to a vector flist.
- Parameters:
- dir - first argument is a reference path
that is needed only for non-absolute patterns.
Absolute patterns may pass null here.
- flist - a vector to accumulate matching files
expand
public static String[] expand(String patt)
- Expands {} constructs. For example {a,b}c becomes ac bc, or
{a{b,c},d}{e,f} becomes abe abf ace acf de df.
All Packages Class Hierarchy This Package Previous Next Index