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
}
|
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 |
condition
protected BooleanTerm condition
ifCommand
protected Command ifCommand
elseCommand
protected Command elseCommand
IfCommand
public IfCommand(BooleanTerm condition,
Command ifCommand)
- Construct an "if" command from the given condition and
command.
- Parameters:
condition - the condition to checkifCommand - 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 checkifCommand - the command to execute if the
condition evaluates to trueelseCommand - the command to execute if the
condition evaluates to false
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