ix.util.match
Class MatchCase

java.lang.Object
  extended by ix.util.match.MatchCase
Direct Known Subclasses:
LTF_Parser.ConstraintParser

public abstract class MatchCase
extends java.lang.Object

The root class for entries in MatchTables.

If you think of a MatchTable as analogous to a case statement, a MatchCase is analogous to a single case clause, with the MatchCase's ifSelected method containing the code that is executed in the body of that clause.

A MatchCase normally contains a pattern that can be examined by the MatchTable that contains the MatchCase. The MatchCase's tryMatch method normally implements a match against that pattern.

If the MatchCase is used as a MatchTable default, the pattern and the tryMatch method are ignored.

See Also:
MatchTable, MatchEnv

Field Summary
protected  java.lang.Object pattern
          An object to match against.
 
Constructor Summary
MatchCase()
           
 
Method Summary
 java.lang.Object getPattern()
          getPattern returns this MatchCase's pattern.
 java.lang.Object ifSelected(java.lang.Object data, java.lang.Object matchResult)
          ifSelected is called by the MatchTable when tryMatch returns a non-null result.
abstract  java.lang.Object tryMatch(java.lang.Object data)
          tryMatch attempts to match against the pattern, returning null if the match fails and some non-null object (such as a MatchEnv) if the match succeeds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pattern

protected java.lang.Object pattern
An object to match against.

Constructor Detail

MatchCase

public MatchCase()
Method Detail

getPattern

public java.lang.Object getPattern()
getPattern returns this MatchCase's pattern.


tryMatch

public abstract java.lang.Object tryMatch(java.lang.Object data)
tryMatch attempts to match against the pattern, returning null if the match fails and some non-null object (such as a MatchEnv) if the match succeeds.


ifSelected

public java.lang.Object ifSelected(java.lang.Object data,
                                   java.lang.Object matchResult)
ifSelected is called by the MatchTable when tryMatch returns a non-null result. The object that was matched, and the non-null match result, are passed as arguments to ifSelected. The method provided here simply returns the same match result.