[1040] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[1217] | 15 | package de.ugoe.cs.autoquest.usability.taskmodel.filter;
|
---|
[1030] | 16 |
|
---|
[1135] | 17 | import java.util.LinkedList;
|
---|
| 18 | import java.util.Queue;
|
---|
[1030] | 19 |
|
---|
| 20 | import com.google.common.base.Predicate;
|
---|
| 21 |
|
---|
| 22 | import de.ugoe.cs.autoquest.eventcore.IEventTarget;
|
---|
| 23 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
[1152] | 24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship;
|
---|
| 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship;
|
---|
| 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
[1217] | 28 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTargetFilter;
|
---|
| 29 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter;
|
---|
| 30 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter;
|
---|
[1030] | 31 |
|
---|
[1040] | 32 | /**
|
---|
| 33 | * <p>
|
---|
| 34 | * TODO comment
|
---|
| 35 | * </p>
|
---|
| 36 | *
|
---|
| 37 | * @author Alexander Deicke
|
---|
| 38 | */
|
---|
[1152] | 39 | public class IterativeDFSFilterStrategy implements TaskModelFilterStrategy {
|
---|
[1040] | 40 |
|
---|
[1135] | 41 | private FilterResult filterStatistic;
|
---|
[1040] | 42 |
|
---|
[1030] | 43 | @SuppressWarnings("unchecked")
|
---|
| 44 | @Override
|
---|
[1152] | 45 | public FilterResult filter(ITaskModel taskModel, EventTargetFilter eventTarget) {
|
---|
[1030] | 46 | Predicate<IEventTarget> filterPredicate = eventTarget.filterPredicate();
|
---|
[1135] | 47 | this.filterStatistic = new FilterResult(filterPredicate);
|
---|
[1152] | 48 | traverse(taskModel);
|
---|
[1030] | 49 | return this.filterStatistic;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | @SuppressWarnings("unchecked")
|
---|
| 53 | @Override
|
---|
[1152] | 54 | public FilterResult filter(ITaskModel taskModel, EventTypeFilter eventType) {
|
---|
[1030] | 55 | Predicate<IEventType> filterPredicate = eventType.filterPredicate();
|
---|
[1135] | 56 | this.filterStatistic = new FilterResult(filterPredicate);
|
---|
[1152] | 57 | traverse(taskModel);
|
---|
[1030] | 58 | return this.filterStatistic;
|
---|
| 59 | }
|
---|
[1040] | 60 |
|
---|
| 61 | @SuppressWarnings("unchecked")
|
---|
| 62 | @Override
|
---|
[1152] | 63 | public FilterResult filter(ITaskModel taskModel, TaskTypeFilter nodeType) {
|
---|
| 64 | Predicate<ITask> filterPredicate = nodeType.filterPredicate();
|
---|
[1135] | 65 | this.filterStatistic = new FilterResult(filterPredicate);
|
---|
[1152] | 66 | traverse(taskModel);
|
---|
[1040] | 67 | return this.filterStatistic;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[1152] | 70 | private void traverse(ITaskModel taskModel) {
|
---|
| 71 | Queue<ITask> unvisitedTasks = new LinkedList<ITask>();
|
---|
| 72 | unvisitedTasks.addAll(taskModel.getTasks());
|
---|
| 73 | while (stillUnvisitedTasks(unvisitedTasks)) {
|
---|
| 74 | ITask task = unvisitedTasks.poll();
|
---|
| 75 | processCurrentTask(task);
|
---|
| 76 | processChildrenOfCurrentTask(unvisitedTasks, task);
|
---|
[1030] | 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[1152] | 80 | private boolean stillUnvisitedTasks(Queue<ITask> unvisitedTasks) {
|
---|
| 81 | return !unvisitedTasks.isEmpty();
|
---|
[1030] | 82 | }
|
---|
| 83 |
|
---|
[1152] | 84 | private void processCurrentTask(ITask task) {
|
---|
| 85 | this.filterStatistic.addTask(task);
|
---|
[1030] | 86 | }
|
---|
[1040] | 87 |
|
---|
[1217] | 88 | private void processChildrenOfCurrentTask(Queue<ITask> unvisitedTasks, ITask task) {
|
---|
[1152] | 89 | if (task instanceof IStructuringTemporalRelationship) {
|
---|
| 90 | for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) {
|
---|
| 91 | unvisitedTasks.add(child);
|
---|
| 92 | }
|
---|
[1030] | 93 | }
|
---|
[1152] | 94 | else if (task instanceof IMarkingTemporalRelationship) {
|
---|
| 95 | unvisitedTasks.add(((IMarkingTemporalRelationship) task).getMarkedTask());
|
---|
| 96 | }
|
---|
[1030] | 97 | }
|
---|
| 98 |
|
---|
| 99 | }
|
---|