source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/tasktree/IterativeDFSFilterStrategy.java @ 1135

Last change on this file since 1135 was 1135, checked in by adeicke, 11 years ago

Restructuring of package structure.

  • Property svn:mime-type set to text/plain
File size: 3.4 KB
Line 
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
15package de.ugoe.cs.autoquest.usability.tasktree;
16
17import java.util.LinkedList;
18import java.util.Queue;
19
20import com.google.common.base.Predicate;
21
22import de.ugoe.cs.autoquest.eventcore.IEventTarget;
23import de.ugoe.cs.autoquest.eventcore.IEventType;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
26import de.ugoe.cs.autoquest.usability.tasktree.filters.EventTargetFilter;
27import de.ugoe.cs.autoquest.usability.tasktree.filters.EventTypeFilter;
28import de.ugoe.cs.autoquest.usability.tasktree.filters.TaskTreeNodeTypeFilter;
29
30/**
31 * <p>
32 * TODO comment
33 * </p>
34 *
35 * @author Alexander Deicke
36 */
37public class IterativeDFSFilterStrategy implements TaskTreeFilterStrategy {
38
39    private FilterResult filterStatistic;
40
41    @SuppressWarnings("unchecked")
42    @Override
43    public FilterResult filter(ITaskTree taskTree, EventTargetFilter eventTarget) {
44        Predicate<IEventTarget> filterPredicate = eventTarget.filterPredicate();
45        this.filterStatistic = new FilterResult(filterPredicate);
46        traverse(taskTree);
47        return this.filterStatistic;
48    }
49
50    @SuppressWarnings("unchecked")
51    @Override
52    public FilterResult filter(ITaskTree taskTree, EventTypeFilter eventType) {
53        Predicate<IEventType> filterPredicate = eventType.filterPredicate();
54        this.filterStatistic = new FilterResult(filterPredicate);
55        traverse(taskTree);
56        return this.filterStatistic;
57    }
58
59    @SuppressWarnings("unchecked")
60    @Override
61    public FilterResult filter(ITaskTree taskTree, TaskTreeNodeTypeFilter nodeType) {
62        Predicate<ITaskTreeNode> filterPredicate = nodeType.filterPredicate();
63        this.filterStatistic = new FilterResult(filterPredicate);
64        traverse(taskTree);
65        return this.filterStatistic;
66    }
67
68    private void traverse(ITaskTree taskTree) {
69        Queue<ITaskTreeNode> unvisitedNodes = new LinkedList<ITaskTreeNode>();
70        unvisitedNodes.add(taskTree.getRoot());
71        while (stillUnvisitedNodes(unvisitedNodes)) {
72            ITaskTreeNode node = unvisitedNodes.poll();
73            processCurrentNode(node);
74            processChildrenOfCurrentNode(unvisitedNodes, node);
75        }
76    }
77
78    private boolean stillUnvisitedNodes(Queue<ITaskTreeNode> unvisitedNodes) {
79        return !unvisitedNodes.isEmpty();
80    }
81
82    private void processCurrentNode(ITaskTreeNode node) {
83        this.filterStatistic.addNode(node);
84    }
85
86    private void processChildrenOfCurrentNode(Queue<ITaskTreeNode> unvisitedNodes,
87                                              ITaskTreeNode node)
88    {
89        for (ITaskTreeNode child : node.getChildren()) {
90            unvisitedNodes.add(child);
91        }
92    }
93
94}
Note: See TracBrowser for help on using the repository browser.