Class TokenizedPattern
- java.lang.Object
-
- org.apache.tools.ant.types.selectors.TokenizedPattern
-
public class TokenizedPattern extends java.lang.ObjectProvides reusable path pattern matching.TokenizedPatternis preferable to equivalentSelectorUtilsmethods if you need to execute multiple matching with the same pattern because here the pattern itself will be parsed only once.- Since:
- 1.8.0
- See Also:
SelectorUtils.matchPath(String, String),SelectorUtils.matchPath(String, String, boolean)
-
-
Field Summary
Fields Modifier and Type Field Description static TokenizedPatternEMPTY_PATTERNInstance that holds no tokens at all.
-
Constructor Summary
Constructors Constructor Description TokenizedPattern(java.lang.String pattern)Initialize theTokenizedPatternby parsing it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsPattern(java.lang.String pat)Does the tokenized pattern contain the given string?intdepth()Get the depth (or length) of a pattern.booleanendsWith(java.lang.String s)Learn whether the last token equals the given string.booleanequals(java.lang.Object o)trueif the original patterns are equal.java.lang.StringgetPattern()Get the pattern.inthashCode()booleanmatchPath(TokenizedPath path, boolean isCaseSensitive)Tests whether or not a given path matches a given pattern.booleanmatchStartOf(TokenizedPath path, boolean caseSensitive)Tests whether or not this pattern matches the start of a path.TokenizedPathrtrimWildcardTokens()Returns a newTokenizedPathwhere all tokens of this pattern to the right containing wildcards have been removed.java.lang.StringtoString()TokenizedPatternwithoutLastToken()Returns a new pattern without the last token of this pattern.
-
-
-
Field Detail
-
EMPTY_PATTERN
public static final TokenizedPattern EMPTY_PATTERN
Instance that holds no tokens at all.
-
-
Constructor Detail
-
TokenizedPattern
public TokenizedPattern(java.lang.String pattern)
Initialize theTokenizedPatternby parsing it.- Parameters:
pattern- The pattern to match against. Must not benull.
-
-
Method Detail
-
matchPath
public boolean matchPath(TokenizedPath path, boolean isCaseSensitive)
Tests whether or not a given path matches a given pattern.- Parameters:
path- The path to match, as aString. Must not benull.isCaseSensitive- Whether or not matching should be performed case sensitively.- Returns:
trueif the pattern matches against the string, orfalseotherwise.
-
matchStartOf
public boolean matchStartOf(TokenizedPath path, boolean caseSensitive)
Tests whether or not this pattern matches the start of a path.- Parameters:
path-TokenizedPathcaseSensitive-boolean- Returns:
boolean
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- The pattern
String
-
getPattern
public java.lang.String getPattern()
Get the pattern.- Returns:
String
-
equals
public boolean equals(java.lang.Object o)
trueif the original patterns are equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
o-Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
depth
public int depth()
Get the depth (or length) of a pattern.- Returns:
int
-
containsPattern
public boolean containsPattern(java.lang.String pat)
Does the tokenized pattern contain the given string?- Parameters:
pat-String- Returns:
boolean
-
rtrimWildcardTokens
public TokenizedPath rtrimWildcardTokens()
Returns a newTokenizedPathwhere all tokens of this pattern to the right containing wildcards have been removed.- Returns:
- the leftmost part of the pattern without wildcards
-
endsWith
public boolean endsWith(java.lang.String s)
Learn whether the last token equals the given string.- Parameters:
s-String- Returns:
boolean
-
withoutLastToken
public TokenizedPattern withoutLastToken()
Returns a new pattern without the last token of this pattern.- Returns:
TokenizedPattern
-
-