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 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.tasktree.filter;
|
---|
16 |
|
---|
17 | import java.util.List;
|
---|
18 |
|
---|
19 | import com.google.common.base.Predicate;
|
---|
20 | import com.google.common.collect.LinkedListMultimap;
|
---|
21 | import com.google.common.collect.Lists;
|
---|
22 | import com.google.common.collect.Multimap;
|
---|
23 |
|
---|
24 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
|
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * <p>
|
---|
30 | * TODO comment
|
---|
31 | * </p>
|
---|
32 | *
|
---|
33 | * @author Alexander Deicke
|
---|
34 | */
|
---|
35 | public class FilterStatistic {
|
---|
36 |
|
---|
37 | @SuppressWarnings("rawtypes")
|
---|
38 | private final Predicate filterPredicate;
|
---|
39 |
|
---|
40 | private List<ITaskTreeNode> filteredNodes = Lists.newArrayList();
|
---|
41 |
|
---|
42 | private List<ITaskTreeNode> nodesNotMatchedFilter = Lists.newArrayList();
|
---|
43 |
|
---|
44 | @SuppressWarnings("rawtypes")
|
---|
45 | public FilterStatistic(Predicate filterPredicate) {
|
---|
46 | this.filterPredicate = filterPredicate;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @SuppressWarnings("unchecked")
|
---|
50 | public void addNode(ITaskTreeNode node) {
|
---|
51 | if (filterPredicate.apply(node)) {
|
---|
52 | filteredNodes.add(node);
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | nodesNotMatchedFilter.add(node);
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public List<ITaskTreeNode> nodesMatchedFilter() {
|
---|
60 | return this.filteredNodes;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public int nrOfNodesMatchedFilter() {
|
---|
64 | return this.filteredNodes.size();
|
---|
65 | }
|
---|
66 |
|
---|
67 | public List<ITaskTreeNode> nodesNotMatchedFilter() {
|
---|
68 | return this.nodesNotMatchedFilter;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public int nrOfNodesNotMatchedFilter() {
|
---|
72 | return this.nodesNotMatchedFilter.size();
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * <p>
|
---|
77 | * TODO: comment
|
---|
78 | * </p>
|
---|
79 | *
|
---|
80 | * @param eventTargetParent
|
---|
81 | * @return
|
---|
82 | */
|
---|
83 | public Multimap<IGUIElement, ITaskTreeNode> groupBy() {
|
---|
84 | Multimap<IGUIElement, ITaskTreeNode> groupedNodes = LinkedListMultimap.create();
|
---|
85 | for(ITaskTreeNode node : filteredNodes) {
|
---|
86 | IGUIElement eventTask = (IGUIElement) ((IEventTask) node).getEventTarget();
|
---|
87 | groupedNodes.put(eventTask.getParent(), node);
|
---|
88 | }
|
---|
89 | return groupedNodes;
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|