package de.ugoe.cs.autoquest.tasktrees.nodeequality; import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; /** *
* This class is capable of comparing Iterations. Iterations equal at distinct levels
* in distinct situations. The following table shows the results of the comparison for the
* specific situations (the parameters are commutative). In any other situation, the comparison
* returns NodeEquality.UNEQUAL
:
*
iteration 1 | *iteration 2 | *comparison result | *
---|---|---|
any iteration | *any iteration with a child that is lexically equal to the child of iteration 1 | *NodeEquality.LEXICALLY_EQUAL |
*
any iteration | *any iteration with a child that is syntactically equal to the child of iteration 1 | *NodeEquality.SYNTACTICALLY_EQUAL |
*
any iteration | *any iteration with a child that is semantically equal to the child of iteration 1 | *NodeEquality.SEMANTICALLY_EQUAL |
*
an iteration with a selection of syntactically equal children | *an iteration with a child that is syntactically equal to the children of the child * selection of iteration 1 | *NodeEquality.SYNTACTICALLY_EQUAL |
*
an iteration with a selection of syntactically equal children | *an iteration with a selection of syntactically equal children that are all syntactically * equal to the selection of children of iteration 1 | *NodeEquality.SYNTACTICALLY_EQUAL |
*
an iteration with a selection of semantically equal children | *an iteration with a child that is semantically equal to the children of the child * selection of iteration 1 | *NodeEquality.SEMANTICALLY_EQUAL |
*
an iteration with a selection of semantically equal children | *an iteration with a selection of semantically equal children that are all semantically * equal to the selection of children of iteration 1 | *NodeEquality.SEMANTICALLY_EQUAL |
*
* simple constructor to provide the rule with the node equality rule manager to be able * to perform comparisons of the children of provided task tree nodes *
* * @param ruleManager the rule manager for comparing task tree nodes */ IterationComparisonRule(NodeEqualityRuleManager ruleManager) { super(); mRuleManager = ruleManager; } /* * (non-Javadoc) * * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) */ @Override public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { if ((!(node1 instanceof IIteration)) || (!(node2 instanceof IIteration))) { return null; } if (node1 == node2) { return NodeEquality.IDENTICAL; } // if both iterations do not have children, they are equal although this doesn't make sense if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { return NodeEquality.LEXICALLY_EQUAL; } else if ((node1.getChildren().size() == 0) || (node2.getChildren().size() == 0)) { return NodeEquality.UNEQUAL; } ITaskTreeNode child1 = node1.getChildren().get(0); ITaskTreeNode child2 = node2.getChildren().get(0); // iterations may have 3 different structures. // 1. they have one child, which is the iterated one // 2. they have a sequence of children, which is iterated // 3. they have a selection of different iterated variants (usually the variants are // semantically equal) // // the permutations of the three variants in combination must be checked // check if both nodes are the same variants of iterations and if their children are equal. // This condition matches, if both iterations are the same variants of iteration. I.e. three // combinations of the permutation are handled herewith. NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { // prevent, that identical is returned, because the iterations itself are not identical // although the iterated tasks are if (nodeEquality == NodeEquality.IDENTICAL) { return NodeEquality.LEXICALLY_EQUAL; } else { return nodeEquality; } } // compare one iteration with a single node as a child and another one with a selection of // semantically equal nodes return selectionChildrenSemanticallyEqualNode(child1, child2); // all other combinations (i.e. sequence with single child and sequence with selection) // can not match } /** *
* compares two task tree nodes. One of them must be a selection, the other one can be any task
* tree node. The method returns a node equality that is not NodeEquality.UNEQUAL
* if the other node is at least semantically equal to the children of the selection. It
* returns more concrete equalities, if the equality between the other node and the children
* of the selection is more concrete.
*