PathMatcherImpl
public interface PathMatcher extends Matcher<String>
Matcher
, matching its ANT like path pattern against the path
provided to the isMatching(String)
and the like methods.
The PathMatcher
applies the following rules from the ANT path pattern
to the path provided via isMatching(String)
method:
A single asterisk ("*") matches zero or more characters within a path name. A
double asterisk ("**") matches zero or more characters across directory
levels. A question mark ("?") matches exactly one character within a path
name.
The single asterisk ("*"), the double asterisk ("**") and the question mark
("?") we refer to as wildcards: You get an array with the substitutes of the
wildcards using the method toWildcardSubstitutes(String)
(or null,
if your String
does not match your path pattern).
You may name a wildcard by prefixing it with "${someWildcardName}=". For
example a named wildcard may look as follows: "${arg1}=*" or "${arg2}=**" or
"${arg3}=?". A placeholder "${arg1}" with no wildcard assignment "=" is
equivalent to "${arg1}=*".
The regular expression pattern construction is inspired by:
"http://stackoverflow.com/questions/33171025/regex-matching-an-ant-path"Modifier and Type | Method | Description |
---|---|---|
String |
getPathPattern() |
Returns the path pattern being used by the
PathMatcher . |
String[] |
getWildcardNames() |
Retrieves the list of wildcard names identifying the wildcards as
specified by the path pattern.
|
boolean |
isMatching(String aPath) |
The this method applies the following rules from the configured ANT path
pattern to the path provided via
isMatching(String) method:
A single asterisk ("*") matches zero or more characters within a path
name. |
String |
toWildcardReplacement(String aPath,
String aWildcardName) |
Returns the wildcard substitute for the wildcards in your path pattern
(see
getPathPattern() ) compared to the actual path
(as of toWildcardSubstitutes(String) ). |
String |
toWildcardReplacementAt(String aPath,
int aIndex) |
Returns the wildcard substitute for the wildcards in your path pattern
(see
getPathPattern() ) compared to the actual path
(as of toWildcardSubstitutes(String) ). |
String[] |
toWildcardReplacements(String aPath) |
Returns an array of the wildcard substitutes for the wildcards in your
path pattern (see
getPathPattern() ) compared to the
actual path (as of toWildcardSubstitutes(String) ). |
String[] |
toWildcardReplacements(String aPath,
String... aWildcardNames) |
Returns the wildcard substitutes for the wildcards in your path pattern
(see
getPathPattern() ) compared to the actual path
(as of toWildcardSubstitutes(String) ). |
String[] |
toWildcardReplacementsAt(String aPath,
int... aIndexes) |
Returns the wildcard substitutes for the wildcards in your path pattern
(see
getPathPattern() ) compared to the actual path
(as of toWildcardSubstitutes(String) ). |
WildcardSubstitutes |
toWildcardSubstitutes(String aPath) |
Returns all available wildcard substitutes as well as the named wildcard
substitutes.
|
boolean isMatching(String aPath)
isMatching(String)
method:
A single asterisk ("*") matches zero or more characters within a path
name. A double asterisk ("**") matches zero or more characters across
directory levels. A question mark ("?") matches exactly one character
within a path name
Tests whether the given event is matching the mathcer's criteria.isMatching
in interface Matcher<String>
aPath
- The matchee used for testing matchability.String getPathPattern()
PathMatcher
.WildcardSubstitutes toWildcardSubstitutes(String aPath)
aPath
- The path for which to retrieve the wildcard substitutes.WildcardSubstitutes
of the wildcards being
substituted.String[] toWildcardReplacements(String aPath)
getPathPattern()
) compared to the
actual path (as of toWildcardSubstitutes(String)
).
The order of the wildcard substitutes aligns to the order of the
wildcards (from left to right) defined in your path pattern.aPath
- The path for which to retrieve the wildcard substitutes.String toWildcardReplacementAt(String aPath, int aIndex)
getPathPattern()
) compared to the actual path
(as of toWildcardSubstitutes(String)
). The text of
the wildcard substitute aligns to the index of the wildcard (from left to
right) as defined in your path pattern.aPath
- The path for which to retrieve the wildcard substitutes.aIndex
- The index of the wildcard in question for which to retrieve
the substitute.String[] toWildcardReplacementsAt(String aPath, int... aIndexes)
getPathPattern()
) compared to the actual path
(as of toWildcardSubstitutes(String)
). The text of
the wildcard substitutes aligns to the indexes of the wildcard (from left
to right) as defined in your path pattern.aPath
- The path for which to retrieve the wildcard substitutes.aIndexes
- The indexes of the wildcards in question for which to
retrieve the substitutes.String toWildcardReplacement(String aPath, String aWildcardName)
getPathPattern()
) compared to the actual path
(as of toWildcardSubstitutes(String)
). The text of
the wildcard substitute aligns to the name of the wildcard (as defined in
your path pattern).aPath
- The path for which to retrieve the wildcard substitutes.aWildcardName
- The name of the wildcard in question for which to
retrieve the substitute.String[] toWildcardReplacements(String aPath, String... aWildcardNames)
getPathPattern()
) compared to the actual path
(as of toWildcardSubstitutes(String)
). The text of
the wildcard substitutes aligns to the order of the provided wildcard
names (as defined in your path pattern).aPath
- The path for which to retrieve the wildcard substitutes.aWildcardNames
- The names of the wildcards in question for which to
retrieve the substitutes in the order of the provided names.String[] getWildcardNames()
Copyright © 2018. All rights reserved.