org.qtitools.qti.node.expression.operator
Class Index

java.lang.Object
  extended by org.qtitools.qti.node.AbstractNode
      extended by org.qtitools.qti.node.AbstractObject
          extended by org.qtitools.qti.node.expression.AbstractExpression
              extended by org.qtitools.qti.node.expression.operator.Index
All Implemented Interfaces:
java.io.Serializable, Expression, ExpressionParent, XmlNode, XmlObject, Validatable

public class Index
extends AbstractExpression

The index operator takes A sub-expression with an ordered container value and any base-type. The result is the nth value of the container. The result has the same base-type as the sub-expression but single cardinality. The first value of A container has index 1, the second 2 and so on. N must be A positive integer. If n exceeds the number of values in the container or the sub-expression is NULL then the result of the index operator is NULL.

Author:
Jiri Kajaba
See Also:
Cardinality, BaseType, Serialized Form

Field Summary
static java.lang.String ATTR_INDEX_NAME
          Name of n attribute in xml schema.
static java.lang.String CLASS_TAG
          Name of this class in xml schema.
 
Fields inherited from class org.qtitools.qti.node.expression.AbstractExpression
logger
 
Fields inherited from interface org.qtitools.qti.node.expression.Expression
DISPLAY_NAME
 
Fields inherited from interface org.qtitools.qti.node.XmlNode
INDENT, NEW_LINE, SIMPLE_NAME_INNER_SEPARATOR, SIMPLE_NAMES_SEPARATOR
 
Constructor Summary
Index(ExpressionParent parent)
          Constructs expression.
 
Method Summary
protected  Value evaluateSelf(int depth)
          Evaluates this expression.
 java.lang.String getClassTag()
          Gets QTI class name of this node.
 java.lang.Integer getIndex()
          Gets value of n attribute.
 BaseType[] getProducedBaseTypes()
          Gets list of all possible produced baseTypes after evaluation (possible baseTypes of evaluated result).
 BaseType[] getRequiredBaseTypes(int index)
          Gets list of all acceptable baseTypes which can child expression at given position produce.
 void setIndex(java.lang.Integer index)
          Sets new value of n attribute.
protected  ValidationResult validateAttributes()
          Validates attributes of this node.
 
Methods inherited from class org.qtitools.qti.node.expression.AbstractExpression
evaluate, getBaseType, getCardinality, getChildren, getFirstChild, getParent, getParentRequiredBaseTypes, getParentRequiredCardinalities, getProducedCardinalities, getProducedNumericalBaseTypes, getRequiredCardinalities, getRequiredSameBaseTypes, getRequiredSameCardinalities, getSecondChild, getType, getValue, isAnyChildNull, isNull, isVariable, reset, toString, validate
 
Methods inherited from class org.qtitools.qti.node.AbstractObject
getParentItem, getParentResult, getParentTest, setParent
 
Methods inherited from class org.qtitools.qti.node.AbstractNode
attrToXmlString, bodyToXmlString, getAttributes, getFullName, getIndent, getNode, getNode, getNode, getNodeGroups, getParentRoot, getSimpleName, getSourceFile, getSourceNode, getSourceString, getSourceUrl, hasChildNodes, load, load, load, load, loadAttributes, readChild, readChildren, setParent, setSourceFile, setSourceNode, setSourceString, setSourceUrl, toXmlString, toXmlString, validateChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.qtitools.qti.node.XmlObject
getParentItem, getParentResult, getParentTest, setParent
 
Methods inherited from interface org.qtitools.qti.node.XmlNode
getAttributes, getFullName, getNodeGroups, getParentRoot, getSimpleName, getSourceFile, getSourceNode, getSourceString, getSourceUrl, hasChildNodes, load, load, load, load, setSourceFile, setSourceNode, setSourceString, setSourceUrl, toXmlString, toXmlString
 

Field Detail

CLASS_TAG

public static final java.lang.String CLASS_TAG
Name of this class in xml schema.

See Also:
Constant Field Values

ATTR_INDEX_NAME

public static final java.lang.String ATTR_INDEX_NAME
Name of n attribute in xml schema.

See Also:
Constant Field Values
Constructor Detail

Index

public Index(ExpressionParent parent)
Constructs expression.

Parameters:
parent - parent of this expression
Method Detail

getClassTag

public java.lang.String getClassTag()
Description copied from interface: XmlNode
Gets QTI class name of this node.

QTI class name has very important role during loading/saving nodes.

For example: Java class name is AssessmentTest; QTI class name is assessmentTest.

Specified by:
getClassTag in interface XmlNode
Specified by:
getClassTag in class AbstractNode
Returns:
QTI class name of this node

getIndex

public java.lang.Integer getIndex()
Gets value of n attribute.

Returns:
value of n attribute
See Also:
setIndex(java.lang.Integer)

setIndex

public void setIndex(java.lang.Integer index)
Sets new value of n attribute.

Parameters:
index - new value of n attribute
See Also:
getIndex()

getRequiredBaseTypes

public BaseType[] getRequiredBaseTypes(int index)
Description copied from interface: ExpressionParent
Gets list of all acceptable baseTypes which can child expression at given position produce.

Result of this method can change in time.

Static example is expression or. Expression or accepts only boolean baseType for any index.

Dynamic example is expression match. Expression match accepts any baseType of its children. but this baseType must be same for all its children.

Specified by:
getRequiredBaseTypes in interface ExpressionParent
Overrides:
getRequiredBaseTypes in class AbstractExpression
Parameters:
index - position of child expression in this parent
Returns:
list of all acceptable baseTypes which can child expression at given position produce

getProducedBaseTypes

public BaseType[] getProducedBaseTypes()
Description copied from interface: Expression
Gets list of all possible produced baseTypes after evaluation (possible baseTypes of evaluated result). Result of this method can change in time.

Static example is expression or. Expression or can produce only boolean baseType and it cannot change.

Dynamic example is expression variable. Expression variable can produce any baseType before evaluation. After evaluation it produces baseType of its result (and it can change every evaluation call!).

Null expression, empty containers (multiple, ordered, record), or NULL values produces all baseTypes. So they are compatible with anything.

Specified by:
getProducedBaseTypes in interface Expression
Overrides:
getProducedBaseTypes in class AbstractExpression
Returns:
list of all possible produced baseTypes after evaluation

validateAttributes

protected ValidationResult validateAttributes()
Description copied from class: AbstractNode
Validates attributes of this node.

Overrides:
validateAttributes in class AbstractNode
Returns:
result of validation

evaluateSelf

protected Value evaluateSelf(int depth)
Description copied from class: AbstractExpression
Evaluates this expression. All children must be already evaluated. Contains no checks.

Specified by:
evaluateSelf in class AbstractExpression
Parameters:
depth - depth of this expression in expression tree (root's depth = 0)
Returns:
result of evaluation


Copyright © 2009. All Rights Reserved.