Package org.codehaus.commons.compiler.util

# Class StringPattern

java.lang.Object
org.codehaus.commons.compiler.util.StringPattern

public class StringPattern extends Object
Implementation of a UNIX shell-like string pattern algorithm.

Additionally, the concept of the "combined pattern" is supported (see `matches(StringPattern[], String)`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`EXCLUDE`
`static final int`
`INCLUDE`
`static final StringPattern[]`
`PATTERNS_ALL`
A `StringPattern` that matches any subject.
`static final StringPattern[]`
`PATTERNS_NONE`
A `StringPattern` that matches no subject whatsoever.

## Constructor Summary

Constructors
Constructor
Description
`StringPattern(int mode, String pattern)`
`StringPattern(String pattern)`

## Method Summary

Modifier and Type
Method
Description
`int`
`getMode()`
`boolean`
`matches(String text)`
Matches the given `text` against the pattern represented by the current instance, as follows: A `*` in the pattern matches any sequence of zero or more characters in the `text` A `?` in the pattern matches exactly one character in the `text` Any other character in the pattern must appear exactly as it is in the `text`
`static boolean`
`matches(StringPattern[] patterns, String text)`
Matchs a given `text` against an array of `StringPattern`s (which was typically created by `parseCombinedPattern(String)`.
`static StringPattern[]`
`parseCombinedPattern(String combinedPattern)`
Parses a "combined pattern" into an array of `StringPattern`s.
`String`
`toString()`

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

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

## Field Details

### INCLUDE

public static final int INCLUDE

See Also:
  - `matches(StringPattern[], String)`
  - Constant Field Values

### EXCLUDE

public static final int EXCLUDE

See Also:
  - `matches(StringPattern[], String)`
  - Constant Field Values

### PATTERNS_ALL

public static final StringPattern[] PATTERNS_ALL
A `StringPattern` that matches any subject.

### PATTERNS_NONE

public static final StringPattern[] PATTERNS_NONE
A `StringPattern` that matches no subject whatsoever.

## Constructor Details

### StringPattern

public StringPattern(int mode, String pattern)

Parameters:
  `mode` - `INCLUDE` or `EXCLUDE`

### StringPattern

public StringPattern(@Nullable String pattern)

## Method Details

### getMode

public int getMode()

Returns:
  Whether this `StringPattern` represents inclusion (`INCLUDE`) or exclusion exclusion (`EXCLUDE`) of subjects

### matches

public boolean matches(String text)
Matches the given `text` against the pattern represented by the current instance, as follows:

- A `*` in the pattern matches any sequence of zero or more characters in the `text`
- A `?` in the pattern matches exactly one character in the `text`
- Any other character in the pattern must appear exactly as it is in the `text`

Notice: The `mode` flag of the current instance does not take any effect here.

### parseCombinedPattern

public static StringPattern[] parseCombinedPattern(String combinedPattern)
Parses a "combined pattern" into an array of `StringPattern`s. A combined pattern string is structured as follows:

       combined-pattern :=
         [ '+' | '-' ] pattern
         { ( '+' | '-' ) pattern }

If a pattern is preceeded with a '-', then the `StringPattern` is created with mode `EXCLUDE`, otherwise with mode `INCLUDE`.

### matches

public static boolean matches(StringPattern[] patterns, String text)
Matchs a given `text` against an array of `StringPattern`s (which was typically created by `parseCombinedPattern(String)`.

The last matching pattern takes effect; if its mode is `INCLUDE`, then `true` is returned, if its mode is `EXCLUDE`, then `false` is returned.

If `patterns` is `PATTERNS_NONE`, or empty, or none of its patterns matches, then `false` is returned.

If `patterns` is `PATTERNS_ALL`, then `true` is returned.

For backwards compatibility, `null` patterns are treated like `PATTERNS_NONE`.

### toString

public String toString()

Overrides:
  `toString` in class `Object`