Changeset 1290


Ignore:
Timestamp:
08/10/13 10:25:24 (11 years ago)
Author:
adeicke
Message:

Refactored filter mechanism.

Location:
trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/taskmodel/filter
Files:
1 added
1 deleted
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/taskmodel/filter/ITaskModelFilter.java

    r1248 r1290  
    2727 * @author Alexander Deicke 
    2828 */ 
    29 public interface TaskModelFilterStrategy { 
     29public interface ITaskModelFilter { 
    3030 
    3131    public FilterResult filter(ITaskModel taskModel, EventTargetFilter eventTarget); 
  • trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/taskmodel/filter/TaskModelFilter.java

    r1248 r1290  
    1515package de.ugoe.cs.autoquest.usability.taskmodel.filter; 
    1616 
    17 import java.util.LinkedList; 
    18 import java.util.Queue; 
    19  
    2017import com.google.common.base.Predicate; 
    2118 
    2219import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
    2320import de.ugoe.cs.autoquest.eventcore.IEventType; 
    24 import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
    25 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 
    2621import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2722import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
     
    3732 * @author Alexander Deicke 
    3833 */ 
    39 public class IterativeDFSFilterStrategy implements TaskModelFilterStrategy { 
     34public class TaskModelFilter implements ITaskModelFilter { 
    4035 
    41     private FilterResult filterStatistic; 
     36        private BFSTaskModelIterator taskModelIterator; 
    4237 
    43     @SuppressWarnings("unchecked") 
    44     @Override 
    45     public FilterResult filter(ITaskModel taskModel, EventTargetFilter eventTarget) { 
    46         Predicate<IEventTarget> filterPredicate = eventTarget.filterPredicate(); 
    47         this.filterStatistic = new FilterResult(filterPredicate); 
    48         traverse(taskModel); 
    49         return this.filterStatistic; 
    50     } 
     38        private FilterResult filterStatistic; 
    5139 
    52     @SuppressWarnings("unchecked") 
    53     @Override 
    54     public FilterResult filter(ITaskModel taskModel, EventTypeFilter eventType) { 
    55         Predicate<IEventType> filterPredicate = eventType.filterPredicate(); 
    56         this.filterStatistic = new FilterResult(filterPredicate); 
    57         traverse(taskModel); 
    58         return this.filterStatistic; 
    59     } 
     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        } 
    6047 
    61     @SuppressWarnings("unchecked") 
    62     @Override 
    63     public FilterResult filter(ITaskModel taskModel, TaskTypeFilter nodeType) { 
    64         Predicate<ITask> filterPredicate = nodeType.filterPredicate(); 
    65         this.filterStatistic = new FilterResult(filterPredicate); 
    66         traverse(taskModel); 
    67         return this.filterStatistic; 
    68     } 
     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        } 
    6954 
    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); 
    77         } 
    78     } 
     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        } 
    7961 
    80     private boolean stillUnvisitedTasks(Queue<ITask> unvisitedTasks) { 
    81         return !unvisitedTasks.isEmpty(); 
    82     } 
     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        } 
    8369 
    84     private void processCurrentTask(ITask task) { 
    85         this.filterStatistic.addTask(task); 
    86     } 
    87  
    88     private void processChildrenOfCurrentTask(Queue<ITask> unvisitedTasks, ITask task) { 
    89         if (task instanceof IStructuringTemporalRelationship) { 
    90             for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 
    91                 unvisitedTasks.add(child); 
    92             } 
    93         } 
    94         else if (task instanceof IMarkingTemporalRelationship) { 
    95             unvisitedTasks.add(((IMarkingTemporalRelationship) task).getMarkedTask()); 
    96         } 
    97     } 
    98  
     70        private void traverse(ITaskModel taskModel) { 
     71                while (this.taskModelIterator.hasNext()) { 
     72                        ITask task = this.taskModelIterator.next(); 
     73                        this.filterStatistic.addTask(task); 
     74                } 
     75        } 
    9976} 
Note: See TracChangeset for help on using the changeset viewer.