Building Parsers with Java

sjm.imperative
Class IfCommand

java.lang.Object
  |
  +--sjm.imperative.Command
        |
        +--sjm.imperative.IfCommand

public class IfCommand
extends Command

This command mimics a normal "if" statement, such as:


     if (x > 7) {
         // body to execute if condition is true
     } else {
         // body to execute if condition is false
     }
 


Field Summary
protected  BooleanTerm condition
           
protected  Command elseCommand
           
protected  Command ifCommand
           
 
Constructor Summary
IfCommand(BooleanTerm condition, Command ifCommand)
          Construct an "if" command from the given condition and command.
IfCommand(BooleanTerm condition, Command ifCommand, Command elseCommand)
          Construct an "if" command from the given condition and command.
 
Method Summary
 void execute()
          Execute this "if" command.
 java.lang.String toString()
          Returns a string description of this if command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

condition

protected BooleanTerm condition

ifCommand

protected Command ifCommand

elseCommand

protected Command elseCommand
Constructor Detail

IfCommand

public IfCommand(BooleanTerm condition,
                 Command ifCommand)
Construct an "if" command from the given condition and command.
Parameters:
condition - the condition to check
ifCommand - the command to execute if the condition evaluates to true

IfCommand

public IfCommand(BooleanTerm condition,
                 Command ifCommand,
                 Command elseCommand)
Construct an "if" command from the given condition and command.
Parameters:
condition - the condition to check
ifCommand - the command to execute if the condition evaluates to true
elseCommand - the command to execute if the condition evaluates to false
Method Detail

execute

public void execute()
Execute this "if" command. Evaluate the condition. If it is true, execute this object's ifCommand. Otherwise, execute the elseCommand, which may be a NullCommand object.
Overrides:
execute in class Command

toString

public java.lang.String toString()
Returns a string description of this if command.
Overrides:
toString in class java.lang.Object
Returns:
a string description of this if command

by Steve Metsker