cdx.scorebot.scoring.logic
Class IfStatement

java.lang.Object
  extended by cdx.scorebot.scoring.logic.IfStatement
All Implemented Interfaces:
LogicCode, LogicCodeExecutable, StatementType

public class IfStatement
extends java.lang.Object
implements LogicCodeExecutable, StatementType

evaluates an if statement

Author:
David Underhill

Constructor Summary
IfStatement(ConditionalOrExpression condition, Statement ifBody)
          instantiate an if statement
IfStatement(ConditionalOrExpression condition, Statement ifBody, Statement elseBody)
          instantiate an if-else statement
 
Method Summary
 void executeLogic(Context context)
          process this logic code in the specified context
 void validateTypes(java.util.HashMap<java.lang.String,LiteralType> varTypes, java.util.HashMap<java.lang.String,TestData> testsInfo)
          Attempts to validate the type-correctness of all constituent LogicCodeEvaluatable logic code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IfStatement

public IfStatement(ConditionalOrExpression condition,
                   Statement ifBody)
instantiate an if statement

Parameters:
condition - the condition
ifBody - the statement to execute if the condition is true

IfStatement

public IfStatement(ConditionalOrExpression condition,
                   Statement ifBody,
                   Statement elseBody)
instantiate an if-else statement

Parameters:
condition - the condition
ifBody - the statement to execute if the condition is true
elseBody - the statement to execute if the condition is false
Method Detail

executeLogic

public void executeLogic(Context context)
                  throws LogicException
process this logic code in the specified context

Specified by:
executeLogic in interface LogicCodeExecutable
Parameters:
context - contains the current context of the logic processor
Throws:
TypeMismatchException - thrown if the condition does not evaluate to a literal boolean value
LogicException - thrown if an exception occurs while processing the logic

validateTypes

public void validateTypes(java.util.HashMap<java.lang.String,LiteralType> varTypes,
                          java.util.HashMap<java.lang.String,TestData> testsInfo)
                   throws LogicException
Description copied from interface: LogicCodeExecutable
Attempts to validate the type-correctness of all constituent LogicCodeEvaluatable logic code. An exception is thrown if there is some type-check failure.

Specified by:
validateTypes in interface LogicCodeExecutable
Parameters:
varTypes - contains the type of value stored by each variable (variables names are keys)
testsInfo - information about each test item keyed on test item names this logic may hold
Throws:
LogicException - thrown if an exception if an invalid test, test result, or test option is found