org.problets.domain.model.control.selection
Class SwitchModel

java.lang.Object
  extended by org.problets.domain.model.DomainModel
      extended by org.problets.domain.model.control.ControlModel
          extended by org.problets.domain.model.control.ConditionControl
              extended by org.problets.domain.model.control.selection.Selection
                  extended by org.problets.domain.model.control.selection.SwitchModel
All Implemented Interfaces:
java.lang.Cloneable

public class SwitchModel
extends Selection

Class: SwitchModel Purpose: Provides procedures to parse the switch cases and get the statement sequence by calling CaseModel. This class is also responsible for generating code and running the model


Field Summary
static int IDENTITY
           
 
Fields inherited from class org.problets.domain.model.control.ConditionControl
INCORRECT_TYPE
 
Fields inherited from class org.problets.domain.model.control.ControlModel
ABORT_EXECUTION, BREAK_EXECUTION, CONTINUE_EXECUTION, END_EXECUTION, INFINITE_EXECUTION, RETURN_EXECUTION, RUN_TIME_ERROR_EXECUTION, SKIP_EXECUTION
 
Fields inherited from class org.problets.domain.model.DomainModel
BOOLEAN, BREAKPOINT, CHARACTER, DOUBLE_PRECISION_REAL, ERROR_TYPE, EVAL_STATUS, expACTION, expASSIGNMENT, expAUTO_DEALLOCATION, expCALL, expCONDITION, expDECLARATION, expDEREFERENCING, expDYNAMIC_ALLOCATION, expDYNAMIC_ALLOCATION_INITIALIZATION, expDYNAMIC_DEALLOCATION, expELSE_CLAUSE, expERROR, expEXECUTION, expIF_CLAUSE, expINITIALIZATION, expINPUT, expPARAMETER_PASSING, expPRINT, expQUESTIONABLE, expREFERENCING, expRETURN, expRUNTIME_ERROR, expSEMANTIC_ERROR, expSYNTAX_ERROR, expUPDATE, MAX_OBJECT_IDENTITY, MIN_OBJECT_IDENTITY, QUADRUPLE_PRECISION_REAL, RUNTIME_ERROR, SEMANTIC_ERROR, SIGNED_INTEGER, SIGNED_LONG, SIGNED_SHORT, SINGLE_PRECISION_REAL, SYNTAX_ERROR, UNDEFINED_TYPE, UNSIGNED_INTEGER, UNSIGNED_LONG, UNSIGNED_SHORT, WARNING
 
Constructor Summary
SwitchModel(ActivationRecord parent, HeapModel heap, java.lang.String in_template)
          Constructor
 
Method Summary
 ExecutionStatus explainProcess(RunEnv runEnv, Behavior behavior, boolean stepFlag)
          public int explainProcess( RunEnv runEnv, Behavior behavior, boolean stepFlag) Extracts the cases from the caseVector and sends it to the explainProcess of CaseModel so that CaseModel can explain the case.
 void getCode(java.util.Vector codeText, OutputStream output)
          public void getCode(Vector codeText, OutputStream output) Generate the Switch clause and display it on the screen
 java.lang.String getNestedSwitchStatement(java.lang.String switchBody, int indexFinder)
          public void getNestedSwitchStatement(switchBody, indexFinder) Parses nested Switch clause within the main switch
static boolean grade(java.lang.String template, java.lang.String studentCode)
          Grade is used for checking student's code compared to the actual code.
static boolean gradeOld(java.lang.String template, java.lang.String studentCode)
          Grade is used for checking student's code compared to the actual code.
 java.util.Vector postProcessStatements(java.lang.String template)
          Post-processes the result of TemplateParser.getNextStatement() to correctly handle case, default, and nested switch statements
 
Methods inherited from class org.problets.domain.model.control.selection.Selection
main
 
Methods inherited from class org.problets.domain.model.control.ConditionControl
getPossibleErrors
 
Methods inherited from class org.problets.domain.model.control.ControlModel
getCodeLength, getName, getStartLineNumber
 
Methods inherited from class org.problets.domain.model.DomainModel
clone, getId, getIdName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDENTITY

public static final int IDENTITY
See Also:
Constant Field Values
Constructor Detail

SwitchModel

public SwitchModel(ActivationRecord parent,
                   HeapModel heap,
                   java.lang.String in_template)
Constructor

Parameters:
parent - - the nested scope's parent activation record
heap - - the heap to be used
in_template - - the template to be parsed
Method Detail

postProcessStatements

public java.util.Vector postProcessStatements(java.lang.String template)
Post-processes the result of TemplateParser.getNextStatement() to correctly handle case, default, and nested switch statements

Parameters:
template - - complete switch template to be parsed
Returns:
vector of parsed statements from the switch

getNestedSwitchStatement

public java.lang.String getNestedSwitchStatement(java.lang.String switchBody,
                                                 int indexFinder)
public void getNestedSwitchStatement(switchBody, indexFinder) Parses nested Switch clause within the main switch

Parameters:
switchBody - - Current template for the switch clause
indexFinder - - Starting location of the nested switch
Returns:
Nested switch statement as a String

getCode

public void getCode(java.util.Vector codeText,
                    OutputStream output)
public void getCode(Vector codeText, OutputStream output) Generate the Switch clause and display it on the screen

Overrides:
getCode in class ControlModel
Parameters:
codeText - - a Vector that holds the code
output - - For outputting the code on the screen

explainProcess

public ExecutionStatus explainProcess(RunEnv runEnv,
                                      Behavior behavior,
                                      boolean stepFlag)
public int explainProcess( RunEnv runEnv, Behavior behavior, boolean stepFlag) Extracts the cases from the caseVector and sends it to the explainProcess of CaseModel so that CaseModel can explain the case. Only one case is sent to CaseModel explainProcess().

Overrides:
explainProcess in class ControlModel
Parameters:
runEnv - - Run Environment of the program
behavior - - behavior of the program
stepFlag - - execution flag
Returns:
status of the program

grade

public static boolean grade(java.lang.String template,
                            java.lang.String studentCode)
Grade is used for checking student's code compared to the actual code.


gradeOld

public static boolean gradeOld(java.lang.String template,
                               java.lang.String studentCode)
Grade is used for checking student's code compared to the actual code. - grade() supersedes this.