org.problets.domain.model.expression.node.operand
Class VarOperand

java.lang.Object
  extended by org.problets.domain.model.DomainModel
      extended by org.problets.domain.model.expression.node.NodeModel
          extended by org.problets.domain.model.expression.node.operand.Operand
              extended by org.problets.domain.model.expression.node.operand.VarOperand
All Implemented Interfaces:
java.lang.Cloneable, Assignable

public class VarOperand
extends Operand
implements Assignable

VarOperand To hold a variable operand

Author:
Amruth Kumar

Field Summary
 
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, IDENTITY, 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
VarOperand(AbstractVarModel inValue)
           
 
Method Summary
 boolean canAssign()
          Returns whether this node is assignable
 Value evaluate()
          This overrides the method declared in NodeModel - and always returns the original value of the variable
 void explain(java.util.Vector explanation, java.util.Vector errors)
          Base Method to be overridden by those of Operand and Operator
 AbstractVarModel getClone()
          Returns a clone of the variable that is this operand for purposes of re-creating the current expression as student's attempted answer in StudentNodeView.
 Value getValue()
          This overrides the method declared in NodeModel - and always returns the value of the variable's clone.
 AbstractVarModel getVarReference()
          Returns a reference to the variable that is this operand.
 boolean grade(java.lang.String actualTemplate, java.lang.String studentCode, java.util.Vector explanation)
          Grades the studentCode according to the actualTemplate, returns true if correct, and false otherwise
static void main(java.lang.String[] args)
           
 void setVarValue(Value inValue)
          Sets the value of the variable which is this operand.
 
Methods inherited from class org.problets.domain.model.expression.node.NodeModel
classifyNodes, clone, contentEquals, contentEquals, getContent, getLeftChild, getNonRecursiveContent, getOrder, getPosition, getRecursiveContent, getRightChild, getSideEffects, getStudentCopy, insertInOrder, recursiveSetValue, setLeftChild, setOrder, setPosition, setRightChild, setValue, shortCircuit, skip, subExpToString, toString, valueEquals
 
Methods inherited from class org.problets.domain.model.DomainModel
getId, getIdName, grade
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VarOperand

public VarOperand(AbstractVarModel inValue)
Method Detail

getVarReference

public AbstractVarModel getVarReference()
Returns a reference to the variable that is this operand. Do not directly reference the variable returned by this function as part of any expression evaluation - use getValue() instead. Feel free to set the value of the variable returned by this function.

Specified by:
getVarReference in interface Assignable

getClone

public AbstractVarModel getClone()
Returns a clone of the variable that is this operand for purposes of re-creating the current expression as student's attempted answer in StudentNodeView. By design, this is the clone of varClone, not varReference, which may have already changed its value in the actual expression due to assignment.

Specified by:
getClone in interface Assignable

getValue

public Value getValue()
This overrides the method declared in NodeModel - and always returns the value of the variable's clone. The scheme is to have VarOperand always return the clone's value, so that the value of the variable at the time of the creation of the expression is returned, rather than its value after the execution of the expression. If a VarOperand's value is set, the varReference's value will be set, not varClone's value.

Overrides:
getValue in class NodeModel

canAssign

public boolean canAssign()
Returns whether this node is assignable

Specified by:
canAssign in interface Assignable

setVarValue

public void setVarValue(Value inValue)
Sets the value of the variable which is this operand. Use this always to set the value of the variable

Specified by:
setVarValue in interface Assignable

grade

public boolean grade(java.lang.String actualTemplate,
                     java.lang.String studentCode,
                     java.util.Vector explanation)
Grades the studentCode according to the actualTemplate, returns true if correct, and false otherwise

Overrides:
grade in class Operand

evaluate

public Value evaluate()
This overrides the method declared in NodeModel - and always returns the original value of the variable

Overrides:
evaluate in class NodeModel

explain

public void explain(java.util.Vector explanation,
                    java.util.Vector errors)
Description copied from class: NodeModel
Base Method to be overridden by those of Operand and Operator

Overrides:
explain in class NodeModel

main

public static void main(java.lang.String[] args)