com.tensegrity.generic.util
Class PatternMatcher

java.lang.Object
  extended bycom.tensegrity.generic.util.PatternMatcher

public final class PatternMatcher
extends java.lang.Object

Class PatternMatcher implements a very simple regular expression mechanism. It can be used to do plain pattern matching similar to the one you can find in DOS filename placeholders.

See the comments in the constructor of this class for further details on the supported pattern matching modes.

Because a PatternMatcher does not precompile a given pattern, instantiation is extremely fast.

Version:
$Id: PatternMatcher.java,v 1.14 2005/05/23 13:43:15 KevinCVS Exp $
Author:
S. Rutz

Field Summary
static int STYLE_FILENAME
          This mode is similar to dos-filename expansion. '?'
static int STYLE_REGULAR
          A simple regular expression style where '.' is the placeholder for any character, 'C*' matches character C (which can be any character) zero or more times, '^' matches the beginning of the string and '$' matches the end of the string.
 
Constructor Summary
PatternMatcher(int mode)
          Constructs a new PatterMatcher with the given mode.
 
Method Summary
 boolean check(java.lang.String pattern, java.lang.String text)
          Checks whether the given text is matched by the given pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STYLE_REGULAR

public static final int STYLE_REGULAR
A simple regular expression style where '.' is the placeholder for any character, 'C*' matches character C (which can be any character) zero or more times, '^' matches the beginning of the string and '$' matches the end of the string.

See Also:
Constant Field Values

STYLE_FILENAME

public static final int STYLE_FILENAME
This mode is similar to dos-filename expansion. '?' serves as a placeholder for a single character. '*' is the wildcard that matches arbitrarily long substrings. For example the pattern '?*house*?' would match all strings that have the substring 'house' inside of them, but would both start and end with two arbitrary additional characters. The pattern '*house*' would match all strings with the substring house anywhere in it.

See Also:
Constant Field Values
Constructor Detail

PatternMatcher

public PatternMatcher(int mode)
Constructs a new PatterMatcher with the given mode.

The modes are:

Method Detail

check

public final boolean check(java.lang.String pattern,
                           java.lang.String text)
Checks whether the given text is matched by the given pattern. The pattern is interpreted according to the selected mode of this PatternMatcher instance.

Parameters:
pattern - the pattern to match, pattern is interpreted according to the mode of this PatternMatcher.
text - the text to match against the pattern.
Returns:
true, if text was matched; false if not.
Throws:
InvalidArgumentException - if one of the arguments is null.

Find more information in the class documentation



Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.