public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull()) {
            return null;
        }

        if ($operands->exclusivelyOrdered() === false) {
            $msg = "The Index operator only accepts values with a cardinality of ordered.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        $n = $this->getExpression()->getN();
        if (gettype($n) === 'string') {
            // The value of $n comes from the state.
            $state = $this->getState();
            if (($index = $state[ProcessingUtils::sanitizeVariableRef($n)]) !== null) {
                if ($index instanceof QtiInteger) {
                    $n = $index->getValue();
                } else {
                    $msg = "The value '${index}' is not an integer. Ordered containers can be only accessed by integers.";
                    throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
                }
            } else {
                $msg = "Unknown variable reference '${n}'.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
            }
        }

        if ($n < 1) {
            $msg = "The value of 'n' must be a non-zero postive integer, '${n}' given.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR);
        }

        $n = $n - 1; // QTI indexes begin at 1...
        if ($n > count($operands[0]) - 1) {
            // As per specs, if n exceeds the number of values in the container,
            // the result of the index operator is NULL.
            return null;
        }

        return $operands[0][$n];
    }