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

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