- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- Location:
- trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality
- Files:
-
- 4 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/IterationComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;11 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 * TODO comment 14 * <p> 15 * This class is capable of comparing Iterations. Iterations equal at distinct levels 16 * in distinct situations. The following table shows the results of the comparison for the 17 * specific situations (the parameters are commutative). In any other situation, the comparison 18 * returns <code>NodeEquality.UNEQUAL</code>: 19 * </p> 20 * 21 * <table border="1"> 22 * <tr> 23 * <th>iteration 1</th> 24 * <th>iteration 2</th> 25 * <th>comparison result</th> 26 * </tr> 27 * <tr> 28 * <td>any iteration</td> 29 * <td>any iteration with a child that is lexically equal to the child of iteration 1</td> 30 * <td><code>NodeEquality.LEXICALLY_EQUAL</code></td> 31 * </tr> 32 * <tr> 33 * <td>any iteration</td> 34 * <td>any iteration with a child that is syntactically equal to the child of iteration 1</td> 35 * <td><code>NodeEquality.SYNTACTICALLY_EQUAL</code></td> 36 * </tr> 37 * <tr> 38 * <td>any iteration</td> 39 * <td>any iteration with a child that is semantically equal to the child of iteration 1</td> 40 * <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 41 * </tr> 42 * <tr> 43 * <td>an iteration with a selection of syntactically equal children</td> 44 * <td>an iteration with a child that is syntactically equal to the children of the child 45 * selection of iteration 1</td> 46 * <td><code>NodeEquality.SYNTACTICALLY_EQUAL</code></td> 47 * </tr> 48 * <tr> 49 * <td>an iteration with a selection of semantically equal children</td> 50 * <td>an iteration with a child that is semantically equal to the children of the child 51 * selection of iteration 1</td> 52 * <td><code>NodeEquality.SEMANTICALLY_EQUAL</code></td> 53 * </tr> 54 * </table> 17 55 * 18 56 * @version $Revision: $ $Date: 19.02.2012$ 19 57 * @author 2012, last modified by $Author: patrick$ 20 58 */ 21 //------------------------------------------------------------------------------------------------- 22 public class IterationComparisonRule implements NodeComparisonRule 23 { 24 /** */ 25 private NodeEqualityRuleManager mRuleManager; 59 public class IterationComparisonRule implements NodeComparisonRule { 60 61 /** the rule manager for internally comparing task tree nodes */ 62 private NodeEqualityRuleManager mRuleManager; 26 63 27 //----------------------------------------------------------------------------------------------- 28 /** 29 * TODO: comment 30 * 31 */ 32 //----------------------------------------------------------------------------------------------- 33 IterationComparisonRule(NodeEqualityRuleManager ruleManager) 34 { 35 super(); 36 mRuleManager = ruleManager; 37 } 38 39 //----------------------------------------------------------------------------------------------- 40 /* (non-Javadoc) 41 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 42 */ 43 //----------------------------------------------------------------------------------------------- 44 @Override 45 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 46 { 47 if ((!(node1 instanceof Iteration)) || (!(node2 instanceof Iteration))) 48 { 49 return null; 50 } 51 52 // if both iterations do not have children, they are equal although this doesn't make sense 53 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) 54 { 55 return new NodesIdentical(); 56 } 57 58 TaskTreeNode child1 = node1.getChildren().get(0); 59 TaskTreeNode child2 = node2.getChildren().get(0); 60 61 // iterations may have 3 different structures. 62 // 1. they have one child, which is the iterated one 63 // 2. they have a sequence of children, which is iterated 64 // 3. they have a selection of different iterated variants (usually the variants are 65 // semantically equal) 66 // 67 // the permutations of the three variants in combination must be checked 68 69 // check if both nodes are the same variants of iterations and if their children are equal. 70 // This condition matches, if both iterations are the same variants of iteration. I.e. three 71 // combinations of the permutation are handled herewith. 72 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 73 74 if (nodeEquality.getStructuralEquality() || nodeEquality.getSemanticalEquality()) 75 { 76 return nodeEquality; 77 } 78 79 // compare one iteration with a single node as a child and another one with a selection of 80 // semantically equal nodes 81 if (selectionChildrenSemanticallyEqualNode(child1, child2)) 82 { 83 return new NodesSemanticallyEqual(); 64 /** 65 * <p> 66 * simple constructor to provide the rule with the node equality rule manager to be able 67 * to perform comparisons of the children of provided task tree nodes 68 * </p> 69 * 70 * @param ruleManager the rule manager for comparing task tree nodes 71 */ 72 IterationComparisonRule(NodeEqualityRuleManager ruleManager) { 73 super(); 74 mRuleManager = ruleManager; 84 75 } 85 76 86 // all other combinations (i.e. sequence with single child and sequence with selection) 87 // can not match 88 return null; 89 } 77 /* 78 * (non-Javadoc) 79 * 80 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 81 */ 82 @Override 83 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 84 if ((!(node1 instanceof IIteration)) || (!(node2 instanceof IIteration))) { 85 return null; 86 } 90 87 91 //----------------------------------------------------------------------------------------------- 92 /** 93 * TODO: comment 94 * 95 * @param taskTreeNode 96 * @param taskTreeNode2 97 * @return 98 */ 99 //----------------------------------------------------------------------------------------------- 100 private boolean selectionChildrenSemanticallyEqualNode(TaskTreeNode taskTreeNode, 101 TaskTreeNode taskTreeNode2) 102 { 103 Selection selection = null; 104 TaskTreeNode node = null; 105 if (taskTreeNode instanceof Selection) 88 // if both iterations do not have children, they are equal although this doesn't make sense 89 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 90 return NodeEquality.IDENTICAL; 91 } 92 93 ITaskTreeNode child1 = node1.getChildren().get(0); 94 ITaskTreeNode child2 = node2.getChildren().get(0); 95 96 // iterations may have 3 different structures. 97 // 1. they have one child, which is the iterated one 98 // 2. they have a sequence of children, which is iterated 99 // 3. they have a selection of different iterated variants (usually the variants are 100 // semantically equal) 101 // 102 // the permutations of the three variants in combination must be checked 103 104 // check if both nodes are the same variants of iterations and if their children are equal. 105 // This condition matches, if both iterations are the same variants of iteration. I.e. three 106 // combinations of the permutation are handled herewith. 107 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 108 109 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 110 return nodeEquality; 111 } 112 113 // compare one iteration with a single node as a child and another one with a selection of 114 // semantically equal nodes 115 return selectionChildrenSemanticallyEqualNode(child1, child2); 116 117 // all other combinations (i.e. sequence with single child and sequence with selection) 118 // can not match 119 } 120 121 /** 122 * <p> 123 * compares two task tree nodes. One of them must be a selection of at least semantically 124 * equal children. The other one can be any task tree node. The method returns a node equality 125 * that is not <code>NodeEquality.UNEQUAL</code> if the other node is at least semantically 126 * equal to the children of the selection. It returns more concrete equalities, if the 127 * equality between the other node and the children of the selection is more concrete. 128 * </p> 129 * 130 * @param taskTreeNode the first task tree node to compare 131 * @param taskTreeNode2 the second task tree node to compare 132 * 133 * @return as described 134 */ 135 private NodeEquality selectionChildrenSemanticallyEqualNode(ITaskTreeNode taskTreeNode, 136 ITaskTreeNode taskTreeNode2) 106 137 { 107 selection = (Selection) taskTreeNode; 108 node = taskTreeNode2; 138 ISelection selection = null; 139 ITaskTreeNode node = null; 140 if (taskTreeNode instanceof ISelection) { 141 selection = (ISelection) taskTreeNode; 142 node = taskTreeNode2; 143 } 144 else if (taskTreeNode2 instanceof ISelection) { 145 selection = (ISelection) taskTreeNode2; 146 node = taskTreeNode; 147 } 148 else { 149 return NodeEquality.UNEQUAL; 150 } 151 152 NodeEquality lessConcreteEqualityForAllComparisons = NodeEquality.IDENTICAL; 153 154 for (ITaskTreeNode child : selection.getChildren()) { 155 NodeEquality nodeEquality = mRuleManager.applyRules(node, child); 156 157 if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 158 return NodeEquality.UNEQUAL; 159 } 160 else if (!lessConcreteEqualityForAllComparisons.isAtLeast(nodeEquality)) { 161 lessConcreteEqualityForAllComparisons = nodeEquality; 162 } 163 } 164 165 return lessConcreteEqualityForAllComparisons; 109 166 } 110 else if (taskTreeNode2 instanceof Selection)111 {112 selection = (Selection) taskTreeNode2;113 node = taskTreeNode;114 }115 else116 {117 return false;118 }119 120 for (TaskTreeNode child : selection.getChildren())121 {122 NodeEquality nodeEquality = mRuleManager.applyRules(node, child);123 124 if (!nodeEquality.getStructuralEquality() && !nodeEquality.getSemanticalEquality())125 {126 return false;127 }128 }129 130 return true;131 }132 167 133 168 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: EqualityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 * TODO comment 12 * <p> 13 * A node comparison rule is used by the {@link NodeEqualityRuleManager} to compare task tree 14 * nodes with each other. It provides one method to be called for a comparison. 15 * </p> 15 16 * 16 17 * @version $Revision: $ $Date: 19.02.2012$ 17 18 * @author 2012, last modified by $Author: patrick$ 18 19 */ 19 //------------------------------------------------------------------------------------------------- 20 public interface NodeComparisonRule 21 { 20 public interface NodeComparisonRule { 22 21 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * compares two nodes with each other. The result of the method is either a node equality or 26 * null. If it is null, it means, that the rule is not able to correctly compare the two 27 * given nodes 28 */ 29 //----------------------------------------------------------------------------------------------- 30 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2); 31 22 /** 23 * <p> 24 * compares two nodes with each other. The result of the method is either a node equality or 25 * null. If it is null, it means, that the rule is not able to correctly compare the two given 26 * nodes 27 * </p> 28 * 29 * @param node1 the first task tree node to compare 30 * @param node2 the second task tree node to compare 31 * 32 * @return as described 33 */ 34 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2); 35 32 36 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEquality.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeEquality.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 * TODO comment 10 * <p> 11 * A node equality denotes, how equal two task tree nodes are. There are different equality levels 12 * which are similar to the usual design levels of GUI design. These levels are 13 * <ul> 14 * <li>conceptual design: defines the concepts to be edited using a GUI</li> 15 * <li>semantical design: defines the possible functions for editing the concepts</li> 16 * <li>syntactical design: defines, which steps are needed to execute the functions</li> 17 * <li>lexical design: defines on the key stroke level, how the steps for executing a function 18 * can be performed</li> 19 * </ul> 20 * It is not possible to compare two task nodes conceptually. But the other design levels can be 21 * identified and compared. 22 * </p> 23 * <p> 24 * Nodes can be identical. This is the case if in the java virtual machine, their comparison 25 * using the <code>==</code> operator or the equals method return true. 26 * </p> 27 * <p> 28 * Nodes are lexically equal, if they represent the same events on a key stroke level to be 29 * carried out to execute the task. Identical nodes are also syntactically equal. 30 * </p> 31 * <p> 32 * Nodes are syntactically equal, if they differ in their events on key stroke level, but the 33 * syntactical result is the same. For example, entering the text "hello" into a text field can 34 * be done by entering the letters in their correct order, but also by copying the text into the 35 * text field. The syntactical result is the same: The text hello was entered. But the tasks 36 * lexically differ because the events on key stroke level are different. On the other hand, 37 * lexically equal nodes are also syntactically equal. 38 * </p> 39 * <p> 40 * Task tree nodes are semantically equal, if they execute the same function for editing the 41 * concepts. An example are a click on a button and a short cut, both executing the same function. 42 * These task tree nodes are syntactically and, therefore, also lexically different, but 43 * semantically equal. Syntactically equal task tree nodes are always also semantically equal. 44 * </p> 13 45 * 14 46 * @version $Revision: $ $Date: 19.02.2012$ 15 47 * @author 2012, last modified by $Author: patrick$ 16 48 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface NodeEquality 19 { 49 public enum NodeEquality { 50 IDENTICAL, 51 LEXICALLY_EQUAL, 52 SYNTACTICALLY_EQUAL, 53 SEMANTICALLY_EQUAL, 54 UNEQUAL; 20 55 21 //----------------------------------------------------------------------------------------------- 22 /** 23 * TODO: comment 24 * 25 * @return 26 */ 27 //----------------------------------------------------------------------------------------------- 28 public boolean getStructuralEquality(); 29 30 //----------------------------------------------------------------------------------------------- 31 /** 32 * TODO: comment 33 * 34 * @return 35 */ 36 //----------------------------------------------------------------------------------------------- 37 public boolean getSemanticalEquality(); 38 56 /** 57 * <p> 58 * Checks for the current node equality, if it is at least identical to the 59 * provided one or even more concrete. As an example, the node equality identical also 60 * indicates, that the nodes are e.g. lexically, syntactically and semantically equal. 61 * Therefore, the method called on <code>IDENTICAL</code> with <code>SEMANTICALLY_EQUAL</code> 62 * as parameter will return true. If this method is called on <code>SYNTACTICALLY_EQUAL</code> 63 * with the parameter <code>IDENTICAL</code> instead, it returns false; 64 * </p> 65 * 66 * @param nodeEquality the node equality to compare with. 67 * 68 * @return as described 69 */ 70 public boolean isAtLeast(NodeEquality nodeEquality) 71 { 72 switch (nodeEquality) { 73 case IDENTICAL: 74 return 75 (this == IDENTICAL); 76 case LEXICALLY_EQUAL: 77 return 78 (this == IDENTICAL) || 79 (this == LEXICALLY_EQUAL); 80 case SYNTACTICALLY_EQUAL: 81 return 82 (this == IDENTICAL) || 83 (this == LEXICALLY_EQUAL) || 84 (this == SYNTACTICALLY_EQUAL); 85 case SEMANTICALLY_EQUAL: 86 return 87 (this == IDENTICAL) || 88 (this == LEXICALLY_EQUAL) || 89 (this == SYNTACTICALLY_EQUAL) || 90 (this == SEMANTICALLY_EQUAL); 91 case UNEQUAL: 92 return 93 (this == UNEQUAL); 94 default : 95 return false; 96 } 97 } 39 98 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeEqualityRuleManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeEqualityRuleManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 9 import java.util.ArrayList; 11 10 import java.util.List; 12 //import java.util.logging.Logger;13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 13 16 //-------------------------------------------------------------------------------------------------17 14 /** 18 * TODO comment 15 * <p> 16 * The node equality rule manager is capable of comparing task tree nodes based on its internal list 17 * of comparison rules. The current list of rules contains the {@link NodeIdentityRule}, the 18 * {@link IterationComparisonRule}, the {@link SequenceComparisonRule}, and 19 * {@link SelectionComparisonRule}. These rules are asked for comparing the two provided task tree 20 * nodes in the mentioned order. If a rule returns a node equality other than null, this equality is 21 * returned. Otherwise the next rule is asked. 22 * </p> 19 23 * 20 24 * @version $Revision: $ $Date: 19.02.2012$ 21 25 * @author 2012, last modified by $Author: patrick$ 22 26 */ 23 //------------------------------------------------------------------------------------------------- 24 public class NodeEqualityRuleManager 25 { 27 public class NodeEqualityRuleManager { 26 28 27 /** */28 //private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName());29 /** */ 30 // private static Logger LOG = Logger.getLogger(NodeEqualityRuleManager.class.getName()); 29 31 30 /** */31 private List<NodeComparisonRule> mRuleIndex = new ArrayList<NodeComparisonRule>();32 /** */ 33 private List<NodeComparisonRule> mRuleIndex = null; 32 34 33 //-----------------------------------------------------------------------------------------------34 /**35 * TODO: comment36 *37 */38 //-----------------------------------------------------------------------------------------------39 public void init()40 {41 mRuleIndex.add(new NodeIdentityRule());42 mRuleIndex.add(new IterationComparisonRule(this));43 mRuleIndex.add(new SequenceComparisonRule(this));44 mRuleIndex.add(new SelectionComparisonRule(this));45 }35 /** 36 * <p> 37 * initializes the node equality rule manager by filling the internal list of comparison rules. 38 * This method must be called before any other method is called on the rule manager. 39 * </p> 40 */ 41 public void init() { 42 mRuleIndex = new ArrayList<NodeComparisonRule>(); 43 mRuleIndex.add(new NodeIdentityRule()); 44 mRuleIndex.add(new IterationComparisonRule(this)); 45 mRuleIndex.add(new SequenceComparisonRule(this)); 46 mRuleIndex.add(new SelectionComparisonRule(this)); 47 } 46 48 47 //----------------------------------------------------------------------------------------------- 48 /** 49 * TODO: comment 50 * 51 * @param node1 52 * @param node2 53 * @return 54 */ 55 //----------------------------------------------------------------------------------------------- 56 public NodeEquality applyRules(TaskTreeNode node1, TaskTreeNode node2) 57 { 58 //LOG.info("checking for equality of " + node1 + " and " + node2); 59 NodeEquality nodeEquality = null; 60 61 for (NodeComparisonRule rule : mRuleIndex) 49 /** 50 * <p> 51 * this method performs a comparison of the two provided task tree nodes. It iterates its 52 * internal comparison rules. If the first rule returns a node equality other than null, 53 * this equality is returned. Otherwise the next rule is tried. If no rule returns an equality 54 * <code>NodeEquality.UNEQUAL</code> is returned. 55 * </p> 56 * 57 * @param node1 the first task tree node to be compared 58 * @param node2 the second task tree node to be compared 59 * 60 * @return as described 61 * 62 * @throws IllegalStateException in the case, the {@link #init()} method was not called on the 63 * manager before a call to this method. 64 */ 65 public NodeEquality applyRules(ITaskTreeNode node1, ITaskTreeNode node2) 66 throws IllegalStateException 62 67 { 63 nodeEquality = rule.compare(node1, node2); 64 65 if (nodeEquality != null) 66 { 67 //LOG.warning("used rule " + rule + " for equality check"); 68 return nodeEquality; 69 } 68 if (mRuleIndex == null) { 69 throw new IllegalStateException("not initialized"); 70 } 71 72 // LOG.info("checking for equality of " + node1 + " and " + node2); 73 NodeEquality nodeEquality = null; 74 75 for (NodeComparisonRule rule : mRuleIndex) { 76 nodeEquality = rule.compare(node1, node2); 77 78 if (nodeEquality != null) { 79 // LOG.warning("used rule " + rule + " for equality check"); 80 return nodeEquality; 81 } 82 } 83 84 // LOG.warning("no rule could be applied --> handling nodes as unequal"); 85 86 return NodeEquality.UNEQUAL; 70 87 } 71 72 //LOG.warning("no rule could be applied --> handling nodes as unequal");73 74 return new NodesUnequal();75 }76 88 77 89 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/NodeIdentityRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 * TODO comment 12 * <p> 13 * This comparison rule returns <code>NodeEquality.IDENTICAL</code> if the comparison of the two 14 * task tree nodes using the <code>==</code> operator or the <code>equals</code> method return true. 15 * Else it returns null to denote, that it can not compare the nodes. 16 * </p> 15 17 * 16 18 * @version $Revision: $ $Date: 19.02.2012$ 17 19 * @author 2012, last modified by $Author: patrick$ 18 20 */ 19 //------------------------------------------------------------------------------------------------- 20 public class NodeIdentityRule implements NodeComparisonRule 21 { 21 public class NodeIdentityRule implements NodeComparisonRule { 22 22 23 //----------------------------------------------------------------------------------------------- 24 /* (non-Javadoc) 25 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 26 */ 27 //----------------------------------------------------------------------------------------------- 28 @Override 29 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 30 { 31 if (node1 == node2) 32 { 33 return new NodesIdentical(); 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 27 */ 28 @Override 29 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 30 if ((node1 == node2) || ((node1 != null) && (node1.equals(node2)))) { 31 return NodeEquality.IDENTICAL; 32 } 33 else { 34 return null; 35 } 34 36 } 35 else if ((node1 != null) && (node1.equals(node2)))36 {37 return new NodesEqual();38 }39 else40 {41 return null;42 }43 }44 37 45 38 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SelectionComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 * TODO comment 13 * <p> 14 * this node comparison rule is capable of comparing selections. If both selections do not have 15 * children, they are treated as lexically equal. If they have the same number of children other 16 * than 0 and all these children are lexically equal, then the selections are lexically equal. 17 * They are syntactically equal, if each child of both selections is syntactically equal to any 18 * other child. The rule can not compare semantical equality if the nodes are not at least 19 * syntactically equal and returns null, if it can not decide this. 20 * </p> 16 21 * 17 22 * @version $Revision: $ $Date: 19.02.2012$ 18 23 * @author 2012, last modified by $Author: patrick$ 19 24 */ 20 //------------------------------------------------------------------------------------------------- 21 public class SelectionComparisonRule implements NodeComparisonRule 22 { 25 public class SelectionComparisonRule implements NodeComparisonRule { 23 26 24 /***/25 private NodeEqualityRuleManager mRuleManager;27 /** the rule manager for internally comparing task tree nodes */ 28 private NodeEqualityRuleManager mRuleManager; 26 29 27 //----------------------------------------------------------------------------------------------- 28 /** 29 * TODO: comment 30 * 31 */ 32 SelectionComparisonRule(NodeEqualityRuleManager ruleManager) 33 { 34 super(); 35 mRuleManager = ruleManager; 36 } 30 /** 31 * <p> 32 * simple constructor to provide the rule with the node equality rule manager to be able 33 * to perform comparisons of the children of provided task tree nodes 34 * </p> 35 * 36 * @param ruleManager the rule manager for comparing task tree nodes 37 */ 38 SelectionComparisonRule(NodeEqualityRuleManager ruleManager) { 39 super(); 40 mRuleManager = ruleManager; 41 } 37 42 38 //----------------------------------------------------------------------------------------------- 39 /* (non-Javadoc) 40 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 41 */ 42 //----------------------------------------------------------------------------------------------- 43 @Override 44 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 45 { 46 if ((!(node1 instanceof Sequence)) || (!(node2 instanceof Sequence))) 47 { 48 return null; 43 /* 44 * (non-Javadoc) 45 * 46 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 47 */ 48 @Override 49 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 50 if ((!(node1 instanceof ISelection)) || (!(node2 instanceof ISelection))) { 51 return null; 52 } 53 54 // if both sequences do not have children, they are equal although this doesn't make sense 55 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 56 return NodeEquality.LEXICALLY_EQUAL; 57 } 58 59 // Selections are syntactically equal, if they have children, which are all syntactically 60 // equal. 61 // They are lexically equals, if they have the same number and order of lexically equal 62 // children 63 boolean lexicallyEqual = node1.getChildren().size() == node2.getChildren().size(); 64 65 for (int i = 0; i < node1.getChildren().size(); i++) { 66 ITaskTreeNode child1 = node1.getChildren().get(i); 67 boolean foundLexicallyEqualChild = false; 68 69 for (int j = 0; j < node2.getChildren().size(); j++) { 70 ITaskTreeNode child2 = node2.getChildren().get(j); 71 72 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 73 74 if (!nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL)) { 75 return null; 76 } 77 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 78 foundLexicallyEqualChild = true; 79 } 80 } 81 82 // if we compare two children at the same position and if they are lexically equal 83 // then it can be further expected, that the selections are lexically equal 84 lexicallyEqual &= foundLexicallyEqualChild; 85 } 86 87 if (lexicallyEqual) { 88 return NodeEquality.LEXICALLY_EQUAL; 89 } 90 else { 91 return NodeEquality.SYNTACTICALLY_EQUAL; 92 } 49 93 } 50 51 // if both sequences do not have children, they are equal although this doesn't make sense52 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0))53 {54 return new NodesEqual();55 }56 57 // Selections are semantically equal, if they have children, which are all semantically equal.58 // they are structurally equals, if they have the same number and order of structurally equal59 // children60 boolean structurallyEqual =61 node1.getChildren().size() == node2.getChildren().size();62 63 for (int i = 0; i < node1.getChildren().size(); i++)64 {65 TaskTreeNode child1 = node1.getChildren().get(i);66 67 for (int j = 0; j < node2.getChildren().size(); j++)68 {69 TaskTreeNode child2 = node2.getChildren().get(j);70 71 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2);72 73 if (!nodeEquality.getSemanticalEquality())74 {75 return null;76 }77 else if (structurallyEqual && (i == j))78 {79 // if we compare two children at the same position and if they are structurally equal80 // then it can be further expected, that the selections are structurally equal81 structurallyEqual &= nodeEquality.getStructuralEquality();82 }83 }84 }85 86 if (structurallyEqual)87 {88 return new NodesEqual();89 }90 else91 {92 return new NodesSemanticallyEqual();93 }94 }95 96 94 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/nodeequality/SequenceComparisonRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeIdentityRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 19.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.nodeequality; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 * TODO comment 13 * <p> 14 * This rule is capable of comparing sequences. If both sequences do not have children, they are 15 * treated as lexically equal. Sequences are lexically equal, if they have the same number and 16 * order of lexically equal children. The rule can not decide, if two sequences are syntactically 17 * or semantically equal. 18 * </p> 16 19 * 17 20 * @version $Revision: $ $Date: 19.02.2012$ 18 21 * @author 2012, last modified by $Author: patrick$ 19 22 */ 20 //------------------------------------------------------------------------------------------------- 21 public class SequenceComparisonRule implements NodeComparisonRule 22 { 23 public class SequenceComparisonRule implements NodeComparisonRule { 23 24 25 /** the rule manager for internally comparing task tree nodes */ 26 private NodeEqualityRuleManager mRuleManager; 24 27 25 /** */ 26 private NodeEqualityRuleManager mRuleManager; 28 /** 29 * <p> 30 * simple constructor to provide the rule with the node equality rule manager to be able 31 * to perform comparisons of the children of provided task tree nodes 32 * </p> 33 * 34 * @param ruleManager the rule manager for comparing task tree nodes 35 */ 36 SequenceComparisonRule(NodeEqualityRuleManager ruleManager) { 37 super(); 38 mRuleManager = ruleManager; 39 } 27 40 28 //----------------------------------------------------------------------------------------------- 29 /** 30 * TODO: comment 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 SequenceComparisonRule(NodeEqualityRuleManager ruleManager) 35 { 36 super(); 37 mRuleManager = ruleManager; 38 } 41 /* 42 * (non-Javadoc) 43 * 44 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 45 */ 46 @Override 47 public NodeEquality compare(ITaskTreeNode node1, ITaskTreeNode node2) { 48 if ((!(node1 instanceof ISequence)) || (!(node2 instanceof ISequence))) { 49 return null; 50 } 39 51 40 //----------------------------------------------------------------------------------------------- 41 /* (non-Javadoc) 42 * @see de.ugoe.cs.tasktree.nodeequality.NodeEqualityRule#apply(TaskTreeNode, TaskTreeNode) 43 */ 44 //----------------------------------------------------------------------------------------------- 45 @Override 46 public NodeEquality compare(TaskTreeNode node1, TaskTreeNode node2) 47 { 48 if ((!(node1 instanceof Sequence)) || (!(node2 instanceof Sequence))) 49 { 50 return null; 52 // if both sequences do not have children, they are equal although this doesn't make sense 53 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0)) { 54 return NodeEquality.LEXICALLY_EQUAL; 55 } 56 57 // 58 if (node1.getChildren().size() != node2.getChildren().size()) { 59 return null; 60 } 61 62 for (int i = 0; i < node1.getChildren().size(); i++) { 63 ITaskTreeNode child1 = node1.getChildren().get(i); 64 ITaskTreeNode child2 = node2.getChildren().get(i); 65 66 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2); 67 68 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 69 return null; 70 } 71 } 72 73 return NodeEquality.LEXICALLY_EQUAL; 51 74 } 52 53 // if both sequences do not have children, they are equal although this doesn't make sense54 if ((node1.getChildren().size() == 0) && (node2.getChildren().size() == 0))55 {56 return new NodesEqual();57 }58 59 // Sequences are equal, if they have the same number and order of children. If all the60 // children match structurally, then the sequences are structurally equal. Otherwise, if61 // at least one pair of children matches only semantically, then the sequences match only62 // semantically.63 if (node1.getChildren().size() != node2.getChildren().size())64 {65 return null;66 }67 68 boolean structurallyEqual = true;69 for (int i = 0; i < node1.getChildren().size(); i++)70 {71 TaskTreeNode child1 = node1.getChildren().get(i);72 TaskTreeNode child2 = node2.getChildren().get(i);73 74 NodeEquality nodeEquality = mRuleManager.applyRules(child1, child2);75 76 structurallyEqual &= nodeEquality.getStructuralEquality();77 78 if (!structurallyEqual && !nodeEquality.getSemanticalEquality())79 {80 return null;81 }82 }83 84 if (structurallyEqual)85 {86 return new NodesEqual();87 }88 else89 {90 return new NodesSemanticallyEqual();91 }92 }93 75 94 76 }
Note: See TracChangeset
for help on using the changeset viewer.