org.openbp.common.string.shellmatcher
Class ShellMatcher

java.lang.Object
  extended by org.openbp.common.string.shellmatcher.ShellMatcher

public class ShellMatcher
extends java.lang.Object

The ShellMatcher implements a UNIX-shell-compatible string pattern matcher. For a description of the meta characters that can be used in a pattern, see the setPattern(java.lang.String) method.
The methods of this class throw the ShellMatcherException runtime exception on argument or pattern syntax error.

Author:
Heiko Erhardt

Constructor Summary
ShellMatcher()
          Default constructor
ShellMatcher(java.lang.String patternArg)
          Value constructor.
 
Method Summary
 boolean match(java.lang.String s)
          Matches a string against the current pattern.
 void setIgnoreCase(boolean ignoreCase)
          Sets the ignore case option.
 void setPattern(java.lang.String pattern)
          Sets the pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShellMatcher

public ShellMatcher()
Default constructor


ShellMatcher

public ShellMatcher(java.lang.String patternArg)
Value constructor.

Parameters:
patternArg - The pattern may contain the following meta characters:
\c*\ \ \ \ \ \ \ \c 0 or more arbitrary characters
\c?\ \ \ \ \ \ \ \c exactly 1 arbitrary character
\c[\ilist\i]\ \ \c one of the characters in the list
\c[^\ilist\i]\ \c one of the characters not in the list
\c[\il\i-\ir\i]\ \ \ \c one of the characters between l and r
\c[^\il\i-\ir\i]\ \ \c one of the characters not between l and r
\c\\ \ \ \ \ \ \ \c escape character
Method Detail

setPattern

public void setPattern(java.lang.String pattern)
Sets the pattern.

Parameters:
pattern - The pattern may contain the following meta characters:
\c*\ \ \ \ \ \ \ \c 0 or more arbitrary characters
\c?\ \ \ \ \ \ \ \c exactly 1 arbitrary character
\c[\ilist\i]\ \ \c one of the characters in the list
\c[^\ilist\i]\ \c one of the characters not in the list
\c[\il\i-\ir\i]\ \ \ \c one of the characters between l and r
\c[^\il\i-\ir\i]\ \ \c one of the characters not between l and r
\c\\ \ \ \ \ \ \ \c escape character

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)
Sets the ignore case option.

Parameters:
ignoreCase - true The character case will be ignored when comparing literals.
false The pattern matcher will distinguish between lower and upper case.

match

public boolean match(java.lang.String s)
Matches a string against the current pattern. A pattern must have been specified before calling this method.

Parameters:
s - The String to match against the pattern
Returns:
@return true The string matches the pattern
false otherwise
Throws:
ShellMatcherException - On argument or pattern syntax error


Copyright © 2011. All Rights Reserved.