The purpose of this class is similar to globbing, but the exact implementation details and accepted wildcards might be different from the usual common implementations.
The class takes a path during instantiation, and uses that to provide functionality to test inclusion, or discover files based on a listing implementation.
The following wildcards are supported in the current implementation:
*
: which matches any number of characters (0 or more), but doesn't pass through directory boundary.**
: which can be used only as a single full path name, and matches zero or more directories with any name.
"?"
, "["
, "]"
.
The single star wildcard can be combined with other characters, to match path names that partially contain the specified characters.
Wildcard paths that are relative, will only match relative paths, and absolute wildcard paths will only match absolute paths. A wildcard path is considered to be absolute according to the rules of SakerPath.
Examples:
dir/no/wildcard
only matchesdir/no/wildcard
abs:/no/wildcard
only matchesabs:/no/wildcard
/no/wildcard
only matches/no/wildcard
dir/*.ext
matches files under the directorydir
which have the extension.ext
dir/*123*
matches files under the directorydir
which contain the number123
dir/**/*.ext
recursively matches files under the directorydir
with the extension.ext
dir/**.ext
is the same asdir/*.ext
dir/**
recursively matches all files under the directorydir
(children and their children too)*d:/
will match root directories whose drive ends withd
This class works in a case sensitive manner. When collecting files, it will return directories and files which match the wildcard as well.
The usage of this class is not restricted to file paths, they are suitable for matching other kind of character sequences when appropriately constructed. (E.g. it can be used to match class names.)
A WildcardPath can be constructed that it doesn't contain any wildcards. In that case the path will only match the paths that equal to the one provided during instantiation.
The wildcard path doesn't handle the "."
and ".."
path names specially.
The class is comparable, and serializable.
public interface | Interface for providing listing functionality for wildcard paths. |
public static final class | Class holding information about the optimization performed in reduce(). |
public | For Externalizable. |
public int | Compares this object with the specified object for order. |
public boolean | Indicates whether some other object is "equal to" this one. |
public boolean | finishable( Checks if appending one or more names to the argument path can result in the wildcard
including it. |
public boolean | finishable( Checks if appending one or more names to the argument array of path names can result in the wildcard
including it. |
public static NavigableMap< | getFiles( Collects the files for multiple wildcard paths, a given execution directory context, and a working directory. |
public static NavigableMap< | getFiles( Collects the files for multiple wildcard paths, and a given task context. |
public NavigableMap< | Collects the files for a given file provider. |
public NavigableMap< | getFiles( Collects the files for a given file provider and working directory. |
public NavigableMap< | getFiles( Collects the files for the specified directories. |
public NavigableMap< | getFiles( Collects the files for the specified execution path configuration. |
public NavigableMap< | getFiles( Collects the files for the specified task context. |
public static < | getItems( Collects the items for multiple wildcard paths and a given ItemLister. |
public < | getItems( Collects the items for a given ItemLister. |
public SakerFile | getSingleFile( Collects a single file matching this wildcard for the given execution directory context and working directory. |
public SakerFile | getSingleFile( Collects a single file matching this wildcard for the given task context. |
public < | getSingleItem( Collects a single item matching this wildcard for the given ItemLister. |
public int | hashCode() Returns a hash code value for the object. |
public boolean | Checks if this wildcard includes/matches the specified path. |
public boolean | Checks if this wildcard includes/matches the path specified by a list of path names. |
public boolean | Checks if this wildcard includes/matches the specified path. |
public boolean | Checks if this wildcard includes/matches the path specified by an array of path names. |
public boolean | Checks if this wildcard path only consists of path names that will match all files recursively. |
public void | The object implements the readExternal method to restore its
contents by calling the methods of DataInput for primitive
types and readObject for objects, strings and arrays. |
public ReducedWildcardPath | reduce() Tries to optimize this wildcard path by removing (reducing) the starting path names that match the
path names in an exact manner. |
public String | toString() Returns a string representation of the object. |
public static WildcardPath | Creates a new wildcard path based on the given path string. |
public static WildcardPath | Creates a new wildcard path for the specified path. |
public static WildcardPath | Creates a new wildcard path for the specified path. |
public static WildcardPath | Creates a new wildcard path for the specified path names. |
public void | The object implements the writeExternal method to save its contents
by calling the methods of DataOutput for its primitive values or
calling the writeObject method of ObjectOutput for objects, strings,
and arrays. |
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementor must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.
The equals
method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
The equals
method for class Object
implements the most discriminating possible equivalence
relation on objects; that is, for any non-null reference values x
and y
, this method returns
true
if and only if x
and y
refer to the same object (x == y
has the value
true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden,
so as to maintain the general contract for the hashCode
method, which states that equal objects must have
equal hash codes.
true
if this object is the same as the obj argument; false
otherwise.
The method returns true
if any only if there exists an appending operation to the argument path that
results in the wildcard matching the result.
true
if the path can be finished so this
wildcard matches it.null
.
The method returns true
if any only if there exists an appending operation to the argument path that
results in the wildcard matching the result.
true
if the path can be finished so this
wildcard matches it.null
.
If the execution directory context is null
, no root directories are considered.
null
to not use a working
directory.null
.The root directories and working directory for the task is used for base directories.
null
.As no working directory is specified, only absolute wildcards should use this function.
null
.null
to not use a working
directory.null
.The root directories specified by the execution directory will be used to discover absolute files.
null
to not use a working
directory.The root file providers and working directory in the argument configuration will be used as a base for file collection.
null
.The root directories and working directory for the task is used for base directories.
null
.null
.null
.The root directories specified by the execution directory will be used to discover absolute files.
null
to not use a working
directory.null
if no matching file found.The root directories and working directory for the task is used for base directories.
null
if no matching file found.null
.null
if no matching item found.null
.
The general contract of hashCode
is:
- Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCode
method must consistently return the same integer, provided no information used inequals
comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)
method, then calling thehashCode
method on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal according to the
Object.equals(
Object) method, then calling thehashCode
method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class Object
does return distinct
integers for distinct objects. (This is typically implemented by converting the internal address of the object
into an integer, but this implementation technique is not required by the Java™ programming language.)
this
wildcard includes/matches the specified path.
The argument will be split up in the same way valueOf(
The argument path may be relative or absolute.
true
if this
wildcard includes the argument.null
.this
wildcard includes/matches the path specified by a list of path names. The argument path may be relative or absolute.
true
if this
wildcard includes the argument.null
.this
wildcard includes/matches the specified path. The argument path may be relative or absolute.
true
if this
wildcard includes the argument.null
.this
wildcard includes/matches the path specified by an array of path names. The argument path may be relative or absolute.
true
if this
wildcard includes the argument.null
.true
if this path contains only the "**"
path names.this
wildcard path by removing (reducing) the starting path names that match the
path names in an exact manner. As a result of this call, the wildcard path will be separated into two parts:
- The first part contains the path names which doesn't contain any wildcards, therefore matching the input in an exact manner.
- The second part starts with the first wildcarded path name and lasts until the end of
this
path.
The resulting first or second parts might be null
in which case this
wildcard either
fully matches paths exactly, or is wildcarded from the beginning.
Examples:
dir/*.ext
will be reduced todir
and*ext
dir/file.ext
will be reduced todir/file.ext
andnull
*.ext
will be reduced tonull
and*ext
(empty string wildcard) will be reduced to empty path and
null
.
will be reduced to empty path andnull
toString
method returns a string that
"textually represents" this object. The result should be a concise but informative representation that is easy
for a person to read. It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of
which the object is an instance, the at-sign character `@
', and the unsigned hexadecimal representation
of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
The argument will be split up by '/'
and '\\'
characters. The path is considered to be
absolute with the same rules as SakerPath.
Trailing slash ('/'
or '\\'
) will be ignored by this function.
null
The argument path will be normalized.
The created wildcard will have the same root (if absolute) and all path names as in the argument.
null
The created wildcard will have the same root (if absolute) and all path names as in the argument.
null
The argument is not sanity checked in any way. If it includes slashes, or other semantically important characters, they are not removed or split up. Passing an array containing invalid path names is considered to be undefined behaviour.
The array will be cloned, any modifications to it won't propagate to the created wildcard.
null