org.umber.core.regexp
Class RegularExpressionJava14

java.lang.Object
  extended byorg.umber.core.regexp.RegularExpressionJava14
All Implemented Interfaces:
IRegularExpression

public class RegularExpressionJava14
extends java.lang.Object
implements IRegularExpression

Regular expression parser that wraps the Java 1.4 java.util.regex package.

Author:
jsheets

Constructor Summary
RegularExpressionJava14()
           
 
Method Summary
 int end(int group)
          Retrieves the ending offset of the matched group text, relative to the start of the full matched text (i.e., group zero).
 int getGroupCount()
          Calculates the number of groups found in the current pattern.
 java.lang.String group(int group)
          Retrieves the fragment of the input text from the most recent call to matches() that corresponds to the given group index.
 boolean loadPattern(java.lang.String pattern)
          Loads the regular expression pattern.
 boolean matches(java.lang.String text)
          Determines if the text matches against the current pattern.
 int start(int group)
          Retrieves the beginning offset of the matched group text, relative to the start of the full matched text (i.e., group zero).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegularExpressionJava14

public RegularExpressionJava14()
Method Detail

loadPattern

public boolean loadPattern(java.lang.String pattern)
Loads the regular expression pattern. Must be called with a valid expression before any of the other interface methods are used. Different regular expression implementations might have slightly different concepts of valid expressions, or idiosyncracities in their parsing strategies.

Specified by:
loadPattern in interface IRegularExpression
Parameters:
pattern - regular expression pattern
Returns:
true if the pattern is valid for this implementation

matches

public boolean matches(java.lang.String text)
Determines if the text matches against the current pattern.

Specified by:
matches in interface IRegularExpression
Parameters:
text - text to match against the current regular expression
Returns:
true if the text matches
Throws:
java.lang.IllegalStateException - if loadPattern() hasn't been called yet on a valid pattern

getGroupCount

public int getGroupCount()
Calculates the number of groups found in the current pattern.

Specified by:
getGroupCount in interface IRegularExpression
Returns:
the number of groups found in the current pattern
Throws:
java.lang.IllegalStateException - if loadPattern() and matches() haven't been called yet on a valid pattern

group

public java.lang.String group(int group)
Retrieves the fragment of the input text from the most recent call to matches() that corresponds to the given group index. The group index is a one-based index to the parenthetical pattern groups set in the most recent call to loadPattern(). Thus, a pattern of "a(bc)d(e?fg)" has two groups: group 1 corresponds to "bc", and group 2 corresponds to "e?fg". A group index of zero will always return the entire matched text.

Specified by:
group in interface IRegularExpression
Parameters:
group - index of parenthetical groups in the current pattern
Returns:
a String fragment of the text that matches that group
Throws:
java.lang.IllegalStateException - if loadPattern() and matches() haven't been called yet on a valid pattern
java.lang.IndexOutOfBoundsException - if the index is < 0 or >= getGroupCount()

start

public int start(int group)
Retrieves the beginning offset of the matched group text, relative to the start of the full matched text (i.e., group zero).

Specified by:
start in interface IRegularExpression
Parameters:
group - index of parenthetical groups in the current pattern
Returns:
the beginning offset of the matched group text
Throws:
java.lang.IllegalStateException - if loadPattern() and matches() haven't been called yet on a valid pattern
java.lang.IndexOutOfBoundsException - if the index is < 0 or >= getGroupCount()

end

public int end(int group)
Retrieves the ending offset of the matched group text, relative to the start of the full matched text (i.e., group zero).

Specified by:
end in interface IRegularExpression
Parameters:
group - index of parenthetical groups in the current pattern
Returns:
the ending offset of the matched group text
Throws:
java.lang.IllegalStateException - if loadPattern() and matches() haven't been called yet on a valid pattern
java.lang.IndexOutOfBoundsException - if the index is < 0 or >= getGroupCount()