org.osesb.utilities.fileio
Class PathSpecifier

java.lang.Object
  extended by org.osesb.utilities.fileio.PathSpecifier

public class PathSpecifier
extends java.lang.Object

Path name specifier. Allows patterns at each level of the path. For example: j*.s* matches java.encryption and javax.swing. A final * character matches all sub-packages. So java.awt.* matches all subpackages of java.awt.

Note:
To keep from recognizing subpackages, specify "?*" as the last entry. The "?" is intended to reflect its usual meaning as "any character". Although the "?" pattern is not recognized in general, it's use here serves to distinguish "all subdirectories" (*) from "all directories at this level (?*).
Here is the table of options for processing various combinations of packages from the swing hierarchy:
            swing
              |
          +---+---+
        table    text
                   |
                  html
 
javax.swing
The swing package only.
javax.swing.*
The swing package and all sub packages: table, text, and text.html.
javax.swing.*.*
All sub packages of swing, not including swing itself and all their subs, recursively: table, text, table.html.
javax.swing.?*
Direct descendants of swing, not including subpackages and not including swing itself: table, text.
javax.swing + javax.swing.?*
The swing package and any direct descendants.
By default, paths are assumed to be separated by the default seperator character for the current system ("/" for Unix, "\" for DOS). The path separator can also be specified, both when creating the specifier and when invoking the match(String, String) function. That allows a package-specifier to be created with a dot-separator, for example, and yet be successfully compared to a file system pathname.

Note:
A null pattern matches everything. The match(java.lang.String) function always returns true. However, when a null string, is compared to any pattern, the null string always returns false. (A null string matches nothing.) When a null string is compared to a null pattern, the result is false. (The null string takes precedence.)

See Also:
Specifier, FileSpecifier

Field Summary
protected  boolean openEnded
          Set true when the pattern to match ends with "*", as in "java.awt.*".
protected  java.util.LinkedList patternList
           
 
Constructor Summary
PathSpecifier(java.util.List pList)
          Create a specifier using a pre-separated list of directory-name patterns.
PathSpecifier(java.util.List pList, java.lang.String aSeparator)
          Create a specifier using a pre-separated list of directory-name patterns, plus the separator that was used to split them apart (for use when gluing them back together with toString().
PathSpecifier(java.lang.String pattern)
          Create a specifier using the default directory-seperator for the current system, where the separator is used to divide the input string into directory-name patterns.
PathSpecifier(java.lang.String s, java.lang.String aSeparator)
          Create a specifier using the specified directory-seperator, where the separator is used to divide the input string into directory-name patterns.
 
Method Summary
protected  void initPatternList(java.util.List pList)
          Initialize the list of path patterns
 boolean match(java.util.List testList)
          Check the list of path-elements to see if it matches this specifier.
 boolean match(java.lang.String s)
          Check the string argument to see if it matches this specifier, where the default directory-seperator for the current system is used to divide the input string into directory-name segments.
 boolean match(java.lang.String path, java.lang.String separator)
          Check the string argument to see if it matches this specifier, where the specified seperator is used to divide the input string into directory-name segments.
static java.util.LinkedList parsePath(java.lang.String path)
          Divide the string argument into directory-name patterns using the default directory-seperator for the current system.
static java.util.LinkedList parsePath(java.lang.String path, java.lang.String aSeparator)
          Divide the string argument into directory-name patterns using the specified directory-seperator.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

patternList

protected java.util.LinkedList patternList

openEnded

protected boolean openEnded
Set true when the pattern to match ends with "*", as in "java.awt.*".

Constructor Detail

PathSpecifier

public PathSpecifier(java.lang.String pattern)
Create a specifier using the default directory-seperator for the current system, where the separator is used to divide the input string into directory-name patterns.

Parameters:
pattern - the pattern to match (ex: j*\s*), where a null pattern or empty string matches everything

PathSpecifier

public PathSpecifier(java.lang.String s,
                     java.lang.String aSeparator)
Create a specifier using the specified directory-seperator, where the separator is used to divide the input string into directory-name patterns.

Note:
The separator is assumed to contain a single character, although it could also contain multiple characters, each of which acts as a separator. On no account can it contain multiple characters which act as a single separator.

Parameters:
s - the pattern to match (ex: j*\s*), where a null pattern or empty string matches everything
aSeparator - the directory-name separator -- "/" for Unix, "\" for DOS, "." for packages.

PathSpecifier

public PathSpecifier(java.util.List pList)
Create a specifier using a pre-separated list of directory-name patterns.

Parameters:
pList - a list of Strings
Throws:
java.lang.ClassCastException - if the list entries are not strings

PathSpecifier

public PathSpecifier(java.util.List pList,
                     java.lang.String aSeparator)
Create a specifier using a pre-separated list of directory-name patterns, plus the separator that was used to split them apart (for use when gluing them back together with toString().

Parameters:
pList - a list of Strings
aSeparator - the directory-name separator
Throws:
java.lang.ClassCastException - if the list entries are not strings
Method Detail

parsePath

public static java.util.LinkedList parsePath(java.lang.String path)
Divide the string argument into directory-name patterns using the default directory-seperator for the current system.

Parameters:
path - the pathname to parse

parsePath

public static java.util.LinkedList parsePath(java.lang.String path,
                                             java.lang.String aSeparator)
Divide the string argument into directory-name patterns using the specified directory-seperator.

Note:
The separator is assumed to contain a single character, although it could also contain multiple characters, each of which acts as a separator. On no account can it contain multiple characters which act as a single separator.

Note:
This method is static so it can be used by other classes. The separator supplied to this method is not saved.

Parameters:
path - the pathname to parse
aSeparator - the directory-name separator -- "/" for Unix, "\" for DOS, "." for packages.

initPatternList

protected void initPatternList(java.util.List pList)
Initialize the list of path patterns

Parameters:
pList - a list of Strings
Throws:
java.lang.ClassCastException - if the list entries are not strings

match

public boolean match(java.lang.String s)
Check the string argument to see if it matches this specifier, where the default directory-seperator for the current system is used to divide the input string into directory-name segments.

Parameters:
s - the string to match, where a null or empty string matches nothing
Returns:
true if the string matche this specifier

match

public boolean match(java.lang.String path,
                     java.lang.String separator)
Check the string argument to see if it matches this specifier, where the specified seperator is used to divide the input string into directory-name segments.

Parameters:
path - the directory-path string to match, where a null or empty string matches nothing
separator - the directory-name separator -- "/" for Unix, "\" for DOS, "." for packages.
Returns:
true if the string matche this specifier

match

public boolean match(java.util.List testList)
Check the list of path-elements to see if it matches this specifier.

Parameters:
testList - a list
Returns:
true if the string matches this specifier

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object