org.apache.tools.ant.types.selectors

Class TokenizedPattern

public class TokenizedPattern extends Object

Provides reusable path pattern matching. PathPattern is preferable to equivalent SelectorUtils methods 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 SelectorUtils

Field Summary
static TokenizedPatternEMPTY_PATTERN
Instance that holds no tokens at all.
Constructor Summary
TokenizedPattern(String pattern)
Initialize the PathPattern by parsing it.
Method Summary
booleancontainsPattern(String pat)
Does the tokenized pattern contain the given string?
intdepth()
The depth (or length) of a pattern.
booleanendsWith(String s)
true if the last token equals the given string.
booleanequals(Object o)
true if the original patterns are equal.
StringgetPattern()
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 new TokenizedPath where all tokens of this pattern to the right containing wildcards have been removed
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(String pattern)
Initialize the PathPattern by parsing it.

Parameters: pattern The pattern to match against. Must not be null.

Method Detail

containsPattern

public boolean containsPattern(String pat)
Does the tokenized pattern contain the given string?

depth

public int depth()
The depth (or length) of a pattern.

endsWith

public boolean endsWith(String s)
true if the last token equals the given string.

equals

public boolean equals(Object o)
true if the original patterns are equal.

getPattern

public String getPattern()

hashCode

public int hashCode()

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 a String. Must not be null. isCaseSensitive Whether or not matching should be performed case sensitively.

Returns: true if the pattern matches against the string, or false otherwise.

matchStartOf

public boolean matchStartOf(TokenizedPath path, boolean caseSensitive)
Tests whether or not this pattern matches the start of a path.

rtrimWildcardTokens

public TokenizedPath rtrimWildcardTokens()
Returns a new TokenizedPath where all tokens of this pattern to the right containing wildcards have been removed

Returns: the leftmost part of the pattern without wildcards

toString

public String toString()

Returns: The pattern String

withoutLastToken

public TokenizedPattern withoutLastToken()
Returns a new pattern without the last token of this pattern.