Changeset 557 for trunk/quest-core-tasktrees/src/main/java/de
- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- Location:
- trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees
- Files:
-
- 5 deleted
- 17 edited
- 23 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager/ComponentManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: ComponentManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.manager; 9 8 10 9 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 11 10 import de.ugoe.cs.quest.tasktrees.temporalrelation.TemporalRelationshipRuleManager; 12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;14 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder Impl;15 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory Impl;11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 13 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder; 14 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 // ------------------------------------------------------------------------------------------------- 25 public class ComponentManager 26 { 27 /** */ 28 private static ComponentManager sInstance; 22 public class ComponentManager { 23 24 /** */ 25 private static ComponentManager instance; 29 26 30 /** */ 31 private TemporalRelationshipRuleManager mTemporalRelationshipRuleManager; 32 33 /** */ 34 private NodeEqualityRuleManager mNodeEqualityRuleManager; 27 /** */ 28 private TemporalRelationshipRuleManager temporalRelationshipRuleManager; 35 29 36 /** */37 private TaskTreeBuilder mTaskTreeBuilder;30 /** */ 31 private NodeEqualityRuleManager nodeEqualityRuleManager; 38 32 39 /** */40 private TaskTreeNodeFactory mTaskTreeNodeFactory;33 /** */ 34 private ITaskTreeBuilder taskTreeBuilder; 41 35 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * TODO: comment 45 * 46 * @return 47 */ 48 //----------------------------------------------------------------------------------------------- 49 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() 50 { 51 return getInstance().mTemporalRelationshipRuleManager; 52 } 36 /** */ 37 private ITaskTreeNodeFactory taskTreeNodeFactory; 53 38 54 //----------------------------------------------------------------------------------------------- 55 /** 56 * TODO: comment 57 * 58 * @return 59 */ 60 //----------------------------------------------------------------------------------------------- 61 public static NodeEqualityRuleManager getNodeEqualityRuleManager() 62 { 63 return getInstance().mNodeEqualityRuleManager; 64 } 39 /** 40 * TODO: comment 41 * 42 * @return 43 */ 44 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() { 45 return getInstance().temporalRelationshipRuleManager; 46 } 65 47 66 //----------------------------------------------------------------------------------------------- 67 /** 68 * TODO: comment 69 * 70 * @return 71 */ 72 //----------------------------------------------------------------------------------------------- 73 public static TaskTreeBuilder getDefaultTaskTreeBuilder() 74 { 75 return getInstance().mTaskTreeBuilder; 76 } 48 /** 49 * TODO: comment 50 * 51 * @return 52 */ 53 public static NodeEqualityRuleManager getNodeEqualityRuleManager() { 54 return getInstance().nodeEqualityRuleManager; 55 } 77 56 78 //----------------------------------------------------------------------------------------------- 79 /** 80 * TODO: comment 81 * 82 * @return 83 */ 84 //----------------------------------------------------------------------------------------------- 85 public static TaskTreeNodeFactory getDefaultTaskTreeNodeFactory() 86 { 87 return getInstance().mTaskTreeNodeFactory; 88 } 57 /** 58 * TODO: comment 59 * 60 * @return 61 */ 62 public static ITaskTreeBuilder getDefaultTaskTreeBuilder() { 63 return getInstance().taskTreeBuilder; 64 } 89 65 90 //----------------------------------------------------------------------------------------------- 91 /** 92 * TODO: comment 93 * 94 * @return 95 */ 96 //----------------------------------------------------------------------------------------------- 97 public static synchronized void clearInstance() 98 { 99 sInstance = null; 100 } 66 /** 67 * TODO: comment 68 * 69 * @return 70 */ 71 public static ITaskTreeNodeFactory getDefaultTaskTreeNodeFactory() { 72 return getInstance().taskTreeNodeFactory; 73 } 101 74 102 //----------------------------------------------------------------------------------------------- 103 /** 104 * TODO: comment 105 * 106 * @return 107 */ 108 //----------------------------------------------------------------------------------------------- 109 private static synchronized ComponentManager getInstance() 110 { 111 if (sInstance == null) 112 { 113 sInstance = new ComponentManager(); 114 sInstance.init(); 75 /** 76 * TODO: comment 77 * 78 * @return 79 */ 80 public static synchronized void clearInstance() { 81 instance = null; 115 82 } 116 return sInstance;117 }118 83 119 //----------------------------------------------------------------------------------------------- 120 /** 121 * TODO: comment 122 * 123 */ 124 //----------------------------------------------------------------------------------------------- 125 private void init() 126 { 127 mNodeEqualityRuleManager = new NodeEqualityRuleManager(); 128 mNodeEqualityRuleManager.init(); 129 130 mTemporalRelationshipRuleManager = 131 new TemporalRelationshipRuleManager(mNodeEqualityRuleManager); 132 mTemporalRelationshipRuleManager.init(); 84 /** 85 * TODO: comment 86 * 87 * @return 88 */ 89 private static synchronized ComponentManager getInstance() { 90 if (instance == null) { 91 instance = new ComponentManager(); 92 instance.init(); 93 } 94 return instance; 95 } 133 96 134 mTaskTreeBuilder = new TaskTreeBuilderImpl(); 135 mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 136 } 97 /** 98 * TODO: comment 99 * 100 */ 101 private void init() { 102 nodeEqualityRuleManager = new NodeEqualityRuleManager(); 103 nodeEqualityRuleManager.init(); 104 105 temporalRelationshipRuleManager = 106 new TemporalRelationshipRuleManager(nodeEqualityRuleManager); 107 temporalRelationshipRuleManager.init(); 108 109 taskTreeBuilder = new TaskTreeBuilder(); 110 taskTreeNodeFactory = new TaskTreeNodeFactory(); 111 } 137 112 138 113 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager/TaskTreeManager.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 10:14:21 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.manager; 10 8 11 import java.util.Observable;12 import java.util.Observer;13 9 import java.util.logging.Logger; 14 10 15 import de.ugoe.cs.quest.eventcore.guimodel.GUIElement; 16 import de.ugoe.cs.quest.eventcore.userinteraction.InteractionEvent; 17 import de.ugoe.cs.quest.eventcore.userinteraction.KeyInteraction; 18 import de.ugoe.cs.quest.eventcore.userinteraction.KeyboardFocusChange; 19 import de.ugoe.cs.quest.eventcore.userinteraction.UserInteractionProvider; 20 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 21 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 22 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; 23 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 24 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 25 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 11 import de.ugoe.cs.quest.eventcore.Event; 12 import de.ugoe.cs.quest.eventcore.IEventTarget; 13 import de.ugoe.cs.quest.eventcore.gui.KeyInteraction; 14 import de.ugoe.cs.quest.eventcore.gui.KeyboardFocusChange; 15 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 20 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 26 21 27 //-------------------------------------------------------------------------------------------------28 22 /** 29 23 * TODO comment 30 * 24 * 31 25 * @version $Revision: $ $Date: $ 32 * @author 26 * @author 2011, last modified by $Author: $ 33 27 */ 34 //------------------------------------------------------------------------------------------------- 35 public class TaskTreeManager implements Observer 36 { 37 /** */ 38 private static final int MAX_INTERACTIONS_TILL_RULE_APPLICATION = 100; 28 public class TaskTreeManager { 29 30 /** */ 31 private static final int MAX_EVENTS_TILL_RULE_APPLICATION = 100; 39 32 40 /** */ 41 private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName()); 42 43 /** */ 44 private TaskTreeBuilder mTaskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 45 46 /** */ 47 private TaskTreeNodeFactory mTaskTreeNodeFactory = 48 ComponentManager.getDefaultTaskTreeNodeFactory(); 49 50 /** */ 51 private int mInteractionsTillRuleApplication = MAX_INTERACTIONS_TILL_RULE_APPLICATION; 52 53 /** */ 54 private Sequence mRootSequence; 55 56 /** */ 57 private GUIElement mCurrentKeyboardFocusGUIElement; 33 /** */ 34 private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName()); 58 35 59 //----------------------------------------------------------------------------------------------- 60 /** 61 * TODO: comment 62 * 63 */ 64 //----------------------------------------------------------------------------------------------- 65 public TaskTreeManager() 66 { 67 mRootSequence = mTaskTreeNodeFactory.createNewSequence(); 68 } 36 /** */ 37 private ITaskTreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 69 38 70 //----------------------------------------------------------------------------------------------- 71 /* (non-Javadoc) 72 * @see java.util.Observer#update(java.util.Observable, java.lang.Object) 73 */ 74 //----------------------------------------------------------------------------------------------- 75 public void update(Observable observable, Object event) 76 { 77 if ((observable instanceof UserInteractionProvider) && 78 (event instanceof InteractionEvent)) 39 /** */ 40 private ITaskTreeNodeFactory taskTreeNodeFactory = 41 ComponentManager.getDefaultTaskTreeNodeFactory(); 42 43 /** */ 44 private int eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 45 46 /** */ 47 private ISequence rootSequence; 48 49 /** */ 50 private IEventTarget currentKeyboardFocusGUIElement; 51 52 /** 53 * TODO: comment 54 * 55 */ 56 public TaskTreeManager() { 57 rootSequence = taskTreeNodeFactory.createNewSequence(); 58 } 59 60 /** 61 * 62 */ 63 public void handleNewEvent(Event event) { 64 if (event.getType() instanceof KeyInteraction) { 65 if (currentKeyboardFocusGUIElement == null) { 66 currentKeyboardFocusGUIElement = event.getTarget(); 67 } 68 69 addEventTask 70 (taskTreeNodeFactory.createNewEventTask 71 (event.getType(), currentKeyboardFocusGUIElement)); 72 } 73 else { 74 addEventTask 75 (taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget())); 76 } 77 } 78 79 /** 80 * 81 */ 82 public synchronized ITaskTree getTaskTree() { 83 LOG.info("applying rules temporal relationship generation rules"); 84 85 ISequence currentRootSequence = rootSequence.clone(); 86 ComponentManager.getTemporalRelationshipRuleManager().applyRules 87 (currentRootSequence, taskTreeBuilder, taskTreeNodeFactory, true); 88 89 return taskTreeNodeFactory.createTaskTree(currentRootSequence); 90 } 91 92 /** 93 * @param task 94 */ 95 private synchronized void addEventTask(IEventTask task) { 96 handleEventTask(task); 97 } 98 99 /** 100 * adds the task to the current or the new sequence. The decision depends on the type of task. 101 * If the task finishes the current sequence, the sequence is marked as finished If the task 102 * does not start a new sequence, it is added to the current sequence, before it is marked s 103 * finished. Otherwise it is added to a new sequence. 104 */ 105 private void handleEventTask(IEventTask eventTask) { 106 if (eventTask.getEventType() instanceof KeyboardFocusChange) { 107 currentKeyboardFocusGUIElement = eventTask.getEventTarget(); 108 } 109 else { 110 LOG.info("handling event task \"" + eventTask + "\""); 111 addTaskToSequence(eventTask, currentKeyboardFocusGUIElement); 112 } 113 } 114 115 /** 116 * 117 */ 118 private void addTaskToSequence(ITaskTreeNode task, IEventTarget currentKeyboardFocusGUIElement) 79 119 { 80 handleNewInteractionEvent((InteractionEvent) event); 120 taskTreeBuilder.addChild(rootSequence, task); 121 122 if (--eventsTillRuleApplication == 0) { 123 eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 124 125 LOG.info("applying rules temporal relationship generation rules"); 126 ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence, 127 taskTreeBuilder, 128 taskTreeNodeFactory, 129 false); 130 } 81 131 } 82 else83 {84 LOG.warning("could not handle notification of " + observable + " regarding " + event);85 }86 }87 88 //-----------------------------------------------------------------------------------------------89 /**90 *91 */92 //-----------------------------------------------------------------------------------------------93 public void handleNewInteractionEvent(InteractionEvent event)94 {95 if (event.getInteraction() instanceof KeyInteraction)96 {97 if (mCurrentKeyboardFocusGUIElement == null)98 {99 mCurrentKeyboardFocusGUIElement = event.getGUIElement();100 }101 102 addInteractionTask(mTaskTreeNodeFactory.createNewInteractionTask103 (mCurrentKeyboardFocusGUIElement, event.getInteraction()));104 }105 else106 {107 addInteractionTask(mTaskTreeNodeFactory.createNewInteractionTask108 (event.getGUIElement(), event.getInteraction()));109 }110 }111 112 //-----------------------------------------------------------------------------------------------113 /**114 *115 */116 //-----------------------------------------------------------------------------------------------117 public synchronized TaskTree getTaskTree()118 {119 LOG.info("applying rules temporal relationship generation rules");120 121 Sequence rootSequence = mRootSequence.clone();122 ComponentManager.getTemporalRelationshipRuleManager().applyRules123 (rootSequence, mTaskTreeBuilder, mTaskTreeNodeFactory, true);124 125 return mTaskTreeNodeFactory.createTaskTree(rootSequence);126 }127 128 //-----------------------------------------------------------------------------------------------129 /**130 * @param task131 */132 //-----------------------------------------------------------------------------------------------133 private synchronized void addInteractionTask(InteractionTask task)134 {135 handleInteractionTask(task);136 }137 138 //-----------------------------------------------------------------------------------------------139 /**140 * adds the task to the current or the new sequence. The decision depends on the type141 * of task. If the task finishes the current sequence, the sequence is marked as finished142 * If the task does not start a new sequence, it is added to the current sequence, before it143 * is marked s finished. Otherwise it is added to a new sequence.144 */145 //-----------------------------------------------------------------------------------------------146 private void handleInteractionTask(InteractionTask interactionTask)147 {148 if (interactionTask.getInteraction() instanceof KeyboardFocusChange)149 {150 mCurrentKeyboardFocusGUIElement = interactionTask.getGUIElement();151 }152 else153 {154 LOG.info("handling interaction task \"" + interactionTask + "\"");155 addTaskToSequence(interactionTask, mCurrentKeyboardFocusGUIElement);156 }157 }158 159 //-----------------------------------------------------------------------------------------------160 /**161 * TODO: comment162 *163 * @param interactionTask164 */165 //-----------------------------------------------------------------------------------------------166 /*private boolean handleAndCorrectFocusChanges(InteractionTask interactionTask)167 {168 GUIElement newGUIElement = interactionTask.getGUIElement();169 170 // find the identical parent element171 GUIElement identicalParentGUIElement = null;172 173 while ((identicalParentGUIElement == null) && (newGUIElement != null))174 {175 GUIElement currentGUIElement = mCurrentGUIElement;176 177 while ((identicalParentGUIElement == null) && (currentGUIElement != null))178 {179 if (newGUIElement.equals(currentGUIElement))180 {181 identicalParentGUIElement = newGUIElement;182 }183 else184 {185 currentGUIElement = currentGUIElement.getParent();186 }187 }188 189 newGUIElement = newGUIElement.getParent();190 }191 192 // now create focus lost interactions for each GUI element, that is not common with the193 // hierarchy of the new GUI element194 GUIElement currentGUIElement = mCurrentGUIElement;195 196 List<InteractionTask> tasksToBeAdded = new ArrayList<InteractionTask>();197 198 while ((currentGUIElement != null) &&199 ((identicalParentGUIElement == null) ||200 (!currentGUIElement.equals(identicalParentGUIElement))))201 {202 tasksToBeAdded.add203 (mTaskTreeNodeFactory.createNewInteractionTask(currentGUIElement, new FocusLost()));204 currentGUIElement = currentGUIElement.getParent();205 }206 207 // now create focus received interactions for each GUI element, that is not common with208 // with the old one. Ensure, that if the current interaction is a focus reception, that209 // it is used instead of a generated one210 newGUIElement = interactionTask.getGUIElement();211 212 int index = tasksToBeAdded.size();213 while ((newGUIElement != null) &&214 ((identicalParentGUIElement == null) ||215 (!newGUIElement.equals(identicalParentGUIElement))))216 {217 tasksToBeAdded.add(index, mTaskTreeNodeFactory.createNewInteractionTask218 (newGUIElement, new FocusReceived()));219 newGUIElement = newGUIElement.getParent();220 }221 222 // this part ensures, that the original focus reception, if any, is preserved as is.223 boolean taskAlreadyHandled = false;224 if (interactionTask.getInteraction() instanceof FocusReceived)225 {226 if (tasksToBeAdded.size() > 0)227 {228 tasksToBeAdded.set(tasksToBeAdded.size() - 1, interactionTask);229 }230 //else231 //{232 // in this case, we already have focus on the element to which the focus shall be changed.233 // therefore, we discard the new focus change on the same element.234 //}235 236 taskAlreadyHandled = true;237 }238 239 // now that all tasks are determined, add them to the sequence240 for (InteractionTask task : tasksToBeAdded)241 {242 addTaskToSequence(task);243 }244 245 mCurrentGUIElement = interactionTask.getGUIElement();246 247 return taskAlreadyHandled;248 }*/249 250 //-----------------------------------------------------------------------------------------------251 /**252 *253 */254 //-----------------------------------------------------------------------------------------------255 private void addTaskToSequence(TaskTreeNode task, GUIElement currentKeyboardFocusGUIElement)256 {257 mTaskTreeBuilder.addChild(mRootSequence, task);258 259 if (--mInteractionsTillRuleApplication == 0)260 {261 mInteractionsTillRuleApplication = MAX_INTERACTIONS_TILL_RULE_APPLICATION;262 263 LOG.info("applying rules temporal relationship generation rules");264 ComponentManager.getTemporalRelationshipRuleManager().applyRules265 (mRootSequence, mTaskTreeBuilder, mTaskTreeNodeFactory, false);266 }267 }268 132 269 133 } -
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 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultEventTargetSequenceDetectionRule.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;12 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class DefaultGUIElementSequenceDetectionRule implements TemporalRelationshipRule 26 { 22 public class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule { 27 23 28 //----------------------------------------------------------------------------------------------- 29 /* (non-Javadoc) 30 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 31 */ 32 //----------------------------------------------------------------------------------------------- 33 @Override 34 public RuleApplicationResult apply(TaskTreeNode parent, 35 TaskTreeBuilder builder, 36 TaskTreeNodeFactory nodeFactory, 37 boolean finalize) 38 { 39 if (!(parent instanceof Sequence)) 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 28 * TaskTreeBuilder, TaskTreeNodeFactory) 29 */ 30 @Override 31 public RuleApplicationResult apply(ITaskTreeNode parent, 32 ITaskTreeBuilder builder, 33 ITaskTreeNodeFactory nodeFactory, 34 boolean finalize) 40 35 { 41 return null; 36 if (!(parent instanceof ISequence)) { 37 return null; 38 } 39 40 RuleApplicationResult result = new RuleApplicationResult(); 41 42 IEventTarget currentEventTarget = null; 43 int startingIndex = -1; 44 45 int index = 0; 46 while (index < parent.getChildren().size()) { 47 ITaskTreeNode child = parent.getChildren().get(index); 48 49 IEventTarget eventTarget = determineEventTarget(child); 50 51 if ((eventTarget != null) && (!eventTarget.equals(currentEventTarget))) { 52 if (startingIndex < 0) { 53 startingIndex = index; 54 currentEventTarget = eventTarget; 55 } 56 else { 57 handleEventTargetSequence(parent, startingIndex, index - 1, builder, 58 nodeFactory, result); 59 60 return result; 61 } 62 } 63 64 index++; 65 } 66 67 if (startingIndex > -1) { 68 if (finalize && (startingIndex > 0)) { 69 handleEventTargetSequence(parent, startingIndex, parent.getChildren().size() - 1, 70 builder, nodeFactory, result); 71 } 72 else { 73 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 74 } 75 } 76 77 return result; 42 78 } 43 44 RuleApplicationResult result = new RuleApplicationResult(); 45 46 GUIElement currentGUIElement = null; 47 int startingIndex = -1; 48 49 int index = 0; 50 while (index < parent.getChildren().size()) 79 80 /** 81 * TODO: comment 82 * 83 * @param child 84 * @return 85 */ 86 private IEventTarget determineEventTarget(ITaskTreeNode node) { 87 if (node instanceof IEventTask) { 88 return ((IEventTask) node).getEventTarget(); 89 } 90 else { 91 return null; 92 } 93 } 94 95 /** 96 * TODO: comment 97 * 98 */ 99 private void handleEventTargetSequence(ITaskTreeNode parent, 100 int startIndex, 101 int endIndex, 102 ITaskTreeBuilder builder, 103 ITaskTreeNodeFactory nodeFactory, 104 RuleApplicationResult result) 51 105 { 52 TaskTreeNode child = parent.getChildren().get(index); 53 54 GUIElement guiElement = determineGUIElement(child); 55 56 if ((guiElement != null) && (!guiElement.equals(currentGUIElement))) 57 { 58 if (startingIndex < 0) 59 { 60 startingIndex = index; 61 currentGUIElement = guiElement; 106 ISequence sequence = nodeFactory.createNewSequence(); 107 108 for (int i = startIndex; i <= endIndex; i++) { 109 builder.addChild(sequence, parent.getChildren().get(startIndex)); 110 builder.removeChild((ISequence) parent, startIndex); 62 111 } 63 else64 {65 handleGuiElementSequence(parent, startingIndex, index - 1, builder, nodeFactory, result);66 112 67 return result; 68 } 69 } 70 71 index++; 113 builder.addChild((ISequence) parent, startIndex, sequence); 114 115 result.addNewlyCreatedParentNode(sequence); 116 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 72 117 } 73 74 if (startingIndex > -1)75 {76 if (finalize && (startingIndex > 0))77 {78 handleGuiElementSequence79 (parent, startingIndex, parent.getChildren().size() - 1, builder, nodeFactory, result);80 }81 else82 {83 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);84 }85 }86 87 return result;88 }89 90 //-----------------------------------------------------------------------------------------------91 /**92 * TODO: comment93 *94 * @param child95 * @return96 */97 //-----------------------------------------------------------------------------------------------98 private GUIElement determineGUIElement(TaskTreeNode node)99 {100 if (node instanceof InteractionTask)101 {102 return ((InteractionTask) node).getGUIElement();103 }104 else105 {106 return null;107 }108 }109 110 //-----------------------------------------------------------------------------------------------111 /**112 * TODO: comment113 *114 */115 //-----------------------------------------------------------------------------------------------116 private void handleGuiElementSequence(TaskTreeNode parent,117 int startIndex,118 int endIndex,119 TaskTreeBuilder builder,120 TaskTreeNodeFactory nodeFactory,121 RuleApplicationResult result)122 {123 Sequence sequence = nodeFactory.createNewSequence();124 125 for (int i = startIndex; i <= endIndex; i++)126 {127 builder.addChild(sequence, parent.getChildren().get(startIndex));128 builder.removeChild((Sequence) parent, startIndex);129 }130 131 builder.addChild((Sequence) parent, startIndex, sequence);132 133 result.addNewlyCreatedParentNode(sequence);134 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);135 }136 118 137 119 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 10 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 11 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 10 import de.ugoe.cs.quest.eventcore.gui.IInteraction; 11 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 15 16 16 //-------------------------------------------------------------------------------------------------17 17 /** 18 18 * TODO comment … … 21 21 * @author 2012, last modified by $Author: patrick$ 22 22 */ 23 //------------------------------------------------------------------------------------------------- 24 public class DefaultSequenceDetectionRule implements TemporalRelationshipRule 25 { 23 public class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule { 26 24 27 //----------------------------------------------------------------------------------------------- 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 30 */ 31 //----------------------------------------------------------------------------------------------- 32 @Override 33 public RuleApplicationResult apply(TaskTreeNode parent, 34 TaskTreeBuilder builder, 35 TaskTreeNodeFactory nodeFactory, 36 boolean finalize) 37 { 38 if (!(parent instanceof Sequence)) 25 /* 26 * (non-Javadoc) 27 * 28 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 29 * TaskTreeBuilder, TaskTreeNodeFactory) 30 */ 31 @Override 32 public RuleApplicationResult apply(ITaskTreeNode parent, 33 ITaskTreeBuilder builder, 34 ITaskTreeNodeFactory nodeFactory, 35 boolean finalize) 39 36 { 40 return null; 37 if (!(parent instanceof ISequence)) { 38 return null; 39 } 40 41 RuleApplicationResult result = new RuleApplicationResult(); 42 int sequenceStartingIndex = -1; 43 44 int index = 0; 45 while (index < parent.getChildren().size()) { 46 ITaskTreeNode child = parent.getChildren().get(index); 47 48 if ((child instanceof IEventTask) && 49 (((IEventTask) child).getEventType() instanceof IInteraction)) 50 { 51 IInteraction eventType = (IInteraction) ((IEventTask) child).getEventType(); 52 53 if (eventType.finishesLogicalSequence() && (sequenceStartingIndex > -1)) 54 { 55 // There are several situations in which this implementation may cause infinite 56 // loops. This is because the rule manager will reapply rules until 57 // no rule is applied anymore. A sequence identified in a first iteration will 58 // be identified as a sequence also in a second iteration. As an example 59 // many sequences start with an interaction starting that sequence and end 60 // with an interaction ending that sequence. This will be reidentified as 61 // further subsequence. It must therefore be assured, that a sequence, that 62 // was once identified is not reidentified in a further application of the rule. 63 // For this, the implementation performs a kind of dry run. It creates a list of 64 // children that would belong to an identified sequence. Only if this list is 65 // not a reidentification then a new sequence is created and added to the 66 // parent. If it is a reidentification can be identified, if the list of 67 // children will contain all children of the parent, or if the list of children 68 // only consists of one sequence. Further, an identified sequence must at least 69 // have one child. 70 if (((sequenceStartingIndex != 0) || 71 (index != (parent.getChildren().size() - 1))) && 72 (((index - sequenceStartingIndex) > 0) || 73 (((index - sequenceStartingIndex) == 0) && 74 (!eventType.startsLogicalSequence())))) 75 { 76 boolean allNewChildrenAreSequences = true; 77 78 for (int j = sequenceStartingIndex; 79 ((allNewChildrenAreSequences) && (j < index)); j++) 80 { 81 allNewChildrenAreSequences &= 82 (parent.getChildren().get(j) instanceof ISequence); 83 } 84 85 if (!allNewChildrenAreSequences) { 86 ISequence sequence = nodeFactory.createNewSequence(); 87 88 for (int j = sequenceStartingIndex; j < index; j++) { 89 builder.addChild 90 (sequence, parent.getChildren().get(sequenceStartingIndex)); 91 builder.removeChild((ISequence) parent, sequenceStartingIndex); 92 } 93 94 if (!eventType.startsLogicalSequence()) { 95 builder.addChild 96 (sequence, parent.getChildren().get(sequenceStartingIndex)); 97 builder.removeChild((ISequence) parent, sequenceStartingIndex); 98 } 99 100 builder.addChild((ISequence) parent, sequenceStartingIndex, sequence); 101 102 result.addNewlyCreatedParentNode(sequence); 103 result.setRuleApplicationStatus 104 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 105 return result; 106 } 107 } 108 } 109 110 if (eventType.startsLogicalSequence()) { 111 sequenceStartingIndex = index; 112 } 113 } 114 115 index++; 116 } 117 118 if (sequenceStartingIndex >= 0) { 119 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 120 } 121 122 return result; 41 123 } 42 43 RuleApplicationResult result = new RuleApplicationResult();44 int sequenceStartingIndex = -1;45 46 int index = 0;47 while (index < parent.getChildren().size())48 {49 TaskTreeNode child = parent.getChildren().get(index);50 51 if (child instanceof InteractionTask)52 {53 if (((InteractionTask) child).getInteraction().finishesLogicalSequence() &&54 (sequenceStartingIndex > -1))55 {56 // There are several situations in which this implementation may cause infinite57 // loops. This is because the rule manager will reapply rules until58 // no rule is applied anymore. A sequence identified in a first iteration will59 // be identified as a sequence also in a second iteration. As an example60 // many sequences start with an interaction starting that sequence and end61 // with an interaction ending that sequence. This will be reidentified as further62 // subsequence. It must therefore be assured, that a sequence, that was once63 // identified is not reidentified in a further application of the rule. For this,64 // the implementation performs a kind of dry run. It creates a list of children65 // that would belong to an identified sequence. Only if this list is not a66 // reidentification then a new sequence is created and added to the parent. If it67 // is a reidentification can be identified, if the list of children will contain68 // all children of the parent, or if the list of children only consists of one69 // sequence. Further, an identified sequence must at least have one child.70 if (((sequenceStartingIndex != 0) || (index != (parent.getChildren().size() - 1))) &&71 (((index - sequenceStartingIndex) > 0) ||72 (((index - sequenceStartingIndex) == 0) &&73 (!((InteractionTask) child).getInteraction().startsLogicalSequence()))))74 {75 boolean allNewChildrenAreSequences = true;76 77 for (int j = sequenceStartingIndex; ((allNewChildrenAreSequences) && (j < index)); j++)78 {79 allNewChildrenAreSequences &= (parent.getChildren().get(j) instanceof Sequence);80 }81 82 if (!allNewChildrenAreSequences)83 {84 Sequence sequence = nodeFactory.createNewSequence();85 86 for (int j = sequenceStartingIndex; j < index; j++)87 {88 builder.addChild(sequence, parent.getChildren().get(sequenceStartingIndex));89 builder.removeChild((Sequence) parent, sequenceStartingIndex);90 }91 92 if (!((InteractionTask) child).getInteraction().startsLogicalSequence())93 {94 builder.addChild(sequence, parent.getChildren().get(sequenceStartingIndex));95 builder.removeChild((Sequence) parent, sequenceStartingIndex);96 }97 98 builder.addChild((Sequence) parent, sequenceStartingIndex, sequence);99 100 result.addNewlyCreatedParentNode(sequence);101 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);102 return result;103 }104 }105 }106 107 if (((InteractionTask) child).getInteraction().startsLogicalSequence())108 {109 sequenceStartingIndex = index;110 }111 }112 113 index++;114 }115 116 if (sequenceStartingIndex >= 0)117 {118 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);119 }120 121 return result;122 }123 124 124 125 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultIterationDetectionRule.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.temporalrelation; 9 8 … … 13 12 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 14 13 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 15 import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; 16 import de.ugoe.cs.quest.tasktrees.treeifc.Selection; 17 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 18 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 19 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 20 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 21 22 //------------------------------------------------------------------------------------------------- 14 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 20 23 21 /** 24 22 * TODO comment … … 27 25 * @author 2012, last modified by $Author: patrick$ 28 26 */ 29 //------------------------------------------------------------------------------------------------- 30 public class DefaultIterationDetectionRule implements TemporalRelationshipRule 31 { 32 /** */ 33 private NodeEqualityRuleManager mNodeEqualityRuleManager; 34 35 //----------------------------------------------------------------------------------------------- 36 /** 37 * TODO: comment 27 public class DefaultIterationDetectionRule implements TemporalRelationshipRule { 28 29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 31 32 /** 33 * TODO: comment 34 * 35 */ 36 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 37 super(); 38 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 39 } 40 41 /* 42 * (non-Javadoc) 43 * 44 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 45 */ 46 @Override 47 public RuleApplicationResult apply(ITaskTreeNode parent, 48 ITaskTreeBuilder treeBuilder, 49 ITaskTreeNodeFactory nodeFactory, 50 boolean finalize) 51 { 52 if (!(parent instanceof ISequence)) { 53 return null; 54 } 55 56 // parent must already have at least 2 children 57 if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) { 58 return null; 59 } 60 61 // iterations represent as a list of nodes that splits up in several equal sublists. If 62 // the remaining nodes also start an equal sublist, then the iteration may not be completed 63 // yet. So wait for further events to only identify completed iterations. 64 65 // to find longer iterations first, start with long sequences 66 for (int end = parent.getChildren().size() - 1; end > 0; end--) { 67 for (int start = 0; start < end; start++) { 68 List<ITaskTreeNode[]> equalVariants = 69 getEqualSublistVariantsInBoundaries(parent, start, end); 70 71 if (equalVariants != null) { 72 if (!finalize) { 73 // check, if the iteration may go on. This may be the case, if the detected 74 // iteration finishes with the last child of the parent, or if the 75 // remaining children, which were not identified as part of the iteration, 76 // start a further occurrence of the iteration 77 if (end == (parent.getChildren().size() - 1)) { 78 RuleApplicationResult result = new RuleApplicationResult(); 79 result.setRuleApplicationStatus 80 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 81 return result; 82 } 83 84 boolean allNodesEqual = true; 85 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 86 { 87 if ((end + i + 1) >= parent.getChildren().size()) { 88 break; 89 } 90 91 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 92 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 93 94 allNodesEqual &= 95 nodeEquality.isAtLeast(NodeEquality.SYNTACTICALLY_EQUAL); 96 } 97 98 if (allNodesEqual) { 99 RuleApplicationResult result = new RuleApplicationResult(); 100 result.setRuleApplicationStatus 101 (RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 102 return result; 103 } 104 } 105 106 RuleApplicationResult result = new RuleApplicationResult(); 107 IIteration newIteration = nodeFactory.createNewIteration(); 108 result.addNewlyCreatedParentNode(newIteration); 109 110 if (equalVariants.size() == 1) { 111 // all children are the same. Create an iteration of this child 112 if (equalVariants.get(0).length == 1) { 113 // all children are the same. Create an iteration of this child 114 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 115 } 116 else { 117 // there was an iteration of structurally equal sequences 118 ISequence sequence = nodeFactory.createNewSequence(); 119 result.addNewlyCreatedParentNode(sequence); 120 121 for (ITaskTreeNode node : equalVariants.get(0)) { 122 treeBuilder.addChild(sequence, node); 123 } 124 125 treeBuilder.setChild(newIteration, sequence); 126 } 127 } 128 else { 129 // there are distinct variants of semantically equal subsequences or 130 // children --> 131 // create an iterated selection 132 ISelection selection = nodeFactory.createNewSelection(); 133 result.addNewlyCreatedParentNode(selection); 134 135 for (ITaskTreeNode[] variant : equalVariants) { 136 if (variant.length == 1) { 137 treeBuilder.addChild(selection, variant[0]); 138 } 139 else { 140 ISequence sequence = nodeFactory.createNewSequence(); 141 result.addNewlyCreatedParentNode(sequence); 142 143 for (ITaskTreeNode node : variant) { 144 treeBuilder.addChild(sequence, node); 145 } 146 147 treeBuilder.addChild(selection, sequence); 148 } 149 } 150 151 treeBuilder.setChild(newIteration, selection); 152 } 153 154 // remove iterated children 155 for (int j = end; j >= start; j--) { 156 treeBuilder.removeChild((ISequence) parent, j); 157 } 158 159 // add the new iteration instead 160 treeBuilder.addChild((ISequence) parent, start, newIteration); 161 162 result.setRuleApplicationStatus 163 (RuleApplicationStatus.RULE_APPLICATION_FINISHED); 164 return result; 165 } 166 } 167 } 168 169 return null; 170 } 171 172 /** 173 * TODO: comment 174 * 175 * @return 176 */ 177 private List<ITaskTreeNode[]> getEqualSublistVariantsInBoundaries(ITaskTreeNode parent, 178 int start, 179 int end) 180 { 181 List<ITaskTreeNode[]> equalVariants = null; 182 183 int noOfChildrenInBoundaries = end - start + 1; 184 185 for (int subListLen = 1; subListLen <= (noOfChildrenInBoundaries / 2); subListLen++) 186 { 187 if ((noOfChildrenInBoundaries % subListLen) == 0) { 188 equalVariants = 189 getEqualSublistVariantsForSubListLength(parent, start, end, subListLen); 190 191 if (equalVariants != null) { 192 return equalVariants; 193 } 194 } 195 } 196 197 return null; 198 } 199 200 /** 38 201 * 39 202 */ 40 //----------------------------------------------------------------------------------------------- 41 DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) 42 { 43 super(); 44 mNodeEqualityRuleManager = nodeEqualityRuleManager; 45 } 46 47 //----------------------------------------------------------------------------------------------- 48 /* (non-Javadoc) 49 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 50 */ 51 //----------------------------------------------------------------------------------------------- 52 @Override 53 public RuleApplicationResult apply(TaskTreeNode parent, 54 TaskTreeBuilder treeBuilder, 55 TaskTreeNodeFactory nodeFactory, 56 boolean finalize) 57 { 58 if (!(parent instanceof Sequence)) 203 private List<ITaskTreeNode[]> getEqualSublistVariantsForSubListLength(ITaskTreeNode parent, 204 int start, 205 int end, 206 int subListLen) 59 207 { 60 return null; 61 } 62 63 // parent must already have at least 2 children 64 if ((parent.getChildren() == null) || (parent.getChildren().size() < 2)) 65 { 66 return null; 67 } 68 69 // iterations represent as a list of nodes that splits up in several equal sublists. If 70 // the remaining nodes also start an equal sublist, then the iteration may not be completed 71 // yet. So wait for further interactions to only identify completed iterations. 72 73 // to find longer iterations first, start with long sequences 74 for (int end = parent.getChildren().size() - 1; end > 0; end--) 75 { 76 for (int start = 0; start < end; start++) 77 { 78 List<TaskTreeNode[]> equalVariants = 79 getEqualSublistVariantsInBoundaries(parent, start, end); 80 81 if (equalVariants != null) 208 List<ITaskTreeNode[]> equalVariants = new ArrayList<ITaskTreeNode[]>(); 209 ITaskTreeNode[] firstVariant = new ITaskTreeNode[subListLen]; 210 211 for (int i = 0; i < subListLen; i++) { 212 firstVariant[i] = parent.getChildren().get(start + i); 213 } 214 215 equalVariants.add(firstVariant); 216 217 for (int parentIdx = (start + subListLen); parentIdx <= end; parentIdx += subListLen) 82 218 { 83 if (!finalize) 84 { 85 // check, if the iteration may go on. This may be the case, if the detected iteration 86 // finishes with the last child of the parent, or if the remaining children, which were 87 // not identified as part of the iteration, start a further occurrence of the iteration 88 if (end == (parent.getChildren().size() - 1)) 89 { 90 RuleApplicationResult result = new RuleApplicationResult(); 91 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 92 return result; 93 } 94 95 boolean allNodesEqual = true; 96 for (int i = 0; ((allNodesEqual) && (i < equalVariants.get(0).length)); i++) 97 { 98 if ((end + i + 1) >= parent.getChildren().size()) 99 { 100 break; 101 } 102 103 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules 104 (equalVariants.get(0)[i], parent.getChildren().get(end + i + 1)); 105 106 allNodesEqual &= 107 nodeEquality.getStructuralEquality() || nodeEquality.getSemanticalEquality(); 108 } 109 110 if (allNodesEqual) 111 { 112 RuleApplicationResult result = new RuleApplicationResult(); 113 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 114 return result; 115 } 116 } 117 118 RuleApplicationResult result = new RuleApplicationResult(); 119 Iteration newIteration = nodeFactory.createNewIteration(); 120 result.addNewlyCreatedParentNode(newIteration); 121 122 if (equalVariants.size() == 1) 123 { 124 // all children are the same. Create an iteration of this child 125 if (equalVariants.get(0).length == 1) 126 { 127 // all children are the same. Create an iteration of this child 128 treeBuilder.setChild(newIteration, equalVariants.get(0)[0]); 129 } 130 else 131 { 132 // there was an iteration of structurally equal sequences 133 Sequence sequence = nodeFactory.createNewSequence(); 134 result.addNewlyCreatedParentNode(sequence); 135 136 for (TaskTreeNode node : equalVariants.get(0)) 137 { 138 treeBuilder.addChild(sequence, node); 139 } 140 141 treeBuilder.setChild(newIteration, sequence); 142 } 143 } 144 else 145 { 146 // there are distinct variants of semantically equal subsequences or children --> 147 // create an iterated selection 148 Selection selection = nodeFactory.createNewSelection(); 149 result.addNewlyCreatedParentNode(selection); 150 151 for (TaskTreeNode[] variant : equalVariants) 152 { 153 if (variant.length == 1) 154 { 155 treeBuilder.addChild(selection, variant[0]); 156 } 157 else 158 { 159 Sequence sequence = nodeFactory.createNewSequence(); 160 result.addNewlyCreatedParentNode(sequence); 161 162 for (TaskTreeNode node : variant) 163 { 164 treeBuilder.addChild(sequence, node); 165 } 166 167 treeBuilder.addChild(selection, sequence); 168 } 169 } 170 171 treeBuilder.setChild(newIteration, selection); 172 } 173 174 // remove iterated children 175 for (int j = end; j >= start; j--) 176 { 177 treeBuilder.removeChild((Sequence) parent, j); 178 } 179 180 // add the new iteration instead 181 treeBuilder.addChild((Sequence) parent, start, newIteration); 182 183 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 184 return result; 185 } 186 } 187 } 188 189 return null; 190 } 191 192 //----------------------------------------------------------------------------------------------- 193 /** 194 * TODO: comment 195 * 196 * @return 197 */ 198 //----------------------------------------------------------------------------------------------- 199 private List<TaskTreeNode[]> getEqualSublistVariantsInBoundaries(TaskTreeNode parent, 200 int start, 201 int end) 202 { 203 List<TaskTreeNode[]> equalVariants = null; 204 205 int noOfChildrenInBoundaries = end - start + 1; 206 207 for (int subListLength = 1; subListLength <= (noOfChildrenInBoundaries / 2); subListLength++) 208 { 209 if ((noOfChildrenInBoundaries % subListLength) == 0) 210 { 211 equalVariants = getEqualSublistVariantsForSubListLength(parent, start, end, subListLength); 212 213 if (equalVariants != null) 214 { 215 return equalVariants; 216 } 217 } 218 } 219 220 return null; 221 } 222 223 //----------------------------------------------------------------------------------------------- 224 /** 225 * 226 */ 227 //----------------------------------------------------------------------------------------------- 228 private List<TaskTreeNode[]> getEqualSublistVariantsForSubListLength(TaskTreeNode parent, 229 int start, 230 int end, 231 int subListLength) 232 { 233 List<TaskTreeNode[]> equalVariants = new ArrayList<TaskTreeNode[]>(); 234 TaskTreeNode[] firstVariant = new TaskTreeNode[subListLength]; 235 236 for (int i = 0; i < subListLength; i++) 237 { 238 firstVariant[i] = parent.getChildren().get(start + i); 239 } 240 241 equalVariants.add(firstVariant); 242 243 for (int parentIdx = (start + subListLength); parentIdx <= end; parentIdx += subListLength) 244 { 245 TaskTreeNode[] otherVariant = new TaskTreeNode[subListLength]; 246 247 for (int i = 0; i < subListLength; i++) 248 { 249 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules 250 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 251 252 if (!nodeEquality.getStructuralEquality()) 253 { 254 if (nodeEquality.getSemanticalEquality()) 255 { 256 otherVariant[i] = parent.getChildren().get(parentIdx + i); 257 } 258 else 259 { 260 return null; 261 } 262 } 263 } 264 265 // check, if there is a semantically equal other variant. If so, add it to the list of 266 // variants 267 boolean semanticallyUnequal = false; 268 for (int i = 0; i < subListLength; i++) 269 { 270 if (otherVariant[i] == null) 271 { 272 otherVariant[i] = firstVariant[i]; 273 } 274 else 275 { 276 semanticallyUnequal = true; 277 } 278 } 279 280 if (semanticallyUnequal) 281 { 282 equalVariants.add(otherVariant); 283 } 284 } 285 286 return equalVariants; 287 } 219 ITaskTreeNode[] otherVariant = new ITaskTreeNode[subListLen]; 220 221 for (int i = 0; i < subListLen; i++) { 222 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules 223 (firstVariant[i], parent.getChildren().get(parentIdx + i)); 224 225 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 226 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 227 otherVariant[i] = parent.getChildren().get(parentIdx + i); 228 } 229 else { 230 return null; 231 } 232 } 233 } 234 235 // check, if there is a semantically equal other variant. If so, add it to the list of 236 // variants 237 boolean semanticallyUnequal = false; 238 for (int i = 0; i < subListLen; i++) { 239 if (otherVariant[i] == null) { 240 otherVariant[i] = firstVariant[i]; 241 } 242 else { 243 semanticallyUnequal = true; 244 } 245 } 246 247 if (semanticallyUnequal) { 248 equalVariants.add(otherVariant); 249 } 250 } 251 252 return equalVariants; 253 } 288 254 289 255 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultMouseClickReductionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonDown;12 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonInteraction;13 import de.ugoe.cs.quest.eventcore. userinteraction.MouseButtonUp;14 import de.ugoe.cs.quest.eventcore. userinteraction.MouseClick;15 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;16 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;19 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.gui.MouseButtonDown; 11 import de.ugoe.cs.quest.eventcore.gui.MouseButtonInteraction; 12 import de.ugoe.cs.quest.eventcore.gui.MouseButtonUp; 13 import de.ugoe.cs.quest.eventcore.gui.MouseClick; 14 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 20 19 21 //-------------------------------------------------------------------------------------------------22 20 /** 23 21 * TODO comment … … 26 24 * @author 2012, last modified by $Author: patrick$ 27 25 */ 28 //------------------------------------------------------------------------------------------------- 29 public class DefaultMouseClickReductionRule implements TemporalRelationshipRule 30 { 26 public class DefaultMouseClickReductionRule implements TemporalRelationshipRule { 31 27 32 //----------------------------------------------------------------------------------------------- 33 /* (non-Javadoc) 34 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Override 38 public RuleApplicationResult apply(TaskTreeNode parent, 39 TaskTreeBuilder builder, 40 TaskTreeNodeFactory nodeFactory, 41 boolean finalize) 42 { 43 if (!(parent instanceof Sequence)) 28 /* 29 * (non-Javadoc) 30 * 31 * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, 32 * TaskTreeBuilder, TaskTreeNodeFactory) 33 */ 34 @Override 35 public RuleApplicationResult apply(ITaskTreeNode parent, 36 ITaskTreeBuilder builder, 37 ITaskTreeNodeFactory nodeFactory, 38 boolean finalize) 44 39 { 45 return null; 40 if (!(parent instanceof ISequence)) { 41 return null; 42 } 43 44 RuleApplicationResult result = new RuleApplicationResult(); 45 46 int index = 0; 47 while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end 48 { 49 if (mouseClickSequenceFound(parent.getChildren().get(index), 50 parent.getChildren().get(index + 1), 51 parent.getChildren().get(index + 2))) 52 { 53 builder.removeChild((ISequence) parent, index); 54 builder.removeChild((ISequence) parent, index); 55 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 56 return result; 57 } 58 else if 59 ((parent.getChildren().get(index) instanceof ISequence) && 60 (parent.getChildren().get(index).getChildren().size() == 2) && 61 (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0), 62 parent.getChildren().get(index).getChildren().get(1), 63 parent.getChildren().get(index + 1)))) 64 { 65 builder.removeChild((ISequence) parent, index); 66 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 67 return result; 68 } 69 70 index++; 71 } 72 73 return result; 46 74 } 47 48 RuleApplicationResult result = new RuleApplicationResult();49 50 int index = 0;51 while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end52 {53 if (mouseClickSequenceFound(parent.getChildren().get(index),54 parent.getChildren().get(index + 1),55 parent.getChildren().get(index + 2)))56 {57 builder.removeChild((Sequence) parent, index);58 builder.removeChild((Sequence) parent, index);59 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);60 return result;61 }62 else if ((parent.getChildren().get(index) instanceof Sequence) &&63 (parent.getChildren().get(index).getChildren().size() == 2) &&64 (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0),65 parent.getChildren().get(index).getChildren().get(1),66 parent.getChildren().get(index + 1))))67 {68 builder.removeChild((Sequence) parent, index);69 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);70 return result;71 }72 73 index++;74 }75 76 return result;77 }78 75 79 //----------------------------------------------------------------------------------------------- 80 /** 76 /** 81 77 * 82 78 */ 83 //----------------------------------------------------------------------------------------------- 84 private boolean mouseClickSequenceFound(TaskTreeNode mouseButtonDown, 85 TaskTreeNode mouseButtonUp, 86 TaskTreeNode mouseClick) 87 { 88 // check the first in a row of three for validity 89 if (!(mouseButtonDown instanceof InteractionTask)) 79 private boolean mouseClickSequenceFound(ITaskTreeNode mouseButtonDown, 80 ITaskTreeNode mouseButtonUp, 81 ITaskTreeNode mouseClick) 90 82 { 91 return false; 83 // check the first in a row of three for validity 84 if (!(mouseButtonDown instanceof IEventTask)) { 85 return false; 86 } 87 88 IEventTarget eventTarget = ((IEventTask) mouseButtonDown).getEventTarget(); 89 90 if (!(((IEventTask) mouseButtonDown).getEventType() instanceof MouseButtonDown)) { 91 return false; 92 } 93 94 MouseButtonInteraction.Button button = 95 ((MouseButtonDown) ((IEventTask) mouseButtonDown).getEventType()).getButton(); 96 97 // check the second node for validity 98 if (!(mouseButtonUp instanceof IEventTask)) { 99 return false; 100 } 101 102 if (!eventTarget.equals(((IEventTask) mouseButtonUp).getEventTarget())) { 103 return false; 104 } 105 106 if (!(((IEventTask) mouseButtonUp).getEventType() instanceof MouseButtonUp)) { 107 return false; 108 } 109 110 if (!button.equals(((MouseButtonUp) ((IEventTask) mouseButtonUp).getEventType()) 111 .getButton())) 112 { 113 return false; 114 } 115 116 // check the third node for validity 117 if (!(mouseClick instanceof IEventTask)) { 118 return false; 119 } 120 121 if (!eventTarget.equals(((IEventTask) mouseClick).getEventTarget())) { 122 return false; 123 } 124 125 if (!(((IEventTask) mouseClick).getEventType() instanceof MouseClick)) { 126 return false; 127 } 128 129 if (!button.equals(((MouseClick) ((IEventTask) mouseClick).getEventType()).getButton())) { 130 return false; 131 } 132 133 return true; 92 134 } 93 94 GUIElement guiElement = ((InteractionTask) mouseButtonDown).getGUIElement();95 96 if (!(((InteractionTask) mouseButtonDown).getInteraction() instanceof MouseButtonDown))97 {98 return false;99 }100 101 MouseButtonInteraction.Button button =102 ((MouseButtonDown) ((InteractionTask) mouseButtonDown).getInteraction()).getButton();103 104 105 // check the second node for validity106 if (!(mouseButtonUp instanceof InteractionTask))107 {108 return false;109 }110 111 if (!guiElement.equals(((InteractionTask) mouseButtonUp).getGUIElement()))112 {113 return false;114 }115 116 if (!(((InteractionTask) mouseButtonUp).getInteraction() instanceof MouseButtonUp))117 {118 return false;119 }120 121 if (!button.equals122 (((MouseButtonUp) ((InteractionTask) mouseButtonUp).getInteraction()).getButton()))123 {124 return false;125 }126 127 128 // check the third node for validity129 if (!(mouseClick instanceof InteractionTask))130 {131 return false;132 }133 134 if (!guiElement.equals(((InteractionTask) mouseClick).getGUIElement()))135 {136 return false;137 }138 139 if (!(((InteractionTask) mouseClick).getInteraction() instanceof MouseClick))140 {141 return false;142 }143 144 if (!button.equals(((MouseClick) ((InteractionTask) mouseClick).getInteraction()).getButton()))145 {146 return false;147 }148 149 return true;150 }151 135 152 136 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultTextInputReductionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 12 11 import java.util.Locale; 13 12 14 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;15 import de.ugoe.cs.quest.eventcore.gui model.TextArea;16 import de.ugoe.cs.quest.eventcore.gui model.TextField;17 import de.ugoe.cs.quest.eventcore. userinteraction.KeyInteraction;18 import de.ugoe.cs.quest.eventcore. userinteraction.KeyPressed;19 import de.ugoe.cs.quest.eventcore. userinteraction.KeyReleased;20 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;21 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;22 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;23 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;24 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;25 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;13 import de.ugoe.cs.quest.eventcore.IEventTarget; 14 import de.ugoe.cs.quest.eventcore.gui.KeyInteraction; 15 import de.ugoe.cs.quest.eventcore.gui.KeyPressed; 16 import de.ugoe.cs.quest.eventcore.gui.KeyReleased; 17 import de.ugoe.cs.quest.eventcore.guimodel.ITextArea; 18 import de.ugoe.cs.quest.eventcore.guimodel.ITextField; 19 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 20 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 21 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 22 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 23 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 24 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 26 25 import de.ugoe.cs.tasktree.keyboardmaps.KeyboardMap; 27 26 import de.ugoe.cs.tasktree.keyboardmaps.KeyboardMapFactory; 28 27 import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey; 29 28 30 //-------------------------------------------------------------------------------------------------31 29 /** 32 30 * TODO comment … … 35 33 * @author 2012, last modified by $Author: patrick$ 36 34 */ 37 //------------------------------------------------------------------------------------------------- 38 public class DefaultTextInputReductionRule implements TemporalRelationshipRule 39 { 40 /** */ 41 private KeyboardMap mKeyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 42 43 //----------------------------------------------------------------------------------------------- 44 /* (non-Javadoc) 45 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 46 */ 47 //----------------------------------------------------------------------------------------------- 48 @Override 49 public RuleApplicationResult apply(TaskTreeNode parent, 50 TaskTreeBuilder builder, 51 TaskTreeNodeFactory nodeFactory, 52 boolean finalize) 53 { 54 if ((!(parent instanceof Sequence)) || 55 (parent instanceof TextInputInteractionTask)) 35 public class DefaultTextInputReductionRule implements TemporalRelationshipRule { 36 37 /** */ 38 private KeyboardMap keyboardMap = KeyboardMapFactory.createKeyboardMap(Locale.GERMAN); 39 40 /* 41 * (non-Javadoc) 42 * 43 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 44 */ 45 @Override 46 public RuleApplicationResult apply(ITaskTreeNode parent, 47 ITaskTreeBuilder builder, 48 ITaskTreeNodeFactory nodeFactory, 49 boolean finalize) 56 50 { 57 return null; 58 } 59 60 RuleApplicationResult result = new RuleApplicationResult(); 61 int textEntryStartIndex = -1; 62 GUIElement currentGUIElement = null; 63 64 int index = 0; 65 TaskTreeNode task = null; 66 while (index < parent.getChildren().size()) 51 if ((!(parent instanceof ISequence)) || (parent instanceof ITextInputEventTask)) { 52 return null; 53 } 54 55 RuleApplicationResult result = new RuleApplicationResult(); 56 int textEntryStartIndex = -1; 57 IEventTarget currentEventTarget = null; 58 59 int index = 0; 60 ITaskTreeNode task = null; 61 while (index < parent.getChildren().size()) { 62 task = parent.getChildren().get(index); 63 if (isKeyInteraction(task) && 64 isDataInputEventTarget(((IEventTask) task).getEventTarget())) 65 { 66 if (textEntryStartIndex < 0) { 67 textEntryStartIndex = index; 68 currentEventTarget = ((IEventTask) task).getEventTarget(); 69 } 70 else if (!currentEventTarget.equals(((IEventTask) task).getEventTarget())) { 71 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, 72 currentEventTarget, builder, nodeFactory, result); 73 return result; 74 } 75 } 76 else if (textEntryStartIndex >= 0) { 77 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentEventTarget, 78 builder, nodeFactory, result); 79 return result; 80 } 81 82 index++; 83 } 84 85 if (textEntryStartIndex >= 0) { 86 if (finalize) { 87 handleTextEntrySequence(parent, textEntryStartIndex, 88 parent.getChildren().size() - 1, currentEventTarget, 89 builder, nodeFactory, result); 90 } 91 else { 92 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 93 } 94 } 95 96 return result; 97 } 98 99 /** 100 * TODO: comment 101 * 102 * @param taskTreeNode 103 * @return 104 */ 105 private boolean isKeyInteraction(ITaskTreeNode taskTreeNode) { 106 if ((taskTreeNode instanceof IEventTask)) { 107 return (((IEventTask) taskTreeNode).getEventType() instanceof KeyInteraction); 108 } 109 else { 110 return false; 111 } 112 } 113 114 /** 115 * TODO: comment 116 * 117 * @param textEntryStartIndex 118 * @param i 119 * @param result 120 * @return 121 */ 122 private void handleTextEntrySequence(ITaskTreeNode parent, 123 int startIndex, 124 int endIndex, 125 IEventTarget eventTarget, 126 ITaskTreeBuilder builder, 127 ITaskTreeNodeFactory nodeFactory, 128 RuleApplicationResult result) 67 129 { 68 task = parent.getChildren().get(index); 69 if (isKeyInteraction(task) && isDataInputGUIElement(((InteractionTask) task).getGUIElement())) 70 { 71 if (textEntryStartIndex < 0) 72 { 73 textEntryStartIndex = index; 74 currentGUIElement = ((InteractionTask) task).getGUIElement(); 75 } 76 else if (!currentGUIElement.equals(((InteractionTask) task).getGUIElement())) 77 { 78 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentGUIElement, 79 builder, nodeFactory, result); 80 return result; 81 } 82 } 83 else if (textEntryStartIndex >= 0) 84 { 85 handleTextEntrySequence(parent, textEntryStartIndex, index - 1, currentGUIElement, 86 builder, nodeFactory, result); 87 return result; 88 } 89 90 index++; 91 } 92 93 if (textEntryStartIndex >= 0) 130 ITextInputEventTask textInput = nodeFactory.createNewTextInputEventTask(eventTarget); 131 132 for (int i = startIndex; i <= endIndex; i++) { 133 builder.addChild(textInput, parent.getChildren().get(startIndex)); 134 builder.removeChild((ISequence) parent, startIndex); 135 } 136 137 builder.addChild((ISequence) parent, startIndex, textInput); 138 139 StringBuffer enteredText = new StringBuffer(); 140 determineEnteredText(textInput, new ArrayList<VirtualKey>(), enteredText); 141 textInput.setEnteredText(enteredText.toString()); 142 143 result.addNewlyCreatedParentNode(textInput); 144 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 145 } 146 147 /** 148 * TODO: comment 149 * 150 * @param eventTarget 151 * @return 152 */ 153 private boolean isDataInputEventTarget(IEventTarget eventTarget) { 154 return ((eventTarget instanceof ITextField) || (eventTarget instanceof ITextArea)); 155 } 156 157 /** 158 * TODO: comment 159 * 160 * @param sequence 161 * @param enteredText 162 */ 163 private void determineEnteredText(ITaskTreeNode node, 164 List<VirtualKey> pressedKeys, 165 StringBuffer enteredText) 94 166 { 95 if (finalize) 96 { 97 handleTextEntrySequence(parent, textEntryStartIndex, parent.getChildren().size() - 1, 98 currentGUIElement, builder, nodeFactory, result); 99 } 100 else 101 { 102 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 103 } 104 } 105 106 return result; 107 } 108 109 //----------------------------------------------------------------------------------------------- 110 /** 111 * TODO: comment 112 * 113 * @param taskTreeNode 114 * @return 115 */ 116 //----------------------------------------------------------------------------------------------- 117 private boolean isKeyInteraction(TaskTreeNode taskTreeNode) 118 { 119 if ((taskTreeNode instanceof InteractionTask)) 120 { 121 return (((InteractionTask) taskTreeNode).getInteraction() instanceof KeyInteraction); 122 } 123 else 124 { 125 return false; 126 } 127 } 128 129 //----------------------------------------------------------------------------------------------- 130 /** 131 * TODO: comment 132 * 133 * @param textEntryStartIndex 134 * @param i 135 * @param result 136 * @return 137 */ 138 //----------------------------------------------------------------------------------------------- 139 private void handleTextEntrySequence(TaskTreeNode parent, 140 int startIndex, 141 int endIndex, 142 GUIElement guiElement, 143 TaskTreeBuilder builder, 144 TaskTreeNodeFactory nodeFactory, 145 RuleApplicationResult result) 146 { 147 TextInputInteractionTask textInput = nodeFactory.createNewTextInputInteractionTask(guiElement); 148 149 for (int i = startIndex; i <= endIndex; i++) 150 { 151 builder.addChild(textInput, parent.getChildren().get(startIndex)); 152 builder.removeChild((Sequence) parent, startIndex); 153 } 154 155 builder.addChild((Sequence) parent, startIndex, textInput); 156 157 StringBuffer enteredText = new StringBuffer(); 158 determineEnteredText(textInput, new ArrayList<VirtualKey>(), enteredText); 159 textInput.setEnteredText(enteredText.toString()); 160 161 result.addNewlyCreatedParentNode(textInput); 162 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 163 } 164 165 //----------------------------------------------------------------------------------------------- 166 /** 167 * TODO: comment 168 * 169 * @param guiElement 170 * @return 171 */ 172 //----------------------------------------------------------------------------------------------- 173 private boolean isDataInputGUIElement(GUIElement guiElement) 174 { 175 return ((guiElement instanceof TextField) || (guiElement instanceof TextArea)); 176 } 177 178 //----------------------------------------------------------------------------------------------- 179 /** 180 * TODO: comment 181 * 182 * @param sequence 183 * @param enteredText 184 */ 185 //----------------------------------------------------------------------------------------------- 186 private void determineEnteredText(TaskTreeNode node, 187 List<VirtualKey> pressedKeys, 188 StringBuffer enteredText) 189 { 190 if ((node instanceof Sequence) || (node instanceof TextInputInteractionTask)) 191 { 192 for (TaskTreeNode child : node.getChildren()) 193 { 194 if (child instanceof InteractionTask) 195 { 196 if (((InteractionTask) child).getInteraction() instanceof KeyPressed) 197 { 198 VirtualKey key = ((KeyPressed) ((InteractionTask) child).getInteraction()).getKey(); 199 200 pressedKeys.add(key); 201 202 if (key == VirtualKey.BACK_SPACE) 203 { 204 if (enteredText.length() > 0) 205 { 206 enteredText.deleteCharAt(enteredText.length() - 1); 207 } 208 } 209 else if (key == VirtualKey.ENTER) 210 { 211 // text fields only contain one line of code. Therefore the return is ignored. 212 if (!(((InteractionTask) child).getGUIElement() instanceof TextField)) 213 { 214 enteredText.append(getCharacter(key, pressedKeys)); 215 } 216 } 217 else 218 { 219 char theChar = getCharacter(key, pressedKeys); 220 if (theChar != Character.UNASSIGNED) 221 { 222 enteredText.append(theChar); 223 } 224 } 225 } 226 else if (((InteractionTask) child).getInteraction() instanceof KeyReleased) 227 { 228 pressedKeys.remove(((KeyReleased) ((InteractionTask) child).getInteraction()).getKey()); 229 } 230 } 231 else 232 { 233 determineEnteredText(child, pressedKeys, enteredText); 234 } 235 } 236 } 237 } 238 239 //----------------------------------------------------------------------------------------------- 240 /** 241 * TODO: comment 242 * 243 * @param key 244 * @param pressedKeys 245 * @return 246 */ 247 //----------------------------------------------------------------------------------------------- 248 private char getCharacter(VirtualKey key, List<VirtualKey> pressedKeys) 249 { 250 boolean numlock = false; 251 boolean shift = false; 252 boolean altgr = false; 253 254 for (VirtualKey pressedKey : pressedKeys) 255 { 256 if (pressedKey.isShiftKey()) 257 { 258 shift = !shift; 259 } 260 else if (pressedKey == VirtualKey.ALT_GRAPH) 261 { 262 altgr = !altgr; 263 } 264 else if (pressedKey == VirtualKey.NUM_LOCK) 265 { 266 numlock = !numlock; 267 } 268 } 269 270 return mKeyboardMap.getCharacterFor(key, numlock, shift, altgr, false); 271 } 167 if ((node instanceof ISequence) || (node instanceof ITextInputEventTask)) { 168 for (ITaskTreeNode child : node.getChildren()) { 169 if (child instanceof IEventTask) { 170 if (((IEventTask) child).getEventType() instanceof KeyPressed) { 171 VirtualKey key = 172 ((KeyPressed) ((IEventTask) child).getEventType()).getKey(); 173 174 pressedKeys.add(key); 175 176 if (key == VirtualKey.BACK_SPACE) { 177 if (enteredText.length() > 0) { 178 enteredText.deleteCharAt(enteredText.length() - 1); 179 } 180 } 181 else if (key == VirtualKey.ENTER) { 182 // text fields only contain one line of code. Therefore the return is 183 // ignored. 184 if (!(((IEventTask) child).getEventTarget() instanceof ITextField)) { 185 enteredText.append(getCharacter(key, pressedKeys)); 186 } 187 } 188 else { 189 char theChar = getCharacter(key, pressedKeys); 190 if (theChar != Character.UNASSIGNED) { 191 enteredText.append(theChar); 192 } 193 } 194 } 195 else if (((IEventTask) child).getEventType() instanceof KeyReleased) { 196 pressedKeys.remove 197 (((KeyReleased) ((IEventTask) child).getEventType()).getKey()); 198 } 199 } 200 else { 201 determineEnteredText(child, pressedKeys, enteredText); 202 } 203 } 204 } 205 } 206 207 /** 208 * TODO: comment 209 * 210 * @param key 211 * @param pressedKeys 212 * @return 213 */ 214 private char getCharacter(VirtualKey key, List<VirtualKey> pressedKeys) { 215 boolean numlock = false; 216 boolean shift = false; 217 boolean altgr = false; 218 219 for (VirtualKey pressedKey : pressedKeys) { 220 if (pressedKey.isShiftKey()) { 221 shift = !shift; 222 } 223 else if (pressedKey == VirtualKey.ALT_GRAPH) { 224 altgr = !altgr; 225 } 226 else if (pressedKey == VirtualKey.NUM_LOCK) { 227 numlock = !numlock; 228 } 229 } 230 231 return keyboardMap.getCharacterFor(key, numlock, shift, altgr, false); 232 } 272 233 273 234 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/RuleApplicationResult.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: RuleApplicationResult.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 … … 11 11 import java.util.List; 12 12 13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 14 15 //-------------------------------------------------------------------------------------------------16 15 /** 17 16 * TODO comment … … 20 19 * @author 2012, last modified by $Author: patrick$ 21 20 */ 22 //------------------------------------------------------------------------------------------------- 23 public class RuleApplicationResult 24 { 21 public class RuleApplicationResult { 25 22 26 /** */ 27 private RuleApplicationStatus mStatus = RuleApplicationStatus.RULE_NOT_APPLIED; 28 29 /** */ 30 private List<TaskTreeNode> mNewParents = new ArrayList<TaskTreeNode>(); 23 /** */ 24 private RuleApplicationStatus status = RuleApplicationStatus.RULE_NOT_APPLIED; 31 25 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * TODO: comment 35 * 36 * @param b 37 */ 38 //----------------------------------------------------------------------------------------------- 39 public RuleApplicationResult() 40 { 41 // this is the default indicating nothing so far 42 } 26 /** */ 27 private List<ITaskTreeNode> newParents = new ArrayList<ITaskTreeNode>(); 43 28 44 //----------------------------------------------------------------------------------------------- 45 /** 46 * TODO: comment 47 * 48 * @param b 49 */ 50 //----------------------------------------------------------------------------------------------- 51 public void setRuleApplicationStatus(RuleApplicationStatus status) 52 { 53 mStatus = status; 54 } 29 /** 30 * TODO: comment 31 * 32 * @param b 33 */ 34 public RuleApplicationResult() { 35 // this is the default indicating nothing so far 36 } 55 37 56 //----------------------------------------------------------------------------------------------- 57 /** 58 * TODO: comment 59 * 60 * @return 61 */ 62 //----------------------------------------------------------------------------------------------- 63 public RuleApplicationStatus getRuleApplicationStatus() 64 { 65 return mStatus; 66 } 38 /** 39 * TODO: comment 40 * 41 * @param b 42 */ 43 public void setRuleApplicationStatus(RuleApplicationStatus status) { 44 this.status = status; 45 } 67 46 68 //----------------------------------------------------------------------------------------------- 69 /** 70 * TODO: comment 71 * 72 * @param sequence 73 */ 74 //----------------------------------------------------------------------------------------------- 75 public void addNewlyCreatedParentNode(TaskTreeNode newParent) 76 { 77 mNewParents.add(newParent); 78 } 47 /** 48 * TODO: comment 49 * 50 * @return 51 */ 52 public RuleApplicationStatus getRuleApplicationStatus() { 53 return status; 54 } 79 55 80 //----------------------------------------------------------------------------------------------- 81 /** 82 * TODO: comment 83 * 84 * @return 85 */ 86 //----------------------------------------------------------------------------------------------- 87 public List<TaskTreeNode> getNewlyCreatedParentNodes() 88 { 89 return mNewParents; 90 } 56 /** 57 * TODO: comment 58 * 59 * @param sequence 60 */ 61 public void addNewlyCreatedParentNode(ITaskTreeNode newParent) { 62 newParents.add(newParent); 63 } 64 65 /** 66 * TODO: comment 67 * 68 * @return 69 */ 70 public List<ITaskTreeNode> getNewlyCreatedParentNodes() { 71 return newParents; 72 } 91 73 92 74 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/RuleApplicationStatus.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: RuleApplicationStatus.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: pharms $ $Date: 09.07.2012 $ … … 5 4 // Creation : 2012 by pharms 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: pharms$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public enum RuleApplicationStatus 19 { 20 RULE_APPLICATION_FINISHED, 21 RULE_APPLICATION_FEASIBLE, 22 RULE_NOT_APPLIED; 16 public enum RuleApplicationStatus { 17 RULE_APPLICATION_FINISHED, 18 RULE_APPLICATION_FEASIBLE, 19 RULE_NOT_APPLIED; 23 20 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRule.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationshipRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;9 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 10 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 14 * TODO comment … … 19 17 * @author 2012, last modified by $Author: patrick$ 20 18 */ 21 //------------------------------------------------------------------------------------------------- 22 public interface TemporalRelationshipRule 23 { 19 public interface TemporalRelationshipRule { 24 20 25 //-----------------------------------------------------------------------------------------------26 21 /** 27 22 * applies the rule to the given situation and returns a rule application result, if this was 28 23 * successful 29 24 */ 30 //----------------------------------------------------------------------------------------------- 31 public RuleApplicationResult apply(TaskTreeNode parent, 32 TaskTreeBuilder builder, 33 TaskTreeNodeFactory nodeFactory, 34 boolean finalize); 25 public RuleApplicationResult apply(ITaskTreeNode parent, 26 ITaskTreeBuilder builder, 27 ITaskTreeNodeFactory nodeFactory, 28 boolean finalize); 35 29 36 30 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationshipRuleManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 … … 13 12 14 13 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;16 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 18 17 19 //-------------------------------------------------------------------------------------------------20 18 /** 21 19 * TODO comment … … 24 22 * @author 2012, last modified by $Author: patrick$ 25 23 */ 26 //------------------------------------------------------------------------------------------------- 27 public class TemporalRelationshipRuleManager 28 { 29 /** */ 30 private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName()); 24 public class TemporalRelationshipRuleManager { 25 26 /** */ 27 private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName()); 31 28 32 /** */33 private NodeEqualityRuleManager mNodeEqualityRuleManager;29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 34 31 35 /** */36 private List<TemporalRelationshipRule> mRuleIndex = new ArrayList<TemporalRelationshipRule>();32 /** */ 33 private List<TemporalRelationshipRule> ruleIndex = new ArrayList<TemporalRelationshipRule>(); 37 34 38 //----------------------------------------------------------------------------------------------- 39 /** 40 * TODO: comment 35 /** 36 * TODO: comment 37 * 38 */ 39 public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) { 40 super(); 41 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 42 } 43 44 /** 45 * TODO: comment 46 * 47 */ 48 public void init() { 49 LOG.info("initializing"); 50 51 ruleIndex.add(new DefaultMouseClickReductionRule()); 52 ruleIndex.add(new DefaultTextInputReductionRule()); 53 ruleIndex.add(new DefaultEventTargetSequenceDetectionRule()); 54 ruleIndex.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager)); 55 ruleIndex.add(new DefaultGuiEventSequenceDetectionRule()); 56 ruleIndex.add(new DefaultIterationDetectionRule(nodeEqualityRuleManager)); 57 } 58 59 /** 60 * returns true, if there is a rule that matches the current situation and if, therefore, a new 61 * temporal relationship has been added to the tree. 62 * 63 * @param parent 64 * @param newChild 65 * @return 66 */ 67 public void applyRules(ITaskTreeNode parent, 68 ITaskTreeBuilder builder, 69 ITaskTreeNodeFactory nodeFactory, 70 boolean finalize) 71 { 72 applyRules(parent, builder, nodeFactory, finalize, ""); 73 } 74 75 /** 76 * returns true, if there is a rule that matches the current situation and if, therefore, a new 77 * temporal relationship has been added to the tree. 78 * 79 * @param parent 80 * @param newChild 81 * @return 82 */ 83 private int applyRules(ITaskTreeNode parent, 84 ITaskTreeBuilder builder, 85 ITaskTreeNodeFactory nodeFactory, 86 boolean finalize, 87 String logIndent) 88 { 89 LOG.info(logIndent + "applying rules for " + parent); 90 91 int noOfRuleApplications = 0; 92 93 for (TemporalRelationshipRule rule : ruleIndex) { 94 RuleApplicationResult result; 95 do { 96 // LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent); 97 result = rule.apply(parent, builder, nodeFactory, finalize); 98 99 if ((result != null) && 100 (result.getRuleApplicationStatus() == 101 RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 102 { 103 LOG.info(logIndent + "applied rule " + rule + " on " + parent); 104 noOfRuleApplications++; 105 106 for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) { 107 noOfRuleApplications += 108 applyRules(newParent, builder, nodeFactory, true, logIndent + " "); 109 } 110 } 111 } 112 while ((result != null) && 113 (result.getRuleApplicationStatus() == 114 RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 115 116 if ((!finalize) && 117 (result != null) && 118 (result.getRuleApplicationStatus() == 119 RuleApplicationStatus.RULE_APPLICATION_FEASIBLE)) 120 { 121 // in this case, don't go on applying rules, which should not be applied yet 122 break; 123 } 124 } 125 126 if (noOfRuleApplications <= 0) { 127 LOG.warning(logIndent + "no rules applied --> no temporal relationship generated"); 128 } 129 130 return noOfRuleApplications; 131 } 132 133 /** 41 134 * 42 135 */ 43 //----------------------------------------------------------------------------------------------- 44 public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) 45 { 46 super(); 47 mNodeEqualityRuleManager = nodeEqualityRuleManager; 48 } 49 50 //----------------------------------------------------------------------------------------------- 51 /** 52 * TODO: comment 53 * 54 */ 55 //----------------------------------------------------------------------------------------------- 56 public void init() 57 { 58 LOG.info("initializing"); 59 60 mRuleIndex.add(new DefaultMouseClickReductionRule()); 61 mRuleIndex.add(new DefaultTextInputReductionRule()); 62 mRuleIndex.add(new DefaultGUIElementSequenceDetectionRule()); 63 mRuleIndex.add(new TrackBarSelectionDetectionRule(mNodeEqualityRuleManager)); 64 mRuleIndex.add(new DefaultSequenceDetectionRule()); 65 mRuleIndex.add(new DefaultIterationDetectionRule(mNodeEqualityRuleManager)); 66 } 67 68 //----------------------------------------------------------------------------------------------- 69 /** 70 * returns true, if there is a rule that matches the current situation and if, therefore, a 71 * new temporal relationship has been added to the tree. 72 * 73 * @param parent 74 * @param newChild 75 * @return 76 */ 77 //----------------------------------------------------------------------------------------------- 78 public void applyRules(TaskTreeNode parent, 79 TaskTreeBuilder builder, 80 TaskTreeNodeFactory nodeFactory, 81 boolean finalize) 82 { 83 applyRules(parent, builder, nodeFactory, finalize, ""); 84 } 85 86 //----------------------------------------------------------------------------------------------- 87 /** 88 * returns true, if there is a rule that matches the current situation and if, therefore, a 89 * new temporal relationship has been added to the tree. 90 * 91 * @param parent 92 * @param newChild 93 * @return 94 */ 95 //----------------------------------------------------------------------------------------------- 96 private int applyRules(TaskTreeNode parent, 97 TaskTreeBuilder builder, 98 TaskTreeNodeFactory nodeFactory, 99 boolean finalize, 100 String logIndent) 101 { 102 LOG.info(logIndent + "applying rules for " + parent); 103 104 int noOfRuleApplications = 0; 105 106 for (TemporalRelationshipRule rule : mRuleIndex) 107 { 108 RuleApplicationResult result; 109 do 110 { 111 //LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent); 112 result = rule.apply(parent, builder, nodeFactory, finalize); 113 114 if ((result != null) && 115 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED)) 116 { 117 LOG.info(logIndent + "applied rule " + rule + " on " + parent); 118 noOfRuleApplications++; 119 120 for (TaskTreeNode newParent : result.getNewlyCreatedParentNodes()) 121 { 122 noOfRuleApplications += 123 applyRules(newParent, builder, nodeFactory, true, logIndent + " "); 124 } 125 } 126 } 127 while ((result != null) && 128 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED)); 129 130 if ((!finalize) && (result != null) && 131 (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FEASIBLE)) 132 { 133 // in this case, don't go on applying rules, which should not be applied yet 134 break; 135 } 136 } 137 138 if (noOfRuleApplications <= 0) 139 { 140 LOG.warning(logIndent + "no rules applied --> no temporal relationship generated"); 141 } 142 143 return noOfRuleApplications; 144 } 145 146 //----------------------------------------------------------------------------------------------- 147 /** 148 * 149 */ 150 //----------------------------------------------------------------------------------------------- 151 /*private void dumpTask(TaskTreeNode task, String indent) 152 { 153 System.err.print(indent); 154 System.err.print(task); 155 System.err.println(" "); 156 157 if ((task.getChildren() != null) && (task.getChildren().size() > 0)) 158 { 159 for (TaskTreeNode child : task.getChildren()) 160 { 161 dumpTask(child, indent + " "); 162 } 163 } 164 }*/ 136 /* 137 * private void dumpTask(TaskTreeNode task, String indent) { System.err.print(indent); 138 * System.err.print(task); System.err.println(" "); 139 * 140 * if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { for (TaskTreeNode 141 * child : task.getChildren()) { dumpTask(child, indent + " "); } } } 142 */ 165 143 166 144 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TrackBarSelectionDetectionRule.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 28.04.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.temporalrelation; 9 8 10 import de.ugoe.cs.quest.eventcore.gui model.TrackBar;11 import de.ugoe.cs.quest.eventcore. userinteraction.ValueSelection;9 import de.ugoe.cs.quest.eventcore.gui.ValueSelection; 10 import de.ugoe.cs.quest.eventcore.guimodel.ITrackBar; 12 11 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEquality; 13 12 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 14 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;15 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;16 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;17 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;19 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;20 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;13 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 14 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 21 20 22 //-------------------------------------------------------------------------------------------------23 21 /** 24 22 * TODO comment … … 27 25 * @author 2012, last modified by $Author: patrick$ 28 26 */ 29 //------------------------------------------------------------------------------------------------- 30 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule 31 { 27 public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule { 32 28 33 /** */34 private NodeEqualityRuleManager mNodeEqualityRuleManager;29 /** */ 30 private NodeEqualityRuleManager nodeEqualityRuleManager; 35 31 36 //----------------------------------------------------------------------------------------------- 37 /** 38 * TODO: comment 32 /** 33 * TODO: comment 34 * 35 */ 36 TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) { 37 super(); 38 this.nodeEqualityRuleManager = nodeEqualityRuleManager; 39 } 40 41 /* 42 * (non-Javadoc) 43 * 44 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 45 */ 46 @Override 47 public RuleApplicationResult apply(ITaskTreeNode parent, 48 ITaskTreeBuilder builder, 49 ITaskTreeNodeFactory nodeFactory, 50 boolean finalize) 51 { 52 if (!(parent instanceof ISequence)) { 53 return null; 54 } 55 56 RuleApplicationResult result = new RuleApplicationResult(); 57 58 int valueSelectionStartIndex = -1; 59 60 int index = 0; 61 while (index < parent.getChildren().size()) { 62 ITaskTreeNode child = parent.getChildren().get(index); 63 64 if ((child instanceof IEventTask) && 65 (((IEventTask) child).getEventTarget() instanceof ITrackBar) && 66 (((IEventTask) child).getEventType() instanceof ValueSelection)) 67 { 68 if (valueSelectionStartIndex < 0) { 69 // let the show begin 70 valueSelectionStartIndex = index; 71 } 72 } 73 else if (valueSelectionStartIndex >= 0) { 74 // current child is no more value selection. But the preceding tasks were. 75 // Therefore, 76 // create an iteration with the different selectable values as selection children 77 handleValueSelections(valueSelectionStartIndex, index - 1, parent, builder, 78 nodeFactory, result); 79 80 return result; 81 } 82 83 index++; 84 } 85 86 if (valueSelectionStartIndex >= 0) { 87 if (finalize) { 88 handleValueSelections(valueSelectionStartIndex, parent.getChildren().size() - 1, 89 parent, builder, nodeFactory, result); 90 } 91 else { 92 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 93 } 94 } 95 96 return result; 97 } 98 99 /** 100 * TODO: comment 101 * 102 * @param valueSelectionStartIndex 103 * @param i 104 */ 105 private void handleValueSelections(int startIndex, 106 int endIndex, 107 ITaskTreeNode parent, 108 ITaskTreeBuilder builder, 109 ITaskTreeNodeFactory nodeFactory, 110 RuleApplicationResult result) 111 { 112 IIteration iteration = nodeFactory.createNewIteration(); 113 result.addNewlyCreatedParentNode(iteration); 114 115 ISelection selection = nodeFactory.createNewSelection(); 116 result.addNewlyCreatedParentNode(selection); 117 builder.setChild(iteration, selection); 118 119 for (int i = endIndex - startIndex; i >= 0; i--) { 120 addChildIfNecessary(selection, parent.getChildren().get(startIndex), builder, 121 nodeFactory, result); 122 builder.removeChild((ISequence) parent, startIndex); 123 } 124 125 builder.addChild((ISequence) parent, startIndex, iteration); 126 127 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 128 } 129 130 /** 39 131 * 40 132 */ 41 //----------------------------------------------------------------------------------------------- 42 TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) 43 { 44 super(); 45 mNodeEqualityRuleManager = nodeEqualityRuleManager; 46 } 133 private void addChildIfNecessary(ISelection parentSelection, 134 ITaskTreeNode node, 135 ITaskTreeBuilder builder, 136 ITaskTreeNodeFactory nodeFactory, 137 RuleApplicationResult result) 138 { 139 for (int i = 0; i < parentSelection.getChildren().size(); i++) { 140 ITaskTreeNode child = parentSelection.getChildren().get(i); 47 141 48 //----------------------------------------------------------------------------------------------- 49 /* (non-Javadoc) 50 * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) 51 */ 52 //----------------------------------------------------------------------------------------------- 53 @Override 54 public RuleApplicationResult apply(TaskTreeNode parent, 55 TaskTreeBuilder builder, 56 TaskTreeNodeFactory nodeFactory, 57 boolean finalize) 58 { 59 if (!(parent instanceof Sequence)) 60 { 61 return null; 62 } 63 64 RuleApplicationResult result = new RuleApplicationResult(); 65 66 int valueSelectionStartIndex = -1; 67 68 int index = 0; 69 while (index < parent.getChildren().size()) 70 { 71 TaskTreeNode child = parent.getChildren().get(index); 72 73 if ((child instanceof InteractionTask) && 74 (((InteractionTask) child).getGUIElement() instanceof TrackBar) && 75 (((InteractionTask) child).getInteraction() instanceof ValueSelection)) 76 { 77 if (valueSelectionStartIndex < 0) 78 { 79 // let the show begin 80 valueSelectionStartIndex = index; 81 } 82 } 83 else if (valueSelectionStartIndex >= 0) 84 { 85 // current child is no more value selection. But the preceding tasks were. Therefore, 86 // create an iteration with the different selectable values as selection children 87 handleValueSelections 88 (valueSelectionStartIndex, index - 1, parent, builder, nodeFactory, result); 89 90 return result; 91 } 92 93 index++; 94 } 95 96 if (valueSelectionStartIndex >= 0) 97 { 98 if (finalize) 99 { 100 handleValueSelections(valueSelectionStartIndex, parent.getChildren().size() - 1, parent, 101 builder, nodeFactory, result); 102 } 103 else 104 { 105 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE); 106 } 107 } 108 109 return result; 110 } 142 if (child instanceof IEventTask) { 143 // check, if the new node is a variant for the current event task 144 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 145 if (nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 146 // the node is a variant. If it not structurally equal, a new sub-selection for 147 // the existing and the new node must be created. Otherwise, the new node does 148 // not need to be added 149 if (!nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 150 ISelection selection = nodeFactory.createNewSelection(); 151 result.addNewlyCreatedParentNode(selection); 152 builder.addChild(parentSelection, selection); 111 153 112 //----------------------------------------------------------------------------------------------- 113 /** 114 * TODO: comment 115 * 116 * @param valueSelectionStartIndex 117 * @param i 118 */ 119 //----------------------------------------------------------------------------------------------- 120 private void handleValueSelections(int startIndex, 121 int endIndex, 122 TaskTreeNode parent, 123 TaskTreeBuilder builder, 124 TaskTreeNodeFactory nodeFactory, 125 RuleApplicationResult result) 126 { 127 Iteration iteration = nodeFactory.createNewIteration(); 128 result.addNewlyCreatedParentNode(iteration); 129 130 Selection selection = nodeFactory.createNewSelection(); 131 result.addNewlyCreatedParentNode(selection); 132 builder.setChild(iteration, selection); 133 134 for (int i = endIndex - startIndex; i >= 0 ; i--) 135 { 136 addChildIfNecessary 137 (selection, parent.getChildren().get(startIndex), builder, nodeFactory, result); 138 builder.removeChild((Sequence) parent, startIndex); 139 } 140 141 builder.addChild((Sequence) parent, startIndex, iteration); 142 143 result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); 144 } 154 builder.addChild(selection, child); 155 builder.addChild(selection, node); 156 builder.removeChild(parentSelection, child); 157 } 145 158 146 //----------------------------------------------------------------------------------------------- 147 /** 148 * 149 */ 150 //----------------------------------------------------------------------------------------------- 151 private void addChildIfNecessary(Selection parentSelection, 152 TaskTreeNode node, 153 TaskTreeBuilder builder, 154 TaskTreeNodeFactory nodeFactory, 155 RuleApplicationResult result) 156 { 157 for (int i = 0; i < parentSelection.getChildren().size(); i++) 158 { 159 TaskTreeNode child = parentSelection.getChildren().get(i); 159 return; 160 } 161 } 162 else if (child instanceof ISelection) { 163 // check, if the new node is a variant for the semantically equal children of the 164 // current 165 // selection 166 boolean addNode = true; 167 for (int j = 0; j < child.getChildren().size(); j++) { 168 NodeEquality nodeEquality = nodeEqualityRuleManager.applyRules(child, node); 169 if (!nodeEquality.isAtLeast(NodeEquality.SEMANTICALLY_EQUAL)) { 170 // the new node is no semantical equivalent of the nodes in the current 171 // selection - break up 172 addNode = false; 173 break; 174 } 175 else if (nodeEquality.isAtLeast(NodeEquality.LEXICALLY_EQUAL)) { 176 addNode = false; 177 break; 178 } 179 } 160 180 161 if (child instanceof InteractionTask) 162 { 163 // check, if the new node is a variant for the current interaction task 164 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules(child, node); 165 if (nodeEquality.getSemanticalEquality()) 166 { 167 // the node is a variant. If it not structurally equal, a new sub-selection for the 168 // existing and the new node must be created. Otherwise, the new node does not need 169 // to be added 170 if (!nodeEquality.getStructuralEquality()) 171 { 172 Selection selection = nodeFactory.createNewSelection(); 173 result.addNewlyCreatedParentNode(selection); 174 builder.addChild(parentSelection, selection); 175 176 builder.addChild(selection, child); 177 builder.addChild(selection, node); 178 builder.removeChild(parentSelection, child); 179 } 180 181 return; 182 } 183 } 184 else if (child instanceof Selection) 185 { 186 // check, if the new node is a variant for the semantically equal children of the current 187 // selection 188 boolean addNode = true; 189 for (int j = 0; j < child.getChildren().size(); j++) 190 { 191 NodeEquality nodeEquality = mNodeEqualityRuleManager.applyRules(child, node); 192 if (!nodeEquality.getSemanticalEquality()) 193 { 194 // the new node is no semantical equivalent of the nodes in the current selection - 195 // break up 196 addNode = false; 197 break; 198 } 199 else if (nodeEquality.getStructuralEquality()) 200 { 201 addNode = false; 202 break; 203 } 181 if (addNode) { 182 // the node is a semantical equivalent to all the nodes in the existing 183 // sub-selection 184 // but it is not structurally identical to either of them. Therefore add it. 185 builder.addChild((ISelection) child, node); 186 return; 187 } 188 } 204 189 } 205 190 206 if (addNode) 207 { 208 // the node is a semantical equivalent to all the nodes in the existing sub-selection 209 // but it is not structurally identical to either of them. Therefore add it. 210 builder.addChild((Selection) child, node); 211 return; 212 } 213 } 191 // if we did not return in the previous checks, then the node must be added 192 builder.addChild(parentSelection, node); 214 193 } 215 216 // if we did not return in the previous checks, then the node must be added217 builder.addChild(parentSelection, node);218 }219 194 220 195 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/IEventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: InteractionTask.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 19:44:52 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeifc; 10 8 11 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;12 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.IEventType; 13 11 14 //-------------------------------------------------------------------------------------------------15 12 /** 16 13 * TODO comment 17 * 14 * 18 15 * @version $Revision: $ $Date: $ 19 * @author 16 * @author 2011, last modified by $Author: $ 20 17 */ 21 //------------------------------------------------------------------------------------------------- 22 public interface InteractionTask extends TaskTreeNode 23 { 24 //----------------------------------------------------------------------------------------------- 25 /** 26 * @return Returns the interaction. 27 */ 28 //----------------------------------------------------------------------------------------------- 29 public Interaction getInteraction(); 18 public interface IEventTask extends ITaskTreeNode { 19 20 /** 21 * @return Returns the event type. 22 */ 23 public IEventType getEventType(); 30 24 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * @return Returns the GUIElement. 34 */ 35 //----------------------------------------------------------------------------------------------- 36 public GUIElement getGUIElement(); 25 /** 26 * @return Returns the event target. 27 */ 28 public IEventTarget getEventTarget(); 29 30 /** 31 * TODO: comment 32 * 33 * @return 34 */ 35 public IEventTask clone(); 37 36 38 37 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/IIteration.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Iteration.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface Iteration extends TemporalRelationship 19 { 15 public interface IIteration extends ITemporalRelationship { 16 17 /** 18 * TODO: comment 19 * 20 * @return 21 */ 22 public IIteration clone(); 20 23 21 24 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ISelection.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Selection.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface Selection extends TemporalRelationship 19 { 15 public interface ISelection extends ITemporalRelationship { 16 17 /** 18 * TODO: comment 19 * 20 * @return 21 */ 22 public ISelection clone(); 20 23 21 24 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ISequence.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Sequence.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface Sequence extends TemporalRelationship 19 { 15 public interface ISequence extends ITemporalRelationship { 20 16 21 //----------------------------------------------------------------------------------------------- 22 /** 23 * TODO: comment 24 * 25 * @return 26 */ 27 //----------------------------------------------------------------------------------------------- 28 public Sequence clone(); 17 /** 18 * TODO: comment 19 * 20 * @return 21 */ 22 public ISequence clone(); 29 23 30 24 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTree.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTree.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 9 import java.util.Map; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public interface TaskTree extends Cloneable 21 { 17 public interface ITaskTree extends Cloneable { 22 18 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * TODO: comment 26 * 27 * @return 28 */ 29 //----------------------------------------------------------------------------------------------- 30 public TaskTreeNode getRoot(); 19 /** 20 * TODO: comment 21 * 22 * @return 23 */ 24 public ITaskTreeNode getRoot(); 31 25 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * TODO: comment 35 * 36 * @return 37 */ 38 //----------------------------------------------------------------------------------------------- 39 public Map<TaskTreeNode, NodeInfo> getTaskMap(); 26 /** 27 * TODO: comment 28 * 29 * @return 30 */ 31 public Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap(); 40 32 41 //----------------------------------------------------------------------------------------------- 42 /** 43 * 44 */ 45 //----------------------------------------------------------------------------------------------- 46 public TaskTree clone(); 33 /** 34 * 35 */ 36 public ITaskTree clone(); 47 37 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeBuilder.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeBuilder.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeifc; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: patrick$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface TaskTreeBuilder 19 { 16 public interface ITaskTreeBuilder { 20 17 21 //----------------------------------------------------------------------------------------------- 22 /** 23 * TODO: comment 24 * 25 * @param sequence 26 * @param task 27 */ 28 //----------------------------------------------------------------------------------------------- 29 void addChild(Sequence parent, TaskTreeNode child); 18 /** 19 * TODO: comment 20 * 21 * @param sequence 22 * @param task 23 */ 24 void addChild(ISequence parent, ITaskTreeNode child); 30 25 31 //----------------------------------------------------------------------------------------------- 32 /** 33 * TODO: comment 34 * 35 * @param parent 36 * @param index 37 * @param sequence 38 */ 39 //----------------------------------------------------------------------------------------------- 40 void addChild(Sequence parent, int index, TaskTreeNode child); 26 /** 27 * TODO: comment 28 * 29 * @param parent 30 * @param index 31 * @param sequence 32 */ 33 void addChild(ISequence parent, int index, ITaskTreeNode child); 41 34 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * TODO: comment 45 * 46 * @param sequence 47 * @param task 48 */ 49 //----------------------------------------------------------------------------------------------- 50 void addChild(Selection parent, TaskTreeNode child); 35 /** 36 * TODO: comment 37 * 38 * @param sequence 39 * @param task 40 */ 41 void addChild(ISelection parent, ITaskTreeNode child); 51 42 52 //----------------------------------------------------------------------------------------------- 53 /** 54 * TODO: comment 55 * 56 * @param sequence 57 * @param task 58 */ 59 //----------------------------------------------------------------------------------------------- 60 void addChild(TextInputInteractionTask parent, TaskTreeNode child); 43 /** 44 * TODO: comment 45 * 46 * @param sequence 47 * @param task 48 */ 49 void addChild(ITextInputEventTask parent, ITaskTreeNode child); 61 50 62 //----------------------------------------------------------------------------------------------- 63 /** 64 * TODO: comment 65 * 66 * @param iteration 67 * @param newChild 68 */ 69 //----------------------------------------------------------------------------------------------- 70 void setChild(Iteration iteration, TaskTreeNode newChild); 51 /** 52 * TODO: comment 53 * 54 * @param iteration 55 * @param newChild 56 */ 57 void setChild(IIteration iteration, ITaskTreeNode newChild); 71 58 72 //----------------------------------------------------------------------------------------------- 73 /** 74 * TODO: comment 75 * 76 * @param parent 77 * @param i 78 */ 79 //----------------------------------------------------------------------------------------------- 80 void removeChild(Sequence parent, int index); 59 /** 60 * TODO: comment 61 * 62 * @param parent 63 * @param i 64 */ 65 void removeChild(ISequence parent, int index); 81 66 82 //----------------------------------------------------------------------------------------------- 83 /** 84 * TODO: comment 85 * 86 * @param parent 87 * @param i 88 */ 89 //----------------------------------------------------------------------------------------------- 90 void removeChild(Selection parent, TaskTreeNode child); 67 /** 68 * TODO: comment 69 * 70 * @param parent 71 * @param i 72 */ 73 void removeChild(ISelection parent, ITaskTreeNode child); 91 74 92 //----------------------------------------------------------------------------------------------- 93 /** 94 * TODO: comment 95 * 96 * @param parent 97 * @param i 98 */ 99 //----------------------------------------------------------------------------------------------- 100 void setDescription(TaskTreeNode parent, String description); 75 /** 76 * TODO: comment 77 * 78 * @param parent 79 * @param i 80 */ 81 void setDescription(ITaskTreeNode node, String description); 101 82 102 83 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeNode.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Task.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 08.11.2011 19:42:29 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeifc; … … 11 9 import java.util.List; 12 10 13 //-------------------------------------------------------------------------------------------------14 11 /** 15 12 * TODO comment 16 * 13 * 17 14 * @version $Revision: $ $Date: $ 18 * @author 15 * @author 2011, last modified by $Author: $ 19 16 */ 20 //------------------------------------------------------------------------------------------------- 21 public interface TaskTreeNode extends Cloneable 22 { 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * 26 */ 27 //----------------------------------------------------------------------------------------------- 28 public String getName(); 17 public interface ITaskTreeNode extends Cloneable { 29 18 30 //----------------------------------------------------------------------------------------------- 31 /** 32 */ 33 //----------------------------------------------------------------------------------------------- 34 //public void addChild(TaskTreeNode child); 35 36 //----------------------------------------------------------------------------------------------- 37 /** 38 */ 39 //----------------------------------------------------------------------------------------------- 40 //public void removeChild(int index); 41 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * 45 */ 46 //----------------------------------------------------------------------------------------------- 47 public String getDescription(); 19 /** 20 * 21 */ 22 public String getName(); 48 23 49 //----------------------------------------------------------------------------------------------- 50 /** 51 */ 52 //----------------------------------------------------------------------------------------------- 53 public List<TaskTreeNode> getChildren(); 54 55 //----------------------------------------------------------------------------------------------- 56 /** 57 * 58 */ 59 //----------------------------------------------------------------------------------------------- 60 public boolean equals(TaskTreeNode taskTreeNode); 24 /** 25 * 26 */ 27 public String getDescription(); 61 28 62 //----------------------------------------------------------------------------------------------- 63 /** 64 * 65 */ 66 //----------------------------------------------------------------------------------------------- 67 public int hashCode(); 29 /** 30 * 31 */ 32 public List<ITaskTreeNode> getChildren(); 68 33 69 //----------------------------------------------------------------------------------------------- 70 /** 71 * 72 */ 73 //----------------------------------------------------------------------------------------------- 74 public TaskTreeNode clone(); 34 /** 35 * 36 */ 37 public boolean equals(ITaskTreeNode taskTreeNode); 38 39 /** 40 * 41 */ 42 public int hashCode(); 43 44 /** 45 * 46 */ 47 public ITaskTreeNode clone(); 48 75 49 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeNodeFactory.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeNodeFactory.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.IEventType; 12 11 13 //-------------------------------------------------------------------------------------------------14 12 /** 15 13 * TODO comment … … 18 16 * @author 2012, last modified by $Author: patrick$ 19 17 */ 20 //------------------------------------------------------------------------------------------------- 21 public interface TaskTreeNodeFactory 18 public interface ITaskTreeNodeFactory 22 19 { 23 20 24 //-----------------------------------------------------------------------------------------------25 21 /** 26 22 * TODO: comment 27 23 * 28 * @param GUIElement29 * @param interaction24 * @param eventType 25 * @param eventTarget 30 26 * @return 31 27 */ 32 //----------------------------------------------------------------------------------------------- 33 InteractionTask createNewInteractionTask(GUIElement guiElement, 34 Interaction interaction); 28 IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget); 35 29 36 //-----------------------------------------------------------------------------------------------37 30 /** 38 31 * TODO: comment … … 40 33 * @return 41 34 */ 42 //----------------------------------------------------------------------------------------------- 43 Sequence createNewSequence(); 35 ISequence createNewSequence(); 44 36 45 //-----------------------------------------------------------------------------------------------46 37 /** 47 38 * TODO: comment … … 49 40 * @return 50 41 */ 51 //----------------------------------------------------------------------------------------------- 52 TextInputInteractionTask createNewTextInputInteractionTask(GUIElement guiElement); 42 ITextInputEventTask createNewTextInputEventTask(IEventTarget eventTarget); 53 43 54 //-----------------------------------------------------------------------------------------------55 44 /** 56 45 * TODO: comment … … 58 47 * @return 59 48 */ 60 //----------------------------------------------------------------------------------------------- 61 Iteration createNewIteration(); 49 IIteration createNewIteration(); 62 50 63 //-----------------------------------------------------------------------------------------------64 51 /** 65 52 * TODO: comment … … 67 54 * @return 68 55 */ 69 //----------------------------------------------------------------------------------------------- 70 Selection createNewSelection(); 56 ISelection createNewSelection(); 71 57 72 //-----------------------------------------------------------------------------------------------73 58 /** 74 59 * TODO: comment … … 77 62 * @return 78 63 */ 79 //----------------------------------------------------------------------------------------------- 80 TaskTree createTaskTree(TaskTreeNode root); 64 ITaskTree createTaskTree(ITaskTreeNode root); 81 65 82 66 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITaskTreeNodeInfo.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeInfo.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeifc; 10 8 11 //-------------------------------------------------------------------------------------------------12 9 /** 13 10 * TODO comment … … 16 13 * @author 2012, last modified by $Author: patrick$ 17 14 */ 18 //------------------------------------------------------------------------------------------------- 19 public interface NodeInfo 20 { 15 public interface ITaskTreeNodeInfo { 21 16 22 //----------------------------------------------------------------------------------------------- 23 /** 24 * 25 */ 26 //----------------------------------------------------------------------------------------------- 27 public TaskTreeNode getTask(); 17 /** 18 * 19 */ 20 public ITaskTreeNode getTask(); 28 21 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 public int getNoOfOccurencesInTree(); 22 /** 23 * 24 */ 25 public int getNoOfOccurencesInTree(); 35 26 36 //----------------------------------------------------------------------------------------------- 37 /** 38 * 39 */ 40 //----------------------------------------------------------------------------------------------- 41 public long getLastUpdate(); 27 /** 28 * 29 */ 30 public long getLastUpdate(); 42 31 43 32 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITemporalRelationship.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TemporalRelationship.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeifc; 9 8 10 //-------------------------------------------------------------------------------------------------11 9 /** 12 10 * TODO comment … … 15 13 * @author 2012, last modified by $Author: patrick$ 16 14 */ 17 // ------------------------------------------------------------------------------------------------- 18 public interface TemporalRelationship extends TaskTreeNode 19 { 15 public interface ITemporalRelationship extends ITaskTreeNode { 16 17 /** 18 * 19 */ 20 public ITemporalRelationship clone(); 20 21 21 22 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeifc/ITextInputEventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TextInputSequence.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 10.06.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeifc; 9 9 10 //-------------------------------------------------------------------------------------------------11 10 /** 12 11 * TODO comment … … 15 14 * @author 2012, last modified by $Author: patrick$ 16 15 */ 17 //------------------------------------------------------------------------------------------------- 18 public interface TextInputInteractionTask extends InteractionTask 19 { 20 //----------------------------------------------------------------------------------------------- 21 /** 22 * TODO: comment 23 * 24 * @return 25 */ 26 //----------------------------------------------------------------------------------------------- 27 public TextInputInteractionTask clone(); 16 public interface ITextInputEventTask extends IEventTask { 17 18 /** 19 * 20 */ 21 public String getEnteredText(); 28 22 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * 32 */ 33 //----------------------------------------------------------------------------------------------- 34 public String getEnteredText(); 23 /** 24 * TODO: comment 25 * 26 * @param string 27 */ 28 public void setEnteredText(String text); 29 30 /** 31 * TODO: comment 32 * 33 * @return 34 */ 35 public ITextInputEventTask clone(); 35 36 36 //-----------------------------------------------------------------------------------------------37 /**38 * TODO: comment39 *40 * @param string41 */42 //-----------------------------------------------------------------------------------------------43 public void setEnteredText(String text);44 37 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/EventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: InteractionTask.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 10:57:52 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 10 8 11 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;12 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;13 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.IEventType; 11 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 15 13 16 //-------------------------------------------------------------------------------------------------17 14 /** 18 15 * TODO comment 19 * 16 * 20 17 * @version $Revision: $ $Date: $ 21 * @author 18 * @author 2011, last modified by $Author: $ 22 19 */ 23 //------------------------------------------------------------------------------------------------- 24 public class InteractionTaskImpl extends TaskTreeNodeImpl implements InteractionTask 25 { 26 /** */ 27 private GUIElement mGUIElement; 28 29 /** */ 30 private Interaction mInteraction; 20 public class EventTask extends TaskTreeNode implements IEventTask { 21 22 /** */ 23 private IEventType eventType; 31 24 32 //----------------------------------------------------------------------------------------------- 33 /** 34 * @param guiElement 35 * @param interaction 36 */ 37 //----------------------------------------------------------------------------------------------- 38 InteractionTaskImpl(GUIElement guiElement, Interaction interaction) 39 { 40 super(interaction.getName() + "(" + guiElement + ")"); 41 super.setDescription(interaction + " on " + guiElement); 42 mGUIElement = guiElement; 43 mInteraction = interaction; 44 } 25 /** */ 26 private IEventTarget eventTarget; 45 27 46 //----------------------------------------------------------------------------------------------- 47 /** 48 * @return Returns the interaction. 49 */ 50 //----------------------------------------------------------------------------------------------- 51 public Interaction getInteraction() 52 { 53 return mInteraction; 54 } 28 /** 29 * @param eventType 30 * @param eventTarget 31 */ 32 EventTask(IEventType eventType, IEventTarget eventTarget) { 33 super(eventType.getName() + "(" + eventTarget + ")"); 34 super.setDescription(eventType + " on " + eventTarget); 35 this.eventType = eventType; 36 this.eventTarget = eventTarget; 37 } 55 38 56 57 //----------------------------------------------------------------------------------------------- 58 /** 59 * @return Returns the GUIElement. 60 */ 61 //----------------------------------------------------------------------------------------------- 62 public GUIElement getGUIElement() 63 { 64 return mGUIElement; 65 } 39 /** 40 * @return Returns the interaction. 41 */ 42 public IEventType getEventType() { 43 return eventType; 44 } 66 45 67 //----------------------------------------------------------------------------------------------- 68 /* (non-Javadoc) 69 * @see de.harms.ctte.Task#equals(de.harms.ctte.Task) 70 */ 71 //----------------------------------------------------------------------------------------------- 72 @Override 73 public boolean equals(TaskTreeNode task) 74 { 75 if (!(task instanceof InteractionTask)) 76 { 77 return false; 46 /** 47 * @return Returns the GUIElement. 48 */ 49 public IEventTarget getEventTarget() { 50 return eventTarget; 78 51 } 79 80 GUIElement otherInteractionElem = ((InteractionTask) task).getGUIElement(); 81 Interaction otherInteraction = ((InteractionTask) task).getInteraction(); 82 83 if ((((mGUIElement == null) && (otherInteractionElem == null)) || 84 ((mGUIElement != null) && (mGUIElement.equals(otherInteractionElem)))) && 85 (((mInteraction == null) && (otherInteraction == null)) || 86 ((mInteraction != null) && (mInteraction.equals(otherInteraction))))) 87 { 88 return true; 52 53 /* 54 * (non-Javadoc) 55 * 56 * @see de.harms.ctte.Task#equals(de.harms.ctte.Task) 57 */ 58 @Override 59 public boolean equals(ITaskTreeNode task) { 60 if (!(task instanceof IEventTask)) { 61 return false; 62 } 63 64 IEventType otherType = ((IEventTask) task).getEventType(); 65 IEventTarget otherTarget = ((IEventTask) task).getEventTarget(); 66 67 if (((eventType == otherType) || 68 ((eventType != null) && (eventType.equals(otherType)))) && 69 ((eventTarget == otherTarget) || 70 ((eventTarget != null) && (eventTarget.equals(otherTarget))))) 71 { 72 return true; 73 } 74 75 return false; 89 76 } 90 91 return false;92 }93 77 94 //----------------------------------------------------------------------------------------------- 95 /* (non-Javadoc) 96 * @see de.harms.tasktrees.TreeNode#clone() 97 */ 98 //----------------------------------------------------------------------------------------------- 99 @Override 100 public InteractionTaskImpl clone() 101 { 102 // GUI element and interaction are unchangeable and do not need to be cloned 103 return (InteractionTaskImpl) super.clone(); 104 } 78 /* 79 * (non-Javadoc) 80 * 81 * @see de.harms.tasktrees.TreeNode#clone() 82 */ 83 @Override 84 public EventTask clone() { 85 // Event type and target are unchangeable and do not need to be cloned 86 return (EventTask) super.clone(); 87 } 105 88 106 89 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/Iteration.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Iteration.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 7 8 8 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 9 10 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;11 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;10 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 12 12 13 //-------------------------------------------------------------------------------------------------14 13 /** 15 14 * TODO comment … … 18 17 * @author 2012, last modified by $Author: patrick$ 19 18 */ 20 //------------------------------------------------------------------------------------------------- 21 public class IterationImpl extends TaskTreeNodeImpl implements Iteration 22 { 19 public class Iteration extends TaskTreeNode implements IIteration { 23 20 24 //----------------------------------------------------------------------------------------------- 25 /** 26 * 27 */ 28 //----------------------------------------------------------------------------------------------- 29 IterationImpl() 30 { 31 super("Iteration"); 32 } 21 /** 22 * 23 */ 24 Iteration() { 25 super("Iteration"); 26 } 33 27 34 //-----------------------------------------------------------------------------------------------35 /* (non-Javadoc)36 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#addChild(TaskTreeNode)37 */38 //-----------------------------------------------------------------------------------------------39 @Override40 public void addChild(TaskTreeNode child)41 {42 // adding more children is not allowed43 throw new UnsupportedOperationException();44 }28 /* 29 * (non-Javadoc) 30 * 31 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#addChild(TaskTreeNode) 32 */ 33 @Override 34 public void addChild(ITaskTreeNode child) { 35 // adding more children is not allowed 36 throw new UnsupportedOperationException 37 ("iterations may not have a list of children. Use setChild() instead."); 38 } 45 39 46 //----------------------------------------------------------------------------------------------- 47 /** 48 * TODO: comment 49 * 50 * @param selection 51 * @return 52 */ 53 //----------------------------------------------------------------------------------------------- 54 public void setChild(TaskTreeNode child) 55 { 56 if (super.getChildren().size() > 0) 57 { 58 super.removeChild(0); 40 /** 41 * TODO: comment 42 * 43 * @param selection 44 * @return 45 */ 46 public void setChild(ITaskTreeNode child) { 47 if (super.getChildren().size() > 0) { 48 super.removeChild(0); 49 } 50 super.addChild(child); 59 51 } 60 super.addChild(child);61 }62 52 63 //----------------------------------------------------------------------------------------------- 64 /* (non-Javadoc) 65 * @see java.lang.Object#clone() 66 */ 67 //----------------------------------------------------------------------------------------------- 68 @Override 69 public IterationImpl clone() 70 { 71 return (IterationImpl) super.clone(); 72 } 53 /* 54 * (non-Javadoc) 55 * 56 * @see java.lang.Object#clone() 57 */ 58 @Override 59 public Iteration clone() { 60 return (Iteration) super.clone(); 61 } 73 62 74 63 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/NodeInfo.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: NodeInfo.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 05.11.2011 19:24:14 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeimpl; … … 12 10 import java.util.List; 13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc. NodeInfo;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 16 14 17 18 //-------------------------------------------------------------------------------------------------19 15 /** 20 16 * TODO comment 21 * 17 * 22 18 * @version $Revision: $ $Date: $ 23 * @author 19 * @author 2011, last modified by $Author: $ 24 20 */ 25 //------------------------------------------------------------------------------------------------- 26 public class NodeInfoImpl implements NodeInfo 27 { 28 /** */ 29 private TaskTreeNode mTask; 30 31 /** */ 32 private long mLastUpdate; 21 public class NodeInfo implements ITaskTreeNodeInfo { 22 23 /** */ 24 private ITaskTreeNode task; 33 25 34 /** */35 private List<TaskTreeNode> mParentNodes = new ArrayList<TaskTreeNode>();26 /** */ 27 private long lastUpdate; 36 28 37 //----------------------------------------------------------------------------------------------- 38 /** 39 * @param node 40 */ 41 //----------------------------------------------------------------------------------------------- 42 NodeInfoImpl(TaskTreeNode task) 43 { 44 mTask = task; 45 mLastUpdate = System.currentTimeMillis(); 46 } 29 /** */ 30 private List<ITaskTreeNode> parentNodes = new ArrayList<ITaskTreeNode>(); 47 31 48 //----------------------------------------------------------------------------------------------- 49 /* (non-Javadoc) 50 * @see de.ugoe.cs.tasktree.treeifc.NodeInfo#getTask() 51 */ 52 //----------------------------------------------------------------------------------------------- 53 @Override 54 public TaskTreeNode getTask() 55 { 56 return mTask; 57 } 32 /** 33 * @param node 34 */ 35 NodeInfo(ITaskTreeNode task) { 36 this.task = task; 37 lastUpdate = System.currentTimeMillis(); 38 } 58 39 59 //----------------------------------------------------------------------------------------------- 60 /* (non-Javadoc) 61 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getNoOfOccurencesInTree() 62 */ 63 //----------------------------------------------------------------------------------------------- 64 @Override 65 public int getNoOfOccurencesInTree() 66 { 67 return mParentNodes.size(); 68 } 40 /* 41 * (non-Javadoc) 42 * 43 * @see de.ugoe.cs.tasktree.treeifc.NodeInfo#getTask() 44 */ 45 @Override 46 public ITaskTreeNode getTask() { 47 return task; 48 } 69 49 70 //----------------------------------------------------------------------------------------------- 71 /* (non-Javadoc) 72 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getLastUpdate() 73 */ 74 //----------------------------------------------------------------------------------------------- 75 @Override 76 public long getLastUpdate() 77 { 78 return mLastUpdate; 79 } 50 /* 51 * (non-Javadoc) 52 * 53 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getNoOfOccurencesInTree() 54 */ 55 @Override 56 public int getNoOfOccurencesInTree() { 57 return parentNodes.size(); 58 } 80 59 81 //----------------------------------------------------------------------------------------------- 82 /** 83 * TODO: comment 84 * 85 */ 86 //----------------------------------------------------------------------------------------------- 87 void addParent(TaskTreeNode parent) 88 { 89 mParentNodes.add(parent); 90 } 60 /* 61 * (non-Javadoc) 62 * 63 * @see de.ugoe.cs.tasktree.treeimpl.NodeInfo#getLastUpdate() 64 */ 65 @Override 66 public long getLastUpdate() { 67 return lastUpdate; 68 } 91 69 92 //----------------------------------------------------------------------------------------------- 93 /** 94 * TODO: comment 95 * 96 */ 97 //----------------------------------------------------------------------------------------------- 98 void removeParent(TaskTreeNode parent) 99 { 100 mParentNodes.remove(parent); 101 } 70 /** 71 * TODO: comment 72 * 73 */ 74 void addParent(ITaskTreeNode parent) { 75 parentNodes.add(parent); 76 } 102 77 103 //----------------------------------------------------------------------------------------------- 104 /* (non-Javadoc) 105 * @see java.lang.Object#toString() 106 */ 107 //----------------------------------------------------------------------------------------------- 108 @Override 109 public synchronized String toString() 110 { 111 return "NodeInfo(" + mTask + ", " + mParentNodes.size() + " parents)"; 112 } 113 78 /** 79 * TODO: comment 80 * 81 */ 82 void removeParent(ITaskTreeNode parent) { 83 parentNodes.remove(parent); 84 } 85 86 /* 87 * (non-Javadoc) 88 * 89 * @see java.lang.Object#toString() 90 */ 91 @Override 92 public synchronized String toString() { 93 return "NodeInfo(" + task + ", " + parentNodes.size() + " parents)"; 94 } 95 114 96 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/Selection.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Selection.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.treeimpl; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public class SelectionImpl extends TaskTreeNodeImpl implements Selection 21 { 17 public class Selection extends TaskTreeNode implements ISelection { 22 18 23 //----------------------------------------------------------------------------------------------- 24 /** 25 * TODO: comment 26 * 27 * @param name 28 */ 29 //----------------------------------------------------------------------------------------------- 30 SelectionImpl() 31 { 32 super("Selection"); 33 } 19 /** 20 * TODO: comment 21 * 22 * @param name 23 */ 24 Selection() { 25 super("Selection"); 26 } 34 27 35 //----------------------------------------------------------------------------------------------- 36 /* (non-Javadoc) 37 * @see java.lang.Object#clone() 38 */ 39 //----------------------------------------------------------------------------------------------- 40 @Override 41 public SelectionImpl clone() 42 { 43 return (SelectionImpl) super.clone(); 44 } 28 /* 29 * (non-Javadoc) 30 * 31 * @see java.lang.Object#clone() 32 */ 33 @Override 34 public Selection clone() { 35 return (Selection) super.clone(); 36 } 45 37 46 38 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/Sequence.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: Sequence.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.treeimpl; 9 8 10 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;9 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 11 10 12 //-------------------------------------------------------------------------------------------------13 11 /** 14 12 * TODO comment … … 17 15 * @author 2012, last modified by $Author: patrick$ 18 16 */ 19 //------------------------------------------------------------------------------------------------- 20 public class SequenceImpl extends TaskTreeNodeImpl implements Sequence 21 { 22 //----------------------------------------------------------------------------------------------- 23 /** 24 * TODO: comment 25 * 26 * @param name 27 */ 28 //----------------------------------------------------------------------------------------------- 29 SequenceImpl() 30 { 31 super("Sequence"); 32 } 17 public class Sequence extends TaskTreeNode implements ISequence { 18 19 /** 20 * TODO: comment 21 * 22 * @param name 23 */ 24 Sequence() { 25 super("Sequence"); 26 } 33 27 34 //----------------------------------------------------------------------------------------------- 35 /** 36 * TODO: comment 37 * 38 * @param name 39 */ 40 //----------------------------------------------------------------------------------------------- 41 SequenceImpl(String name) 42 { 43 super(name); 44 } 28 /** 29 * TODO: comment 30 * 31 * @param name 32 */ 33 Sequence(String name) { 34 super(name); 35 } 45 36 46 //----------------------------------------------------------------------------------------------- 47 /* (non-Javadoc) 48 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 49 */ 50 //----------------------------------------------------------------------------------------------- 51 @Override 52 public SequenceImpl clone() 53 { 54 return (SequenceImpl) super.clone(); 55 } 37 /* 38 * (non-Javadoc) 39 * 40 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 41 */ 42 @Override 43 public Sequence clone() { 44 return (Sequence) super.clone(); 45 } 56 46 57 47 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTree.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTree.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 … … 11 10 import java.util.Map; 12 11 13 import de.ugoe.cs.quest.tasktrees.treeifc. NodeInfo;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;15 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeInfo; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeImpl implements TaskTree 26 { 27 /** the map of nodes */ 28 private Map<TaskTreeNode, NodeInfo> mTaskMap; 29 30 /** the root node of the task tree */ 31 private TaskTreeNode mRootNode; 32 33 //----------------------------------------------------------------------------------------------- 34 /** 35 * TODO: comment 36 * 37 */ 38 //----------------------------------------------------------------------------------------------- 39 TaskTreeImpl(TaskTreeNode rootNode) 40 { 41 mRootNode = rootNode; 42 } 22 public class TaskTree implements ITaskTree { 23 24 /** the map of nodes */ 25 private Map<ITaskTreeNode, ITaskTreeNodeInfo> taskMap; 43 26 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getRoot() 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public TaskTreeNode getRoot() 51 { 52 return mRootNode; 53 } 27 /** the root node of the task tree */ 28 private ITaskTreeNode rootNode; 54 29 55 //----------------------------------------------------------------------------------------------- 56 /* (non-Javadoc) 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getTaskMap() 58 */ 59 //----------------------------------------------------------------------------------------------- 60 @Override 61 public synchronized Map<TaskTreeNode, NodeInfo> getTaskMap() 62 { 63 if (mTaskMap == null) 64 { 65 mTaskMap = new HashMap<TaskTreeNode, NodeInfo>(); 66 addNodeToMap(mRootNode, null); 30 /** 31 * TODO: comment 32 * 33 */ 34 TaskTree(ITaskTreeNode rootNode) { 35 this.rootNode = rootNode; 67 36 } 68 return mTaskMap;69 }70 37 71 //----------------------------------------------------------------------------------------------- 72 /** 73 * TODO: comment 74 * 75 * @param rootNode 76 */ 77 //----------------------------------------------------------------------------------------------- 78 private void addNodeToMap(TaskTreeNode node, TaskTreeNode parent) 79 { 80 NodeInfoImpl nodeInfo = (NodeInfoImpl) mTaskMap.get(node); 81 82 if (nodeInfo == null) 83 { 84 nodeInfo = new NodeInfoImpl(node); 85 mTaskMap.put(node, nodeInfo); 38 /* 39 * (non-Javadoc) 40 * 41 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getRoot() 42 */ 43 @Override 44 public ITaskTreeNode getRoot() { 45 return rootNode; 86 46 } 87 88 if (parent != null) 89 { 90 // through first removing an existing parent it is assured, that a parent is recorded 91 // only once. This is needed, because parent may be reused in a tree as well, but we always 92 // iterate the whole tree 93 nodeInfo.removeParent(parent); 94 nodeInfo.addParent(parent); 47 48 /* 49 * (non-Javadoc) 50 * 51 * @see de.ugoe.cs.tasktree.treeifc.TaskTree#getTaskMap() 52 */ 53 @Override 54 public synchronized Map<ITaskTreeNode, ITaskTreeNodeInfo> getTaskMap() { 55 if (taskMap == null) { 56 taskMap = new HashMap<ITaskTreeNode, ITaskTreeNodeInfo>(); 57 addNodeToMap(rootNode, null); 58 } 59 return taskMap; 95 60 } 96 97 for (TaskTreeNode child : node.getChildren()) 98 { 99 addNodeToMap(child, node); 61 62 /** 63 * TODO: comment 64 * 65 * @param rootNode 66 */ 67 private void addNodeToMap(ITaskTreeNode node, ITaskTreeNode parent) { 68 NodeInfo nodeInfo = (NodeInfo) taskMap.get(node); 69 70 if (nodeInfo == null) { 71 nodeInfo = new NodeInfo(node); 72 taskMap.put(node, nodeInfo); 73 } 74 75 if (parent != null) { 76 // through first removing an existing parent it is assured, that a parent is recorded 77 // only once. This is needed, because parent may be reused in a tree as well, but we 78 // always iterate the whole tree 79 nodeInfo.removeParent(parent); 80 nodeInfo.addParent(parent); 81 } 82 83 for (ITaskTreeNode child : node.getChildren()) { 84 addNodeToMap(child, node); 85 } 100 86 } 101 }102 87 103 //----------------------------------------------------------------------------------------------- 104 /* (non-Javadoc) 105 * @see java.lang.Object#clone() 106 */ 107 //----------------------------------------------------------------------------------------------- 108 @Override 109 public TaskTreeImpl clone() 110 { 111 TaskTreeImpl clone = null; 112 try 113 { 114 clone = (TaskTreeImpl) super.clone(); 115 116 clone.mRootNode = mRootNode.clone(); 117 118 // the clone will create the task map itself, when it is first retrieved 119 clone.mTaskMap = null; 120 88 /* 89 * (non-Javadoc) 90 * 91 * @see java.lang.Object#clone() 92 */ 93 @Override 94 public TaskTree clone() { 95 TaskTree clone = null; 96 try { 97 clone = (TaskTree) super.clone(); 98 99 clone.rootNode = rootNode.clone(); 100 101 // the clone will create the task map itself, when it is first retrieved 102 clone.taskMap = null; 103 104 } 105 catch (CloneNotSupportedException e) { 106 // this should never happen. Therefore simply dump the exception 107 e.printStackTrace(); 108 } 109 110 return clone; 121 111 } 122 catch (CloneNotSupportedException e)123 {124 // this should never happen. Therefore simply dump the exception125 e.printStackTrace();126 }127 128 return clone;129 }130 112 131 113 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeBuilder.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeBuilderImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 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. Sequence;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;14 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;15 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;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.ISequence; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeBuilderImpl implements TaskTreeBuilder 26 { 27 //-----------------------------------------------------------------------------------------------28 /* (non-Javadoc)29 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode)30 */31 //-----------------------------------------------------------------------------------------------32 @Override33 public void addChild(Sequence parent, TaskTreeNode child)34 {35 if (!(parent instanceof SequenceImpl))36 {37 throw new IllegalArgumentException 38 ("illegal type of task tree node provided: " + parent.getClass());22 public class TaskTreeBuilder implements ITaskTreeBuilder { 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode) 28 */ 29 @Override 30 public void addChild(ISequence parent, ITaskTreeNode child) { 31 if (!(parent instanceof Sequence)) { 32 throw new IllegalArgumentException 33 ("illegal type of task tree node provided: " + parent.getClass()); 34 } 35 36 addChildInternal(parent, -1, child); 39 37 } 40 38 41 addChildInternal(parent, -1, child); 42 } 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) 43 */ 44 @Override 45 public void addChild(ISequence parent, int index, ITaskTreeNode child) { 46 if (!(parent instanceof Sequence)) { 47 throw new IllegalArgumentException 48 ("illegal type of task tree node provided: " + parent.getClass()); 49 } 43 50 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public void addChild(Sequence parent, int index, TaskTreeNode child) 51 { 52 if (!(parent instanceof SequenceImpl)) 53 { 54 throw new IllegalArgumentException 55 ("illegal type of task tree node provided: " + parent.getClass()); 51 addChildInternal(parent, index, child); 56 52 } 57 53 58 addChildInternal(parent, index, child); 59 } 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) 58 */ 59 @Override 60 public void addChild(ISelection parent, ITaskTreeNode child) { 61 if (!(parent instanceof Selection)) { 62 throw new IllegalArgumentException 63 ("illegal type of task tree node provided: " + parent.getClass()); 64 } 60 65 61 //----------------------------------------------------------------------------------------------- 62 /* (non-Javadoc) 63 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) 64 */ 65 //----------------------------------------------------------------------------------------------- 66 @Override 67 public void addChild(Selection parent, TaskTreeNode child) 68 { 69 if (!(parent instanceof SelectionImpl)) 70 { 71 throw new IllegalArgumentException 72 ("illegal type of task tree node provided: " + parent.getClass()); 66 addChildInternal(parent, -1, child); 73 67 } 74 68 75 addChildInternal(parent, -1, child); 76 } 69 /* 70 * (non-Javadoc) 71 * 72 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc. 73 * TextInputEventTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 74 */ 75 @Override 76 public void addChild(ITextInputEventTask parent, ITaskTreeNode child) { 77 if (!(parent instanceof TextInputEventTask)) { 78 throw new IllegalArgumentException 79 ("illegal type of task tree node provided: " + parent.getClass()); 80 } 77 81 78 //----------------------------------------------------------------------------------------------- 79 /* (non-Javadoc) 80 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc.TextInputInteractionTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 81 */ 82 //----------------------------------------------------------------------------------------------- 83 @Override 84 public void addChild(TextInputInteractionTask parent, TaskTreeNode child) 85 { 86 if (!(parent instanceof TextInputInteractionTaskImpl)) 87 { 88 throw new IllegalArgumentException 89 ("illegal type of task tree node provided: " + parent.getClass()); 82 addChildInternal(parent, -1, child); 90 83 } 91 84 92 addChildInternal(parent, -1, child); 93 } 85 /* 86 * (non-Javadoc) 87 * 88 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) 89 */ 90 @Override 91 public void setChild(IIteration iteration, ITaskTreeNode newChild) { 92 if (!(iteration instanceof Iteration)) { 93 throw new IllegalArgumentException 94 ("illegal type of iteration provided: " + iteration.getClass()); 95 } 94 96 95 //----------------------------------------------------------------------------------------------- 96 /* (non-Javadoc) 97 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) 98 */ 99 //----------------------------------------------------------------------------------------------- 100 @Override 101 public void setChild(Iteration iteration, TaskTreeNode newChild) 102 { 103 if (!(iteration instanceof IterationImpl)) 104 { 105 throw new IllegalArgumentException 106 ("illegal type of iteration provided: " + iteration.getClass()); 97 if (!(newChild instanceof TaskTreeNode)) { 98 throw new IllegalArgumentException 99 ("illegal type of task tree node provided: " + newChild.getClass()); 100 } 101 102 ((Iteration) iteration).setChild(newChild); 107 103 } 108 104 109 if (!(newChild instanceof TaskTreeNodeImpl)) 110 { 111 throw new IllegalArgumentException 112 ("illegal type of task tree node provided: " + newChild.getClass()); 113 } 114 115 ((IterationImpl) iteration).setChild(determineNode(newChild)); 116 } 105 /* 106 * (non-Javadoc) 107 * 108 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) 109 */ 110 @Override 111 public void removeChild(ISequence parent, int index) { 112 if (!(parent instanceof TaskTreeNode)) { 113 throw new IllegalArgumentException 114 ("illegal type of task tree node provided: " + parent.getClass()); 115 } 117 116 118 //----------------------------------------------------------------------------------------------- 119 /* (non-Javadoc) 120 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) 121 */ 122 //----------------------------------------------------------------------------------------------- 123 @Override 124 public void removeChild(Sequence parent, int index) 125 { 126 if (!(parent instanceof TaskTreeNodeImpl)) 127 { 128 throw new IllegalArgumentException 129 ("illegal type of task tree node provided: " + parent.getClass()); 117 ((TaskTreeNode) parent).removeChild(index); 130 118 } 131 119 132 ((TaskTreeNodeImpl) parent).removeChild(index); 133 } 120 /* 121 * (non-Javadoc) 122 * 123 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) 124 */ 125 @Override 126 public void removeChild(ISelection parent, ITaskTreeNode child) { 127 if (!(parent instanceof TaskTreeNode)) { 128 throw new IllegalArgumentException 129 ("illegal type of task tree node provided: " + parent.getClass()); 130 } 134 131 135 //----------------------------------------------------------------------------------------------- 136 /* (non-Javadoc) 137 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) 138 */ 139 //----------------------------------------------------------------------------------------------- 140 @Override 141 public void removeChild(Selection parent, TaskTreeNode child) 142 { 143 if (!(parent instanceof TaskTreeNodeImpl)) 144 { 145 throw new IllegalArgumentException 146 ("illegal type of task tree node provided: " + parent.getClass()); 132 for (int i = 0; i < parent.getChildren().size(); i++) { 133 if ((parent.getChildren().get(i) == child) || 134 ((parent.getChildren().get(i) != null) && 135 (parent.getChildren().get(i).equals(child)))) 136 { 137 ((TaskTreeNode) parent).removeChild(i); 138 break; 139 } 140 } 147 141 } 148 142 149 for (int i = 0; i < parent.getChildren().size(); i++) 150 { 151 if ((parent.getChildren().get(i) == child) || 152 ((parent.getChildren().get(i) != null) && (parent.getChildren().get(i).equals(child)))) 153 { 154 ((TaskTreeNodeImpl) parent).removeChild(i); 155 break; 156 } 157 } 158 } 143 /* 144 * (non-Javadoc) 145 * 146 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) 147 */ 148 @Override 149 public void setDescription(ITaskTreeNode parent, String description) { 150 if (!(parent instanceof TaskTreeNode)) { 151 throw new IllegalArgumentException 152 ("illegal type of task tree node provided: " + parent.getClass()); 153 } 159 154 160 //----------------------------------------------------------------------------------------------- 161 /* (non-Javadoc) 162 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) 163 */ 164 //----------------------------------------------------------------------------------------------- 165 @Override 166 public void setDescription(TaskTreeNode parent, String description) 167 { 168 if (!(parent instanceof TaskTreeNodeImpl)) 169 { 170 throw new IllegalArgumentException 171 ("illegal type of task tree node provided: " + parent.getClass()); 155 ((TaskTreeNode) parent).setDescription(description); 172 156 } 173 157 174 ((TaskTreeNodeImpl) parent).setDescription(description); 175 } 176 177 //----------------------------------------------------------------------------------------------- 178 /** 158 /** 179 159 * 180 160 */ 181 //----------------------------------------------------------------------------------------------- 182 private void addChildInternal(TaskTreeNode parent, int index, TaskTreeNode child) 183 { 184 if (!(child instanceof TaskTreeNodeImpl)) 185 { 186 throw new IllegalArgumentException 187 ("illegal type of task tree node provided: " + child.getClass()); 161 private void addChildInternal(ITaskTreeNode parent, int index, ITaskTreeNode child) { 162 if (!(child instanceof TaskTreeNode)) { 163 throw new IllegalArgumentException 164 ("illegal type of task tree node provided: " + child.getClass()); 165 } 166 167 if (index > -1) { 168 ((TaskTreeNode) parent).addChild(index, child); 169 } 170 else { 171 ((TaskTreeNode) parent).addChild(child); 172 } 188 173 } 189 190 if (index > -1)191 {192 ((TaskTreeNodeImpl) parent).addChild(index, determineNode(child));193 }194 else195 {196 ((TaskTreeNodeImpl) parent).addChild(determineNode(child));197 }198 }199 200 //-----------------------------------------------------------------------------------------------201 /**202 * TODO: comment203 *204 * @param newChild205 * @return206 */207 //-----------------------------------------------------------------------------------------------208 private TaskTreeNode determineNode(TaskTreeNode newNode)209 {210 return newNode;211 /*TaskTreeNode node = mTaskMap.get(newNode);212 if (node == null)213 {214 node = newNode;215 mTaskMap.put(node, node);216 }217 218 return node;*/219 }220 174 221 175 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeNode.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TreeNode.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 11:00:46 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.treeimpl; … … 12 10 import java.util.List; 13 11 14 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 15 16 17 //------------------------------------------------------------------------------------------------- 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 13 18 14 /** 19 15 * TODO comment 20 * 16 * 21 17 * @version $Revision: $ $Date: $ 22 * @author 18 * @author 2011, last modified by $Author: $ 23 19 */ 24 //------------------------------------------------------------------------------------------------- 25 public class TaskTreeNodeImpl implements TaskTreeNode 26 { 27 /** */ 28 private static int sTemporalId = 0; 29 30 /** */ 31 private String mName; 32 33 /** */ 34 private String mDescription; 35 36 /** */ 37 private int mId; 38 39 /** children */ 40 private List<TaskTreeNode> mChildren; 41 42 //----------------------------------------------------------------------------------------------- 43 /** 44 */ 45 //----------------------------------------------------------------------------------------------- 46 TaskTreeNodeImpl(String name) 47 { 48 mName = name; 49 mId = getNewId(); 50 } 51 52 //----------------------------------------------------------------------------------------------- 53 /** 54 * TODO: comment 55 * 56 * @return 57 */ 58 //----------------------------------------------------------------------------------------------- 59 private static synchronized int getNewId() 60 { 61 if (sTemporalId == Integer.MAX_VALUE) 62 { 63 sTemporalId = 0; 64 } 65 66 return sTemporalId++; 67 } 68 69 //----------------------------------------------------------------------------------------------- 70 /** 71 * @return Returns the name. 72 */ 73 //----------------------------------------------------------------------------------------------- 74 public String getName() 75 { 76 return mName; 77 } 78 79 //----------------------------------------------------------------------------------------------- 80 /* (non-Javadoc) 81 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#getDescription() 82 */ 83 //----------------------------------------------------------------------------------------------- 84 @Override 85 public String getDescription() 86 { 87 return mDescription; 88 } 89 90 //----------------------------------------------------------------------------------------------- 91 /** 92 */ 93 //----------------------------------------------------------------------------------------------- 94 public synchronized List<TaskTreeNode> getChildren() 95 { 96 if ((mChildren == null) || (mChildren.size() == 0)) 97 { 98 return new ArrayList<TaskTreeNode>(); 99 } 100 101 return mChildren.subList(0, mChildren.size()); 102 } 103 104 //----------------------------------------------------------------------------------------------- 105 /* (non-Javadoc) 106 * @see de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode) 107 */ 108 //----------------------------------------------------------------------------------------------- 109 @Override 110 public boolean equals(TaskTreeNode taskTreeNode) 111 { 112 if (!this.getClass().isInstance(taskTreeNode)) 113 { 114 return false; 115 } 116 117 if (taskTreeNode.hashCode() != hashCode()) 118 { 119 return false; 120 } 121 122 TaskTreeNodeImpl other = (TaskTreeNodeImpl) taskTreeNode; 123 124 if (mId != other.mId) 125 { 126 return false; 127 } 128 129 if (!mName.equals(other.mName)) 130 { 131 return false; 132 } 133 134 synchronized (other) 135 { 136 if (mChildren == null) 137 { 138 return (other.mChildren == null); 139 } 140 else if (other.mChildren == null) 141 { 142 return (mChildren == null); 143 } 144 else if (other.mChildren.size() != mChildren.size()) 145 { 146 return false; 147 } 148 149 for (int i = 0; i < mChildren.size(); i++) 150 { 151 if (!mChildren.get(i).equals(other.mChildren.get(i))) 152 { 153 return false; 154 } 155 } 156 } 157 158 return true; 159 } 160 161 //----------------------------------------------------------------------------------------------- 162 /* (non-Javadoc) 163 * @see java.lang.Object#hashCode() 164 */ 165 //----------------------------------------------------------------------------------------------- 166 @Override 167 public synchronized int hashCode() 168 { 169 return getClass().getSimpleName().hashCode(); 170 } 171 172 //----------------------------------------------------------------------------------------------- 173 /* (non-Javadoc) 174 * @see java.lang.Object#toString() 175 */ 176 //----------------------------------------------------------------------------------------------- 177 @Override 178 public synchronized String toString() 179 { 180 if (mChildren == null) 181 { 182 return mName + "(" + mId + ")"; 183 } 184 else 185 { 186 return mName + "(" + mId + ", " + mChildren.size() + " children)"; 187 } 188 } 189 190 //----------------------------------------------------------------------------------------------- 191 /** 192 * TODO: comment 193 * 194 * @param i 195 * @return 196 */ 197 //----------------------------------------------------------------------------------------------- 198 void setDescription(String description) 199 { 200 mDescription = description; 201 } 202 203 //----------------------------------------------------------------------------------------------- 204 /** 205 */ 206 //----------------------------------------------------------------------------------------------- 207 synchronized void addChild(TaskTreeNode child) 208 { 209 if (mChildren == null) 210 { 211 mChildren = new ArrayList<TaskTreeNode>(); 212 } 213 214 mChildren.add(child); 215 } 216 217 //----------------------------------------------------------------------------------------------- 218 /** 219 */ 220 //----------------------------------------------------------------------------------------------- 221 synchronized void addChild(int index, TaskTreeNode child) 222 { 223 if (mChildren == null) 224 { 225 mChildren = new ArrayList<TaskTreeNode>(); 226 } 227 228 mChildren.add(index, child); 229 } 230 231 //----------------------------------------------------------------------------------------------- 232 /** 233 * TODO: comment 234 * 235 * @param i 236 * @return 237 */ 238 //----------------------------------------------------------------------------------------------- 239 synchronized TaskTreeNode removeChild(int index) 240 { 241 return mChildren.remove(index); 242 } 243 244 //----------------------------------------------------------------------------------------------- 245 /* (non-Javadoc) 246 * @see java.lang.Object#clone() 247 */ 248 //----------------------------------------------------------------------------------------------- 249 @Override 250 public TaskTreeNode clone() 251 { 252 TaskTreeNodeImpl clone = null; 253 try 254 { 255 clone = (TaskTreeNodeImpl) super.clone(); 256 257 if (mChildren != null) 258 { 259 clone.mChildren = new ArrayList<TaskTreeNode>(); 260 261 for (TaskTreeNode child : mChildren) 262 { 263 clone.mChildren.add(child.clone()); 264 } 265 } 266 267 } 268 catch (CloneNotSupportedException e) 269 { 270 // this should never happen. Therefore simply dump the exception 271 e.printStackTrace(); 272 } 273 274 return clone; 275 } 20 public class TaskTreeNode implements ITaskTreeNode { 21 /** */ 22 private static int temporalId = 0; 23 24 /** */ 25 private String name; 26 27 /** */ 28 private String description; 29 30 /** */ 31 private int id; 32 33 /** children */ 34 private List<ITaskTreeNode> children; 35 36 /** 37 * 38 */ 39 public TaskTreeNode(String name) { 40 this.name = name; 41 id = getNewId(); 42 } 43 44 /** 45 * TODO: comment 46 * 47 * @return 48 */ 49 private static synchronized int getNewId() { 50 if (temporalId == Integer.MAX_VALUE) { 51 temporalId = 0; 52 } 53 54 return temporalId++; 55 } 56 57 /** 58 * @return Returns the name. 59 */ 60 public String getName() { 61 return name; 62 } 63 64 /* 65 * (non-Javadoc) 66 * 67 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNode#getDescription() 68 */ 69 @Override 70 public String getDescription() { 71 return description; 72 } 73 74 /** 75 * 76 */ 77 public synchronized List<ITaskTreeNode> getChildren() { 78 if ((children == null) || (children.size() == 0)) { 79 return new ArrayList<ITaskTreeNode>(); 80 } 81 82 return children.subList(0, children.size()); 83 } 84 85 /* 86 * (non-Javadoc) 87 * 88 * @see de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode) 89 */ 90 @Override 91 public boolean equals(ITaskTreeNode taskTreeNode) { 92 if (!this.getClass().isInstance(taskTreeNode)) { 93 return false; 94 } 95 96 if (taskTreeNode.hashCode() != hashCode()) { 97 return false; 98 } 99 100 TaskTreeNode other = (TaskTreeNode) taskTreeNode; 101 102 if (id != other.id) { 103 return false; 104 } 105 106 if (!name.equals(other.name)) { 107 return false; 108 } 109 110 synchronized (other) { 111 if (children == null) { 112 return (other.children == null); 113 } 114 else if (other.children == null) { 115 return (children == null); 116 } 117 else if (other.children.size() != children.size()) { 118 return false; 119 } 120 121 for (int i = 0; i < children.size(); i++) { 122 if (!children.get(i).equals(other.children.get(i))) { 123 return false; 124 } 125 } 126 } 127 128 return true; 129 } 130 131 /* 132 * (non-Javadoc) 133 * 134 * @see java.lang.Object#hashCode() 135 */ 136 @Override 137 public synchronized int hashCode() { 138 return getClass().getSimpleName().hashCode(); 139 } 140 141 /* 142 * (non-Javadoc) 143 * 144 * @see java.lang.Object#toString() 145 */ 146 @Override 147 public synchronized String toString() { 148 if (children == null) { 149 return name + "(" + id + ")"; 150 } 151 else { 152 return name + "(" + id + ", " + children.size() + " children)"; 153 } 154 } 155 156 /** 157 * TODO: comment 158 * 159 * @param i 160 * @return 161 */ 162 void setDescription(String description) { 163 this.description = description; 164 } 165 166 /** 167 * 168 */ 169 synchronized void addChild(ITaskTreeNode child) { 170 if (children == null) { 171 children = new ArrayList<ITaskTreeNode>(); 172 } 173 174 children.add(child); 175 } 176 177 /** 178 * 179 */ 180 synchronized void addChild(int index, ITaskTreeNode child) { 181 if (children == null) { 182 children = new ArrayList<ITaskTreeNode>(); 183 } 184 185 children.add(index, child); 186 } 187 188 /** 189 * TODO: comment 190 * 191 * @param i 192 * @return 193 */ 194 synchronized ITaskTreeNode removeChild(int index) { 195 return children.remove(index); 196 } 197 198 /* 199 * (non-Javadoc) 200 * 201 * @see java.lang.Object#clone() 202 */ 203 @Override 204 public ITaskTreeNode clone() { 205 TaskTreeNode clone = null; 206 try { 207 clone = (TaskTreeNode) super.clone(); 208 209 if (children != null) { 210 clone.children = new ArrayList<ITaskTreeNode>(); 211 212 for (ITaskTreeNode child : children) { 213 clone.children.add(child.clone()); 214 } 215 } 216 217 } 218 catch (CloneNotSupportedException e) { 219 // this should never happen. Therefore simply dump the exception 220 e.printStackTrace(); 221 } 222 223 return clone; 224 } 276 225 277 226 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TaskTreeNodeFactory.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeNodeFactoryImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 7 8 8 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 9 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.Interaction;12 import de.ugoe.cs.quest.tasktrees.treeifc.I nteractionTask;13 import de.ugoe.cs.quest.tasktrees.treeifc.I teration;14 import de.ugoe.cs.quest.tasktrees.treeifc. Selection;15 import de.ugoe.cs.quest.tasktrees.treeifc. Sequence;16 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTree;17 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNode;18 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;19 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;10 import de.ugoe.cs.quest.eventcore.IEventTarget; 11 import de.ugoe.cs.quest.eventcore.IEventType; 12 import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask; 13 import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 14 import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 15 import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 16 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 17 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 18 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 19 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 20 20 21 //-------------------------------------------------------------------------------------------------22 21 /** 23 22 * TODO comment … … 26 25 * @author 2012, last modified by $Author: patrick$ 27 26 */ 28 //------------------------------------------------------------------------------------------------- 29 public class TaskTreeNodeFactoryImpl implements TaskTreeNodeFactory 30 { 27 public class TaskTreeNodeFactory implements ITaskTreeNodeFactory { 31 28 32 //----------------------------------------------------------------------------------------------- 33 /* (non-Javadoc) 34 * @see TaskTreeNodeFactory#createNewInteractionTask(GUIElement, Interaction) 35 */ 36 //----------------------------------------------------------------------------------------------- 37 @Override 38 public InteractionTask createNewInteractionTask(GUIElement guiElement, 39 Interaction interaction) 40 { 41 return new InteractionTaskImpl(guiElement, interaction); 42 } 29 /* 30 * (non-Javadoc) 31 * 32 * @see TaskTreeNodeFactory#createNewEventTask(IEventType, IEventTarget) 33 */ 34 @Override 35 public IEventTask createNewEventTask(IEventType eventType, IEventTarget eventTarget) { 36 return new EventTask(eventType, eventTarget); 37 } 43 38 44 //----------------------------------------------------------------------------------------------- 45 /* (non-Javadoc) 46 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSequence() 47 */ 48 //----------------------------------------------------------------------------------------------- 49 @Override 50 public Sequence createNewSequence() 51 { 52 return new SequenceImpl(); 53 } 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSequence() 43 */ 44 @Override 45 public ISequence createNewSequence() { 46 return new Sequence(); 47 } 54 48 55 //----------------------------------------------------------------------------------------------- 56 /* (non-Javadoc) 57 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewTextInputInteractionTask() 58 */ 59 //----------------------------------------------------------------------------------------------- 60 @Override 61 public TextInputInteractionTask createNewTextInputInteractionTask(GUIElement guiElement) 62 { 63 return new TextInputInteractionTaskImpl(guiElement); 64 } 49 /* 50 * (non-Javadoc) 51 * 52 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewTextInputEventTask(eventTarget) 53 */ 54 @Override 55 public ITextInputEventTask createNewTextInputEventTask(IEventTarget eventTarget) { 56 return new TextInputEventTask(eventTarget); 57 } 65 58 66 //----------------------------------------------------------------------------------------------- 67 /* (non-Javadoc) 68 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewIteration() 69 */ 70 //----------------------------------------------------------------------------------------------- 71 @Override 72 public Iteration createNewIteration() 73 { 74 return new IterationImpl(); 75 } 59 /* 60 * (non-Javadoc) 61 * 62 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewIteration() 63 */ 64 @Override 65 public IIteration createNewIteration() { 66 return new Iteration(); 67 } 76 68 77 //----------------------------------------------------------------------------------------------- 78 /* (non-Javadoc) 79 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSelection() 80 */ 81 //----------------------------------------------------------------------------------------------- 82 @Override 83 public Selection createNewSelection() 84 { 85 return new SelectionImpl(); 86 } 69 /* 70 * (non-Javadoc) 71 * 72 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createNewSelection() 73 */ 74 @Override 75 public ISelection createNewSelection() { 76 return new Selection(); 77 } 87 78 88 //----------------------------------------------------------------------------------------------- 89 /* (non-Javadoc) 90 * @see de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createTaskTree(de.ugoe.cs.tasktree.treeifc.TaskTreeNode) 91 */ 92 //----------------------------------------------------------------------------------------------- 93 @Override 94 public TaskTree createTaskTree(TaskTreeNode root) 95 { 96 return new TaskTreeImpl(root); 97 } 79 /* 80 * (non-Javadoc) 81 * 82 * @see 83 * de.ugoe.cs.tasktree.treeifc.TaskTreeNodeFactory#createTaskTree(de.ugoe.cs.tasktree.treeifc 84 * .TaskTreeNode) 85 */ 86 @Override 87 public ITaskTree createTaskTree(ITaskTreeNode root) { 88 return new TaskTree(root); 89 } 98 90 99 91 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/treeimpl/TextInputEventTask.java
r498 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TextInputSequenceImpl.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 10.06.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.treeimpl; 9 8 10 import de.ugoe.cs.quest.eventcore. guimodel.GUIElement;11 import de.ugoe.cs.quest.eventcore. userinteraction.TextInput;12 import de.ugoe.cs.quest.tasktrees.treeifc. TextInputInteractionTask;9 import de.ugoe.cs.quest.eventcore.IEventTarget; 10 import de.ugoe.cs.quest.eventcore.gui.TextInput; 11 import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 13 12 14 //-------------------------------------------------------------------------------------------------15 13 /** 16 14 * TODO comment … … 19 17 * @author 2012, last modified by $Author: patrick$ 20 18 */ 21 //------------------------------------------------------------------------------------------------- 22 public class TextInputInteractionTaskImpl extends InteractionTaskImpl 23 implements TextInputInteractionTask 24 { 19 public class TextInputEventTask extends EventTask implements ITextInputEventTask { 25 20 26 /** the text, that was finally entered in this sequence without all backspaces, etc. */ 27 private String mEnteredText; 28 29 //----------------------------------------------------------------------------------------------- 30 /** 31 * TODO: comment 32 * 33 * @param name 34 */ 35 //----------------------------------------------------------------------------------------------- 36 TextInputInteractionTaskImpl(GUIElement guiElement) 37 { 38 super(guiElement, new TextInput()); 39 } 21 /** the text, that was finally entered in this sequence without all backspaces, etc. */ 22 private String enteredText; 40 23 41 //----------------------------------------------------------------------------------------------- 42 /* (non-Javadoc) 43 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 44 */ 45 //----------------------------------------------------------------------------------------------- 46 @Override 47 public TextInputInteractionTaskImpl clone() 48 { 49 // entered text is unchangeable and does not need to be cloned 50 return (TextInputInteractionTaskImpl) super.clone(); 51 } 24 /** 25 * TODO: comment 26 * 27 * @param name 28 */ 29 TextInputEventTask(IEventTarget eventTarget) { 30 super(new TextInput(), eventTarget); 31 } 52 32 53 //-----------------------------------------------------------------------------------------------54 /* (non-Javadoc)55 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#getEnteredText()56 */57 //-----------------------------------------------------------------------------------------------58 @Override59 public String getEnteredText()60 {61 return mEnteredText;62 }33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.tasktree.treeimpl.TaskTreeNodeImpl#clone() 37 */ 38 @Override 39 public TextInputEventTask clone() { 40 // entered text is unchangeable and does not need to be cloned 41 return (TextInputEventTask) super.clone(); 42 } 63 43 64 //----------------------------------------------------------------------------------------------- 65 /* (non-Javadoc) 66 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#setEnteredText(java.lang.String) 67 */ 68 //----------------------------------------------------------------------------------------------- 69 @Override 70 public void setEnteredText(String text) 71 { 72 mEnteredText = text; 73 } 44 /* 45 * (non-Javadoc) 46 * 47 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#getEnteredText() 48 */ 49 @Override 50 public String getEnteredText() { 51 return enteredText; 52 } 74 53 75 //----------------------------------------------------------------------------------------------- 76 /* (non-Javadoc) 77 * @see java.lang.Object#toString() 78 */ 79 //----------------------------------------------------------------------------------------------- 80 @Override 81 public synchronized String toString() 82 { 83 if (super.getChildren() == null) 84 { 85 return super.getName(); 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.tasktree.treeifc.TextInputSequence#setEnteredText(java.lang.String) 58 */ 59 @Override 60 public void setEnteredText(String text) { 61 enteredText = text; 86 62 } 87 else 88 { 89 return "TextInputInteraction(\"" + mEnteredText + "\", " + super.getChildren().size() + 90 " children)"; 63 64 /* 65 * (non-Javadoc) 66 * 67 * @see java.lang.Object#toString() 68 */ 69 @Override 70 public synchronized String toString() { 71 if (super.getChildren() == null) { 72 return super.getName(); 73 } 74 else { 75 return 76 "TextInputInteraction(\"" + enteredText + "\", " + super.getChildren().size() + 77 " children)"; 78 } 91 79 } 92 } 93 80 94 81 }
Note: See TracChangeset
for help on using the changeset viewer.