Top Description Fields Constructors Methods
org.codehaus.commons.compiler.util

public Class StringPattern

extends Object
Class Inheritance
Imports
java.util.ArrayList, .List, org.codehaus.commons.nullanalysis.Nullable

Implementation of a UNIX shell-like string pattern algorithm.

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

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
private final int
private final String
public static final StringPattern[]
PATTERNS_ALL

A StringPattern that matches any subject.

public static final StringPattern[]
PATTERNS_NONE

A StringPattern that matches no subject whatsoever.

Constructor Summary

AccessConstructor and Description
public
StringPattern(int mode, String pattern)

public

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

Whether this StringPattern represents inclusion (INCLUDE) or exclusion exclusion (EXCLUDE) of subjects
getMode
()

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
public static boolean
matches(StringPattern[] patterns, String text)

Matchs a given text against an array of StringPatterns (which was typically created by parseCombinedPattern(String).

public static StringPattern[]
parseCombinedPattern(String combinedPattern)

Parses a "combined pattern" into an array of StringPatterns.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static boolean
wildmatch(String pattern, String text)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

EXCLUDEback to summary
public static final int EXCLUDE
See Also
matches(StringPattern[], String)
INCLUDEback to summary
public static final int INCLUDE
See Also
matches(StringPattern[], String)
modeback to summary
private final int mode
patternback to summary
private final String pattern
Annotations
@Nullable
PATTERNS_ALLback to summary
public static final StringPattern[] PATTERNS_ALL

A StringPattern that matches any subject.

PATTERNS_NONEback to summary
public static final StringPattern[] PATTERNS_NONE

A StringPattern that matches no subject whatsoever.

Constructor Detail

StringPatternback to summary
public StringPattern(int mode, String pattern)
Parameters
mode:int

INCLUDE or EXCLUDE

StringPatternback to summary
public StringPattern(String pattern)

Method Detail

getModeback to summary
public int getMode()
Returns:int

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

matchesback to summary
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.

matchesback to summary
public static boolean matches(StringPattern[] patterns, String text)

Matchs a given text against an array of StringPatterns (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.

Annotations
@SuppressWarnings:unused, null
parseCombinedPatternback to summary
public static StringPattern[] parseCombinedPattern(String combinedPattern)

Parses a "combined pattern" into an array of StringPatterns. 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.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
wildmatchback to summary
private static boolean wildmatch(String pattern, String text)