net.sf.parcinj
Class Alternative<P extends Processor>

java.lang.Object
  extended by net.sf.parcinj.AbstractSymbol<P>
      extended by net.sf.parcinj.Alternative<P>
All Implemented Interfaces:
Symbol<P>

public class Alternative<P extends Processor>
extends AbstractSymbol<P>

Compound symbol which contains several Symbols. The symbol which matches will be processed.


Field Summary
protected  java.util.List<Symbol<P>> _symbols
           
 
Constructor Summary
Alternative()
          Creates an instance without any symbol.
Alternative(Symbol<P> symbol)
          Creates an instance with one symbol.
 
Method Summary
 void addSymbol(Symbol<P> symbol)
          Adds the specified symbol.
 void doProcess(TokenIterator iterator, P processor)
          Processes the current token of the specified iterator by the first matching symbol.
 MatchingResult matches(Token token)
          Returns MatchingResult.OK if at least one symbol matches the specified token.
 AbstractSymbol<P> or(Symbol<P> symbol)
          Appends the specified symbol.
 
Methods inherited from class net.sf.parcinj.AbstractSymbol
followedBy, oneOrMoreTimes, optional, process, zeroOrMoreTimes, zeroOrMoreTimesSeparatedBy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_symbols

protected final java.util.List<Symbol<P extends Processor>> _symbols
Constructor Detail

Alternative

public Alternative()
Creates an instance without any symbol.


Alternative

public Alternative(Symbol<P> symbol)
Creates an instance with one symbol.

Method Detail

or

public AbstractSymbol<P> or(Symbol<P> symbol)
Appends the specified symbol.

Specified by:
or in interface Symbol<P extends Processor>
Overrides:
or in class AbstractSymbol<P extends Processor>
Returns:
this.

matches

public MatchingResult matches(Token token)
Returns MatchingResult.OK if at least one symbol matches the specified token. If no symbol matches the list of failure reasons are returned.

Parameters:
token - Token to be checked. Will be null if beyond last token.

doProcess

public void doProcess(TokenIterator iterator,
                      P processor)
Processes the current token of the specified iterator by the first matching symbol.

Specified by:
doProcess in class AbstractSymbol<P extends Processor>
processor - Processor who does the actual processing.

addSymbol

public void addSymbol(Symbol<P> symbol)
Adds the specified symbol.