- All Implemented Interfaces:
Matchable<String>
,Matcher<String>
,WildcardMatcher
,org.refcodes.mixin.DelimiterAccessor
,org.refcodes.mixin.Schemable<MatcherSchema>
public class PathMatcher
extends AbstractWildcardMatcher<String>
implements WildcardMatcher, org.refcodes.mixin.DelimiterAccessor
The
PathMatcher
provides WildcardMatcher
functionality for
matching paths: The PathMatcher
matches 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 ("*" as of Wildcard.FILE
) matches zero or more
characters within a path name. A double asterisk ("**" as of
Wildcard.PATH
) matches zero or more characters across directory
levels. A question mark ("?" as of Wildcard.CHAR
) matches exactly one
character within a path name. The single asterisk ("*" as of
Wildcard.FILE
), the double asterisk ("**" as of
Wildcard.PATH
) and the question mark ("?" as of
Wildcard.CHAR
) 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"-
Nested Class Summary
Nested classes/interfaces inherited from class org.refcodes.matcher.AbstractWildcardMatcher
AbstractWildcardMatcher.WildcardMatcherSubstitutes
Nested classes/interfaces inherited from interface org.refcodes.mixin.DelimiterAccessor
org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B extends org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B>>, org.refcodes.mixin.DelimiterAccessor.DelimiterMutator, org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
-
Field Summary
Fields inherited from class org.refcodes.matcher.AbstractWildcardMatcher
REGEX_PATTERN, WILDCARD_NAMES
Fields inherited from class org.refcodes.matcher.AbstractMatcher
MATCHEE
-
Constructor Summary
ConstructorDescriptionPathMatcher
(String aPathPattern) Constructs an ANT PathMatcher
, matching its ANT path pattern against the path provided to theisMatching(String)
method.PathMatcher
(String aPathPattern, char aDelimiter) Constructs an ANT PathMatcher
, matching its ANT path pattern against the path provided to theisMatching(String)
method. -
Method Summary
Modifier and TypeMethodDescriptionboolean
char
Returns the path pattern being used by thePathMatcher
.String[]
Retrieves the list of wildcard names identifying the wildcards as specified by the pattern.int
hashCode()
boolean
isMatching
(String aPath) The this method applies the following rules from the configured ANT path pattern to the path provided viaisMatching(String)
method: A single asterisk ("*" as ofWildcard.FILE
) matches zero or more characters within a path name.For debugging purposes, retrieve the regex pattern created from the ANT path pattern.toSchema()
toWildcardReplacement
(String aPath, String aWildcardName) Returns the wildcard substitute for the wildcards in your pattern compared to the actual text.toWildcardReplacementAt
(String aPath, int aIndex) Returns the wildcard substitute for the wildcards in your pattern compared to the actual text (as ofWildcardMatcher.toWildcardSubstitutes(String)
).String[]
toWildcardReplacements
(String aPath) Returns an array of the wildcard substitutes for the wildcards in your pattern compared to the actual text (as ofWildcardMatcher.toWildcardSubstitutes(String)
).String[]
toWildcardReplacements
(String aPath, String... aWildcardNames) Returns the wildcard substitutes for the wildcards in your pattern compared to the actual text .String[]
toWildcardReplacementsAt
(String aPath, int... aIndexes) Returns the wildcard substitutes for the wildcards in your pattern compared to the actual text.org.refcodes.mixin.WildcardSubstitutes
toWildcardSubstitutes
(String aPath) Returns all available wildcard substitutes as well as the named wildcard substitutes.
-
Constructor Details
-
PathMatcher
Constructs an ANT PathMatcher
, matching its ANT path pattern against the path provided to theisMatching(String)
method. Theorg.refcodes.data.Delimiter#PATH
is used as default path delimiter. ThePathMatcher
applies the following rules from the ANT path pattern to the path provided viaisMatching(String)
method: A single asterisk ("**" as ofWildcard.FILE
) matches zero or more characters within a path name. A double asterisk ("**" as ofWildcard.PATH
) matches zero or more characters across directory levels. A question mark ("?" as ofWildcard.CHAR
) matches exactly one character within a path name.- Parameters:
aPathPattern
- The pattern to be used when matching a path viaisMatching(String)
.
-
PathMatcher
Constructs an ANT PathMatcher
, matching its ANT path pattern against the path provided to theisMatching(String)
method. Theorg.refcodes.data.Delimiter#PATH
is used as default path delimiter. ThePathMatcher
applies the following rules from the ANT path pattern to the path provided viaisMatching(String)
method: A single asterisk ("**" as ofWildcard.FILE
) matches zero or more characters within a path name. A double asterisk ("**" as ofWildcard.PATH
) matches zero or more characters across directory levels. A question mark ("?" as ofWildcard.CHAR
) matches exactly one character within a path name.- Parameters:
aPathPattern
- The pattern to be used when matching a path viaisMatching(String)
.aDelimiter
- The delimiter separating the path elements from each other and must not be one of the following chars: '?', '*', '|'.- Throws:
IllegalArgumentException
- thrown in case the delimiter provided was one of the following chars: '?', '*', '|'.
-
-
Method Details
-
getWildcardNames
Retrieves the list of wildcard names identifying the wildcards as specified by the pattern.- Specified by:
getWildcardNames
in interfaceWildcardMatcher
- Returns:
- The wild card names or null of no wild card names have been defined.
-
getPathPattern
Returns the path pattern being used by thePathMatcher
.- Returns:
- The path pattern being used.
-
isMatching
The this method applies the following rules from the configured ANT path pattern to the path provided viaisMatching(String)
method: A single asterisk ("*" as ofWildcard.FILE
) matches zero or more characters within a path name. A double asterisk ("**" as ofWildcard.PATH
) matches zero or more characters across directory levels. A question mark ("?" as ofWildcard.CHAR
) matches exactly one character within a path name Tests whether the given event is matching the mathcer's criteria.- Specified by:
isMatching
in interfaceMatchable<String>
- Parameters:
aPath
- The matchee used for testing matchability.- Returns:
- True in case the matchee matches the matcher's criteria, else false.
-
toWildcardSubstitutes
Returns all available wildcard substitutes as well as the named wildcard substitutes.- Specified by:
toWildcardSubstitutes
in interfaceWildcardMatcher
- Parameters:
aPath
- Tex textfor which to retrieve the wildcard substitutes.- Returns:
- The
WildcardSubstitutes
of the wildcards being substituted.
-
toWildcardReplacements
Returns an array of the wildcard substitutes for the wildcards in your pattern compared to the actual text (as ofWildcardMatcher.toWildcardSubstitutes(String)
). The order of the wildcard substitutes aligns to the order of the wildcards (from left to right) defined in your pattern.- Specified by:
toWildcardReplacements
in interfaceWildcardMatcher
- Parameters:
aPath
- Tex textfor which to retrieve the wildcard substitutes.- Returns:
- The text substituting the wildcards in the order of the wildcards being substituted or null if there are none such substitutes.
-
toWildcardReplacementAt
Returns the wildcard substitute for the wildcards in your pattern compared to the actual text (as ofWildcardMatcher.toWildcardSubstitutes(String)
). The text of the wildcard substitute aligns to the index of the wildcard (from left to right) as defined in your pattern.- Specified by:
toWildcardReplacementAt
in interfaceWildcardMatcher
- Parameters:
aPath
- Tex textfor which to retrieve the wildcard substitutes.aIndex
- The index of the wildcard in question for which to retrieve the substitute.- Returns:
- The text substituting the wildcard at the given pattern's wildcard index or null if there is none such substitute.
-
toWildcardReplacementsAt
Returns the wildcard substitutes for the wildcards in your pattern compared to the actual text. The text of the wildcard substitutes aligns to the indexes of the wildcard (from left to right) as defined in your pattern.- Specified by:
toWildcardReplacementsAt
in interfaceWildcardMatcher
- Parameters:
aPath
- Tex textfor which to retrieve the wildcard substitutes.aIndexes
- The indexes of the wildcards in question for which to retrieve the substitutes.- Returns:
- The text substituting the wildcards at the given pattern's wildcard indexes or null if there is none such substitute.
-
toWildcardReplacement
Returns the wildcard substitute for the wildcards in your pattern compared to the actual text. The text of the wildcard substitute aligns to the name of the wildcard (as defined in your pattern).- Specified by:
toWildcardReplacement
in interfaceWildcardMatcher
- Parameters:
aPath
- Tex textfor which to retrieve the wildcard substitutes.aWildcardName
- The name of the wildcard in question for which to retrieve the substitute.- Returns:
- The text substituting the wildcard with the given pattern's wildcard name or null if there is none such substitute.
-
toWildcardReplacements
Returns the wildcard substitutes for the wildcards in your pattern compared to the actual text . The text of the wildcard substitutes aligns to the order of the provided wildcard names (as defined in your pattern).- Specified by:
toWildcardReplacements
in interfaceWildcardMatcher
- Parameters:
aPath
- Tex textfor 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.- Returns:
- The text substituting the wildcard with the given pattern's wildcard names or null if there are none such substitute.
-
toPattern
For debugging purposes, retrieve the regex pattern created from the ANT path pattern.- Returns:
- Returns the regex created from the ANT path pattern.
-
hashCode
public int hashCode() -
equals
-
getDelimiter
public char getDelimiter()- Specified by:
getDelimiter
in interfaceorg.refcodes.mixin.DelimiterAccessor
-
toSchema
- Specified by:
toSchema
in interfaceorg.refcodes.mixin.Schemable<MatcherSchema>
- Overrides:
toSchema
in classAbstractMatcher<String>
-