Changeset 1217 for trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/rules/patterns/InteractionPatternVisitor.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/InteractionPatternVisitor.java
r1204 r1217 25 25 import de.ugoe.cs.autoquest.eventcore.StringEventType; 26 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 27 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 28 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 29 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskVisitor; 30 import de.ugoe.cs.autoquest.usability.task tree.filters.EventTypeFilter;31 import de.ugoe.cs.autoquest.usability.task tree.filters.TaskTypeFilter;33 import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter; 34 import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter; 32 35 33 36 /** … … 39 42 */ 40 43 public abstract class InteractionPatternVisitor implements ITaskVisitor { 41 42 43 44 45 protected TaskTypeFilter taskType; 46 44 47 protected EventTypeFilter eventType; 45 48 46 49 protected InteractionPattern containedPattern; 47 50 48 51 protected boolean present = false; 49 52 50 53 protected List<ITask> retainedSelectionTasks = Lists.newArrayList(); 51 52 /* (non-Javadoc) 53 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.NodeVisitor#visit(de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask) 54 55 /* 56 * (non-Javadoc) 57 * 58 * @see 59 * de.ugoe.cs.autoquest.tasktrees.treeifc.NodeVisitor#visit(de.ugoe.cs.autoquest.tasktrees.treeifc 60 * .IEventTask) 54 61 */ 55 62 public void visit(IEventTask event) { 56 if (!this.present && isEventVisitor()) {63 if (!this.present && isEventVisitor()) { 57 64 IEventType eventType = event.getEventType(); 58 if (eventType instanceof StringEventType) {65 if (eventType instanceof StringEventType) { 59 66 this.present = eventType.toString().equals(nameOfEventType()); 60 } else { 67 } 68 else { 61 69 this.present = eventType.getClass().equals(this.eventType.clazz()); 62 70 } 63 71 } 64 72 } 65 73 66 74 public boolean isEventVisitor() { 67 75 return this.eventType != null && this.containedPattern == null; 68 76 } 69 77 70 78 protected String nameOfEventType() { 71 79 String ret = StringUtils.EMPTY; 72 80 Iterable<String> splitted = Splitter.on("_").split(this.eventType.name()); 73 for (String str : splitted) {81 for (String str : splitted) { 74 82 str = str.toLowerCase(); 75 83 ret += Character.toString(str.charAt(0)).toUpperCase() + str.substring(1); … … 77 85 return ret; 78 86 } 79 80 /* (non-Javadoc) 81 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.TaskVisitor#accept(de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 87 88 /* 89 * (non-Javadoc) 90 * 91 * @see 92 * de.ugoe.cs.autoquest.tasktrees.treeifc.TaskVisitor#accept(de.ugoe.cs.autoquest.tasktrees. 93 * treeifc.ITask) 82 94 */ 83 95 @Override 84 96 public void visit(ITask task) { 85 task.accept(this); 86 97 if (task instanceof ISequence) { 98 this.visit((ISequence) task); 99 } 100 else if (task instanceof IIteration) { 101 this.visit((IIteration) task); 102 } 103 else if (task instanceof ISelection) { 104 this.visit((ISelection) task); 105 } 106 else { 107 this.visit((IOptional) task); 108 } 87 109 } 88 89 /* (non-Javadoc) 90 * @see de.ugoe.cs.autoquest.tasktrees.treeifc.NodeVisitor#visit(de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection) 110 111 /* 112 * (non-Javadoc) 113 * 114 * @see 115 * de.ugoe.cs.autoquest.tasktrees.treeifc.NodeVisitor#visit(de.ugoe.cs.autoquest.tasktrees.treeifc 116 * .ISelection) 91 117 */ 92 118 public void visit(ISelection selection) { 93 if (isEventVisitor()) {119 if (isEventVisitor()) { 94 120 retainNodesWherePatternIsPresent(selection); 95 121 this.present = patternIsPresent(); 96 } else { 97 this.present = containedPattern.containedIn(selection); 122 } 123 else { 124 this.present = containedPattern.containedIn(selection); 98 125 } 99 126 } 100 127 101 128 @SuppressWarnings("unchecked") 102 103 for (ITask task : selection.getChildren()) {129 protected void retainNodesWherePatternIsPresent(ISelection selection) { 130 for (ITask task : selection.getChildren()) { 104 131 this.present = false; 105 132 task.accept(this); 106 if (this.present && this.taskType.filterPredicate().apply(selection)) {133 if (this.present && this.taskType.filterPredicate().apply(selection)) { 107 134 this.retainedSelectionTasks.add(selection); 108 135 } 109 if (this.present) {110 136 if (this.present) { 137 break; 111 138 } 112 139 } 113 140 } 114 141 115 142 private boolean patternIsPresent() { 116 143 return !this.retainedSelectionTasks.isEmpty(); 117 144 } 118 145 119 146 /** 120 147 * <p> 121 148 * TODO: comment 122 149 * </p> 123 * 150 * 124 151 * @return 125 152 */ … … 132 159 * TODO: comment 133 160 * </p> 134 * 161 * 135 162 */ 136 163 public void reset() { … … 143 170 * TODO: comment 144 171 * </p> 145 * 172 * 146 173 * @return 147 174 */ … … 154 181 * TODO: comment 155 182 * </p> 156 * 183 * 157 184 * @return 158 185 */ … … 160 187 return this.retainedSelectionTasks; 161 188 } 162 189 163 190 }
Note: See TracChangeset
for help on using the changeset viewer.