[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 |
|
---|
| 17 | import com.google.common.base.Predicate;
|
---|
| 18 |
|
---|
| 19 | import de.ugoe.cs.autoquest.eventcore.IEventTarget;
|
---|
| 20 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
[1152] | 21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
| 22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
[1217] | 23 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTargetFilter;
|
---|
| 24 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter;
|
---|
| 25 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskTypeFilter;
|
---|
[1030] | 26 |
|
---|
[1040] | 27 | /**
|
---|
| 28 | * <p>
|
---|
| 29 | * TODO comment
|
---|
| 30 | * </p>
|
---|
| 31 | *
|
---|
| 32 | * @author Alexander Deicke
|
---|
| 33 | */
|
---|
[1290] | 34 | public class TaskModelFilter implements ITaskModelFilter {
|
---|
[1040] | 35 |
|
---|
[1290] | 36 | private BFSTaskModelIterator taskModelIterator;
|
---|
[1040] | 37 |
|
---|
[1290] | 38 | private FilterResult filterStatistic;
|
---|
[1030] | 39 |
|
---|
[1290] | 40 | @SuppressWarnings("unchecked")
|
---|
| 41 | @Override
|
---|
| 42 | public FilterResult filter(ITaskModel taskModel,
|
---|
| 43 | EventTargetFilter eventTarget) {
|
---|
| 44 | Predicate<IEventTarget> filterPredicate = eventTarget.filterPredicate();
|
---|
| 45 | return setup(taskModel, filterPredicate);
|
---|
| 46 | }
|
---|
[1040] | 47 |
|
---|
[1290] | 48 | @SuppressWarnings("unchecked")
|
---|
| 49 | @Override
|
---|
| 50 | public FilterResult filter(ITaskModel taskModel, EventTypeFilter eventType) {
|
---|
| 51 | Predicate<IEventType> filterPredicate = eventType.filterPredicate();
|
---|
| 52 | return setup(taskModel, filterPredicate);
|
---|
| 53 | }
|
---|
[1040] | 54 |
|
---|
[1290] | 55 | @SuppressWarnings("unchecked")
|
---|
| 56 | @Override
|
---|
| 57 | public FilterResult filter(ITaskModel taskModel, TaskTypeFilter nodeType) {
|
---|
| 58 | Predicate<ITask> filterPredicate = nodeType.filterPredicate();
|
---|
| 59 | return setup(taskModel, filterPredicate);
|
---|
| 60 | }
|
---|
[1030] | 61 |
|
---|
[1290] | 62 | private FilterResult setup(ITaskModel taskModel,
|
---|
| 63 | Predicate<?> filterPredicate) {
|
---|
| 64 | this.filterStatistic = new FilterResult(filterPredicate);
|
---|
| 65 | this.taskModelIterator = BFSTaskModelIterator.iterator(taskModel);
|
---|
| 66 | traverse(taskModel);
|
---|
| 67 | return this.filterStatistic;
|
---|
| 68 | }
|
---|
[1030] | 69 |
|
---|
[1290] | 70 | private void traverse(ITaskModel taskModel) {
|
---|
| 71 | while (this.taskModelIterator.hasNext()) {
|
---|
| 72 | ITask task = this.taskModelIterator.next();
|
---|
| 73 | this.filterStatistic.addTask(task);
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
[1030] | 76 | }
|
---|