com.edugility.objexj
Class Matcher<T>

java.lang.Object
  extended by com.edugility.objexj.Matcher<T>
Type Parameters:
T - the kind of Object any input consists of

public class Matcher<T>
extends Object

An object that matches a Pattern against a List of items (the input).

Matchers are produced by the Pattern.matcher(List) method. Once a Matcher has been produced it stores results about any match that might have occurred.

Matchers are not safe for use by multiple Java threads.

Author:
Laird Nelson
See Also:
Pattern, Pattern.matcher(List), matches(), lookingAt(), Syntax Guide

Method Summary
 Object get(Object key)
          Returns the value of the variable indexed under the supplied key, or null if no such value was ever established.
 List<? extends T> getInput()
          Returns the input with which this Matcher is currently affiliated.
 Pattern<T> getPattern()
          Returns the Pattern with which this Matcher is currently affiliated.
 Map<?,?> getVariables()
          Returns a non-null, unmodifiable Map representing the variables set by this Matcher during its execution.
 List<? extends T> group(int index)
          Returns the capture group matched by the last match indexed under the supplied zero-based index, or null if no such capture group was matched.
 int groupCount()
          Returns the total number of capture groups matched by this Matcher.
 boolean lookingAt()
          Returns true if a prefix of this Matcher's input matches this Matcher's affiliated Pattern.
 boolean matches()
          Returns true if this Matcher matches the entire input against its affiliated Pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

matches

public final boolean matches()
Returns true if this Matcher matches the entire input against its affiliated Pattern.

In many cases the lookingAt() method is more suitable.

Returns:
true if this Matcher matches the entire input against its affiliated Pattern; false otherwise
See Also:
lookingAt()

lookingAt

public final boolean lookingAt()
Returns true if a prefix of this Matcher's input matches this Matcher's affiliated Pattern.

Sometimes the matches() method is more suitable.

Returns:
true if a prefix of this Matcher's input matches this Matcher's affiliated Pattern; false otherwise
See Also:
matches()

groupCount

public final int groupCount()
Returns the total number of capture groups matched by this Matcher. Any successful match will cause this method to return an int greater than or equal to 1. Group indices are numbered starting with 0.

Returns:
the total number of capture groups matched by this Matcher; never less than 0
See Also:
Syntax Guide

group

public final List<? extends T> group(int index)
Returns the capture group matched by the last match indexed under the supplied zero-based index, or null if no such capture group was matched.

Parameters:
index - a zero-based number identifying a capture group; may be any number
Returns:
a List of items (a subset of the input), or null if no such capture group was ever identified
See Also:
Syntax Guide

getVariables

public final Map<?,?> getVariables()
Returns a non-null, unmodifiable Map representing the variables set by this Matcher during its execution. Variables may be set from within a Pattern's parsed expression.

This method never returns null.

Returns:
a non-null unmodifiable Map of variables
See Also:
Syntax Guide

get

public final Object get(Object key)
Returns the value of the variable indexed under the supplied key, or null if no such value was ever established. Variables may be set from within a Pattern's parsed expression.

Parameters:
key - the name of the variable; may be null but if so then null will be returned
Returns:
the value of the variable, or null
See Also:
Syntax Guide

getPattern

public final Pattern<T> getPattern()
Returns the Pattern with which this Matcher is currently affiliated. This method never returns null.

Returns:
a non-null Pattern

getInput

public final List<? extends T> getInput()
Returns the input with which this Matcher is currently affiliated. This method may return null.

Returns:
the input, or null


Copyright © 2012–2013, Laird Nelson. All rights reserved.