Changeset 1217 for trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/rules/patterns/InteractionPattern.java
- Timestamp:
- 06/06/13 17:08:25 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/rules/patterns/InteractionPattern.java
r1204 r1217 15 15 package de.ugoe.cs.autoquest.usability.rules.patterns; 16 16 17 import java.util.Arrays;18 17 import java.util.List; 19 18 … … 24 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 25 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 26 import de.ugoe.cs.autoquest.usability.task tree.IterativeDFSFilterStrategy;27 import de.ugoe.cs.autoquest.usability.task tree.filters.TaskModelFilter;28 import de.ugoe.cs.autoquest.usability.task tree.filters.TaskTypeFilter;25 import de.ugoe.cs.autoquest.usability.taskmodel.filter.IterativeDFSFilterStrategy; 26 import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskModelFilter; 27 import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter; 29 28 30 29 /** 31 30 * <p> 32 * TODO comment31 * A interaction pattern is a simple approach to describe the structure of usage behaviour. 33 32 * </p> 34 33 * … … 36 35 */ 37 36 public class InteractionPattern { 38 37 38 /** 39 * <p> 40 * {@link TaskModelFilter}, which is used to filter a task model after different {@link ITask}s 41 * </p> 42 */ 39 43 private TaskModelFilter taskTreeFilter = new TaskModelFilter(new IterativeDFSFilterStrategy()); 40 41 private TaskTypeFilter concernedTask; 42 44 45 /** 46 * <p> 47 * Type of root task. Determines the order in which sub task appear. 48 * </p> 49 */ 50 private TaskTypeFilter rootTask; 51 52 /** 53 * <p> 54 * Helper objects, which decide whether or not a defined pattern condition holds. 55 * </p> 56 */ 43 57 private List<InteractionPatternVisitor> patternVisitors; 44 58 59 /** 60 * <p> 61 * Flag, which indicates if the interaction pattern was found within a given task model. 62 * </p> 63 */ 45 64 private boolean present = false; 46 47 /** 48 * <p> 49 * TODO: comment 50 * </p> 51 * 52 * @param concernedNode 53 * @param eventType 54 */ 55 public InteractionPattern(TaskTypeFilter concernedNode, 56 InteractionPatternVisitor... patternVisitor) 65 66 /** 67 * <p> 68 * Constructor. Creates a new interaction pattern for a given root task and a collection of 69 * {@link InteractionPatternVisitor}s. 70 * </p> 71 * 72 * @param rootTask 73 * Type of root task, which determines the order in which sub task appear. 74 * @param patternVisitors 75 * {@link InteractionPatternVisitor}s, which decide whether or not a defined pattern 76 * condition holds 77 */ 78 public InteractionPattern(TaskTypeFilter rootTask, 79 List<InteractionPatternVisitor> patternVisitors) 57 80 { 58 this.patternVisitors = Arrays.asList(patternVisitor); 59 this.concernedTask = concernedNode; 60 } 61 81 this.patternVisitors = patternVisitors; 82 this.rootTask = rootTask; 83 } 84 85 /** 86 * 87 * <p> 88 * Checks if a interaction pattern is contained in a given task model. 89 * </p> 90 * 91 * @param taskModel 92 * {@link ITaskModel}, which might contain the interaction pattern 93 * @return true, iff interaction pattern is contained 94 */ 62 95 public boolean containedIn(ITaskModel taskModel) { 63 96 List<ITask> allConcernedTasks = filterAllConcernedTasksFrom(taskModel); 64 for(ITask concernedTask : allConcernedTasks) { 65 checkTask(concernedTask); 66 if(this.present) break; 97 for (ITask concernedTask : allConcernedTasks) { 98 checkTask(concernedTask); 99 if (this.present) 100 break; 67 101 } 68 102 return this.present; 69 103 } 70 104 71 private void checkTask(ITask concernedTask) { 72 applyAllVisitors(concernedTask); 73 if(allVisitorsArePresent()) { 105 /** 106 * 107 * <p> 108 * Checks a single {@link ITask} for the interaction pattern. 109 * </p> 110 * 111 * @param task 112 * task, which might contain the interaction pattern 113 */ 114 private void checkTask(ITask task) { 115 applyAllVisitors(task); 116 if (allVisitorsArePresent()) { 74 117 this.present = true; 75 } else { 118 } 119 else { 76 120 resetAllVisitors(); 77 121 } 78 122 } 79 123 124 /** 125 * 126 * <p> 127 * Checks if a interaction pattern is contained in a given task. 128 * </p> 129 * 130 * @param task 131 * task, which might contain the interaction pattern 132 * @return true, iff interaction pattern is contained 133 */ 80 134 public boolean containedIn(ITask task) { 81 135 checkTask(task); 82 return this.present; 83 } 84 85 private void applyAllVisitors(ITask concernedTask) { 136 return this.present; 137 } 138 139 /** 140 * 141 * <p> 142 * Method applys all {@link InteractionPatternVisitor}s, to check single interaction pattern 143 * conditions. 144 * </p> 145 * 146 * @param task 147 * task, which might contain the interaction pattern 148 */ 149 private void applyAllVisitors(ITask task) { 86 150 Optional<InteractionPatternVisitor> previousVisitor = Optional.absent(); 87 for(InteractionPatternVisitor visitor : patternVisitors) { 88 if (appliedOnSelectionNode(previousVisitor)) { 89 for (ITask selection : previousVisitor.get().getRetainedSelectionNodes()) { 90 selection.accept(visitor); 91 } 92 } else { 93 previousVisitor = Optional.of(visitor); 94 concernedTask.accept(visitor); 95 } 96 } 97 } 98 99 private boolean appliedOnSelectionNode(Optional<InteractionPatternVisitor> previousVisitor) { 100 return previousVisitor.isPresent() && previousVisitor.get().hasExcludedSelectionNodes(); 101 } 102 103 /** 104 * <p> 105 * TODO: comment 106 * </p> 107 * 108 * @param taskTree 109 * @return 151 for (InteractionPatternVisitor visitor : patternVisitors) { 152 if (appliedOnSelectionNode(previousVisitor)) { 153 for (ITask selection : previousVisitor.get().getRetainedSelectionNodes()) { 154 selection.accept(visitor); 155 } 156 } 157 else { 158 previousVisitor = Optional.of(visitor); 159 task.accept(visitor); 160 } 161 } 162 } 163 164 /** 165 * 166 * <p> 167 * Checks, if a {@link InteractionPatternVisitor} was applied on a {@link ISelection} task. 168 * </p> 169 * 170 * @param interactionPatternVisitor 171 * {@link InteractionPatternVisitor} 172 * @return true, iff {@link InteractionPatternVisitor} was applied on {@link ISelection} task 173 */ 174 private boolean appliedOnSelectionNode(Optional<InteractionPatternVisitor> interactionPatternVisitor) 175 { 176 return interactionPatternVisitor.isPresent() && 177 interactionPatternVisitor.get().hasExcludedSelectionNodes(); 178 } 179 180 /** 181 * <p> 182 * Filters given task model after root task of interaction pattern. 183 * </p> 184 * 185 * @param taskModel 186 * {@link ITaskModel} 187 * @return all tasks of task model, which matches root task of interaction pattern 110 188 */ 111 189 private List<ITask> filterAllConcernedTasksFrom(ITaskModel taskModel) { 112 return this.taskTreeFilter.filterByNodeType(this.concernedTask).from(taskModel).tasksMatchedFilter(); 113 } 114 115 /** 116 * <p> 117 * TODO: comment 118 * </p> 119 * 120 * @return 190 return this.taskTreeFilter.filterByNodeType(this.rootTask).from(taskModel) 191 .tasksMatchedFilter(); 192 } 193 194 /** 195 * <p> 196 * Checks, if all interaction pattern condition are evaluated to true. 197 * </p> 198 * 199 * @return true, iff all interaction pattern condition are true 121 200 */ 122 201 private boolean allVisitorsArePresent() { 123 Iterable<InteractionPatternVisitor> allPresent = Iterables.filter(this.patternVisitors, new Predicate<InteractionPatternVisitor>() { 124 125 public boolean apply(InteractionPatternVisitor visitor) { 126 return visitor.isPresent(); 127 } 128 129 }); 202 Iterable<InteractionPatternVisitor> allPresent = 203 Iterables.filter(this.patternVisitors, new Predicate<InteractionPatternVisitor>() { 204 205 public boolean apply(InteractionPatternVisitor visitor) { 206 return visitor.isPresent(); 207 } 208 209 }); 130 210 return Iterables.size(allPresent) == this.patternVisitors.size(); 131 211 } 132 133 /** 134 * <p> 135 * TODO: comment136 * </p> 137 * 212 213 /** 214 * <p> 215 * Resets all interaction pattern condition. 216 * </p> 217 * 138 218 */ 139 219 private void resetAllVisitors() { 140 for (InteractionPatternVisitor visitor : this.patternVisitors) {220 for (InteractionPatternVisitor visitor : this.patternVisitors) { 141 221 visitor.reset(); 142 222 } 143 223 144 224 } 145 225
Note: See TracChangeset
for help on using the changeset viewer.