Package org.apache.tools.ant.types.selectors

# Class TokenizedPattern

java.lang.Object
org.apache.tools.ant.types.selectors.TokenizedPattern

public class TokenizedPattern extends Object
Provides reusable path pattern matching. `TokenizedPattern` 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.matchPath(String, String)`
  - `SelectorUtils.matchPath(String, String, boolean)`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final TokenizedPattern`
  `EMPTY_PATTERN`
  Instance that holds no tokens at all.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TokenizedPattern(String pattern)`
  Initialize the `TokenizedPattern` by parsing it.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `containsPattern(String pat)`
  Does the tokenized pattern contain the given string?
  `int`
  `depth()`
  Get the depth (or length) of a pattern.
  `boolean`
  `endsWith(String s)`
  Learn whether the last token equals the given string.
  `boolean`
  `equals(Object o)`
  `true` if the original patterns are equal.
  `String`
  `getPattern()`
  Get the pattern.
  `int`
  `hashCode()`
  `boolean`
  `matchPath(TokenizedPath path, boolean isCaseSensitive)`
  Tests whether or not a given path matches a given pattern.
  `boolean`
  `matchStartOf(TokenizedPath path, boolean caseSensitive)`
  Tests whether or not this pattern matches the start of a path.
  `TokenizedPath`
  `rtrimWildcardTokens()`
  Returns a new `TokenizedPath` where all tokens of this pattern to the right containing wildcards have been removed.
  `String`
  `toString()`
  `TokenizedPattern`
  `withoutLastToken()`
  Returns a new pattern without the last token of this pattern.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### EMPTY_PATTERN

    public static final TokenizedPattern EMPTY_PATTERN
    Instance that holds no tokens at all.

- ## Constructor Details

  - ### TokenizedPattern

    public TokenizedPattern(String pattern)
    Initialize the `TokenizedPattern` by parsing it.
    Parameters:
      `pattern` - The pattern to match against. Must not be `null`.

- ## Method Details

  - ### 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.
    Parameters:
      `path` - `TokenizedPath`
      `caseSensitive` - `boolean`
    Returns:
      `boolean`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`
    Returns:
      The pattern `String`

  - ### getPattern

    public String getPattern()
    Get the pattern.
    Returns:
      `String`

  - ### equals

    public boolean equals(Object o)
    `true` if the original patterns are equal.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `o` - `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### depth

    public int depth()
    Get the depth (or length) of a pattern.
    Returns:
      `int`

  - ### containsPattern

    public boolean containsPattern(String pat)
    Does the tokenized pattern contain the given string?
    Parameters:
      `pat` - `String`
    Returns:
      `boolean`

  - ### 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

  - ### endsWith

    public boolean endsWith(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`