[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] | 15 | package de.ugoe.cs.autoquest.tasktrees.treeimpl; |
---|
[439] | 16 | |
---|
[1146] | 17 | import java.util.Collection; |
---|
| 18 | import java.util.Collections; |
---|
[439] | 19 | import java.util.HashMap; |
---|
[1146] | 20 | import java.util.List; |
---|
[439] | 21 | import java.util.Map; |
---|
| 22 | |
---|
[1146] | 23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; |
---|
| 24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
| 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
| 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo; |
---|
| 29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
[439] | 30 | |
---|
| 31 | /** |
---|
| 32 | * TODO comment |
---|
| 33 | * |
---|
| 34 | * @version $Revision: $ $Date: 21.02.2012$ |
---|
| 35 | * @author 2012, last modified by $Author: patrick$ |
---|
| 36 | */ |
---|
[1146] | 37 | class TaskModel implements ITaskModel { |
---|
[557] | 38 | |
---|
[1146] | 39 | /** */ |
---|
| 40 | private static final long serialVersionUID = 1L; |
---|
[439] | 41 | |
---|
[1146] | 42 | /** the map of tasks */ |
---|
| 43 | private List<IUserSession> userSessions; |
---|
[439] | 44 | |
---|
[1146] | 45 | /** the map of tasks */ |
---|
| 46 | private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); |
---|
| 47 | |
---|
[557] | 48 | /** |
---|
[1146] | 49 | * |
---|
[557] | 50 | */ |
---|
[1146] | 51 | TaskModel(List<IUserSession> userSessions) { |
---|
| 52 | if ((userSessions == null) || (userSessions.size() == 0)) { |
---|
| 53 | throw new IllegalArgumentException("user sessions must not be null"); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | this.userSessions = userSessions; |
---|
| 57 | |
---|
| 58 | for (IUserSession session : this.userSessions) { |
---|
| 59 | for (ITaskInstance taskInstance : session) { |
---|
| 60 | addTaskToMap(taskInstance.getTask()); |
---|
| 61 | } |
---|
| 62 | } |
---|
[439] | 63 | } |
---|
| 64 | |
---|
[1146] | 65 | |
---|
| 66 | /* (non-Javadoc) |
---|
| 67 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() |
---|
[557] | 68 | */ |
---|
| 69 | @Override |
---|
[1146] | 70 | public List<IUserSession> getUserSessions() { |
---|
| 71 | return Collections.unmodifiableList(userSessions); |
---|
[439] | 72 | } |
---|
[557] | 73 | |
---|
[1146] | 74 | |
---|
| 75 | /* (non-Javadoc) |
---|
| 76 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() |
---|
[557] | 77 | */ |
---|
| 78 | @Override |
---|
[1146] | 79 | public Collection<ITask> getTasks() { |
---|
| 80 | return Collections.unmodifiableCollection(taskMap.keySet()); |
---|
[439] | 81 | } |
---|
[557] | 82 | |
---|
[1146] | 83 | |
---|
| 84 | /* (non-Javadoc) |
---|
| 85 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) |
---|
| 86 | */ |
---|
| 87 | @Override |
---|
| 88 | public ITaskInfo getTaskInfo(ITask task) { |
---|
| 89 | return taskMap.get(task); |
---|
| 90 | } |
---|
| 91 | |
---|
[557] | 92 | /** |
---|
[1146] | 93 | * |
---|
[557] | 94 | */ |
---|
[1146] | 95 | private void addTaskToMap(ITask task) { |
---|
| 96 | TaskInfo taskInfo = taskMap.get(task); |
---|
[557] | 97 | |
---|
[1146] | 98 | if (taskInfo == null) { |
---|
| 99 | taskInfo = new TaskInfo(task); |
---|
| 100 | taskMap.put(task, taskInfo); |
---|
[557] | 101 | } |
---|
| 102 | |
---|
[1146] | 103 | if (task instanceof IStructuringTemporalRelationship) { |
---|
| 104 | for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
| 105 | addTaskToMap(child); |
---|
| 106 | } |
---|
[557] | 107 | } |
---|
[1146] | 108 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
| 109 | addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask()); |
---|
[557] | 110 | } |
---|
[439] | 111 | } |
---|
| 112 | |
---|
[557] | 113 | /* |
---|
| 114 | * (non-Javadoc) |
---|
| 115 | * |
---|
| 116 | * @see java.lang.Object#clone() |
---|
| 117 | */ |
---|
| 118 | @Override |
---|
[1146] | 119 | public TaskModel clone() { |
---|
| 120 | return new TaskModel(userSessions); |
---|
[467] | 121 | } |
---|
| 122 | |
---|
[439] | 123 | } |
---|