source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskModel.java @ 1287

Last change on this file since 1287 was 1287, checked in by pharms, 11 years ago
  • added counting of task occurrences
  • Property svn:executable set to *
File size: 4.6 KB
RevLine 
[1113]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
[922]15package de.ugoe.cs.autoquest.tasktrees.treeimpl;
[439]16
[1146]17import java.util.Collection;
18import java.util.Collections;
[439]19import java.util.HashMap;
[1146]20import java.util.List;
[439]21import java.util.Map;
22
[1146]23import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
[1287]25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList;
[1146]26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
[439]29
30/**
[1216]31 * <p>
32 * this is the default implementation of the interface {@link ITaskModel}. It
33 * does not do anything fancy except implementing the interface.
34 * </p>
[439]35 *
[1216]36 * @author Patrick Harms
[439]37 */
[1146]38class TaskModel implements ITaskModel {
[557]39   
[1216]40    /**
41     * <p>
42     * default serial version UID
43     * </p>
44     */
[1146]45    private static final long serialVersionUID = 1L;
[439]46
[1216]47    /**
48     * <p>
49     * the user sessions belonging to the model
50     * </p>
51     */
[1146]52    private List<IUserSession> userSessions;
[439]53
[1216]54    /**
55     * <p>
56     * the tasks contained in the user session belonging to the model as well as statistical infos
57     * about them
58     * </p>
59     */
[1146]60    private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>();
61
[557]62    /**
[1216]63     * <p>
64     * initializes the task model with the user sessions out of which the tasks are extracted
65     * </p>
66     *
67     * @param userSessions as described
[557]68     */
[1146]69    TaskModel(List<IUserSession> userSessions) {
70        if ((userSessions == null) || (userSessions.size() == 0)) {
71            throw new IllegalArgumentException("user sessions must not be null");
72        }
73       
74        this.userSessions = userSessions;
75       
76        for (IUserSession session : this.userSessions) {
77            for (ITaskInstance taskInstance : session) {
[1287]78                addTasksToMap(taskInstance);
[1146]79            }
80        }
[439]81    }
82
[1287]83   
[1146]84    /* (non-Javadoc)
85     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions()
[557]86     */
87    @Override
[1146]88    public List<IUserSession> getUserSessions() {
89        return Collections.unmodifiableList(userSessions);
[439]90    }
[557]91
[1146]92
93    /* (non-Javadoc)
94     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks()
[557]95     */
96    @Override
[1146]97    public Collection<ITask> getTasks() {
98        return Collections.unmodifiableCollection(taskMap.keySet());
[439]99    }
[557]100
[1146]101
102    /* (non-Javadoc)
[1216]103     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask)
[1146]104     */
105    @Override
106    public ITaskInfo getTaskInfo(ITask task) {
107        return taskMap.get(task);
108    }
109
[1216]110    /* (non-Javadoc)
111     * @see java.lang.Object#clone()
112     */
113    @Override
114    public TaskModel clone() {
115        return new TaskModel(userSessions);
116    }
117
[1287]118
[557]119    /**
[1216]120     * <p>
[1287]121     * internal convenience method to recursively add the tasks of a task instance and its
122     * children to the task model
123     * </p>
124     *
125     * @param taskInstance the task instance of which the tasks shall be added
126     */
127    private void addTasksToMap(ITaskInstance taskInstance) {
128        addTaskToMap(taskInstance.getTask());
129       
130        if (taskInstance instanceof ITaskInstanceList) {
131            for (ITaskInstance child : (ITaskInstanceList) taskInstance) {
132                addTasksToMap(child);
133            }
134        }
135    }
136
137   
138    /**
139     * <p>
[1216]140     * internal convenience method to build the task model during initialization
141     * </p>
[557]142     */
[1146]143    private void addTaskToMap(ITask task) {
144        TaskInfo taskInfo = taskMap.get(task);
[557]145
[1146]146        if (taskInfo == null) {
147            taskInfo = new TaskInfo(task);
148            taskMap.put(task, taskInfo);
[557]149        }
150
[1287]151        taskInfo.increaseCount();
152
153        /*if (task instanceof IStructuringTemporalRelationship) {
[1146]154            for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) {
155                addTaskToMap(child);
156            }
[557]157        }
[1146]158        else if (task instanceof IMarkingTemporalRelationship) {
159            addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask());
[1287]160        }*/
[439]161    }
162
163}
Note: See TracBrowser for help on using the repository browser.