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 | |
---|
15 | package de.ugoe.cs.autoquest.tasktrees.treeimpl; |
---|
16 | |
---|
17 | import java.util.Collection; |
---|
18 | import java.util.Collections; |
---|
19 | import java.util.HashMap; |
---|
20 | import java.util.List; |
---|
21 | import java.util.Map; |
---|
22 | |
---|
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; |
---|
30 | |
---|
31 | /** |
---|
32 | * TODO comment |
---|
33 | * |
---|
34 | * @version $Revision: $ $Date: 21.02.2012$ |
---|
35 | * @author 2012, last modified by $Author: patrick$ |
---|
36 | */ |
---|
37 | class TaskModel implements ITaskModel { |
---|
38 | |
---|
39 | /** */ |
---|
40 | private static final long serialVersionUID = 1L; |
---|
41 | |
---|
42 | /** the map of tasks */ |
---|
43 | private List<IUserSession> userSessions; |
---|
44 | |
---|
45 | /** the map of tasks */ |
---|
46 | private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); |
---|
47 | |
---|
48 | /** |
---|
49 | * |
---|
50 | */ |
---|
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 | } |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | /* (non-Javadoc) |
---|
67 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() |
---|
68 | */ |
---|
69 | @Override |
---|
70 | public List<IUserSession> getUserSessions() { |
---|
71 | return Collections.unmodifiableList(userSessions); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | /* (non-Javadoc) |
---|
76 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() |
---|
77 | */ |
---|
78 | @Override |
---|
79 | public Collection<ITask> getTasks() { |
---|
80 | return Collections.unmodifiableCollection(taskMap.keySet()); |
---|
81 | } |
---|
82 | |
---|
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 | |
---|
92 | /** |
---|
93 | * |
---|
94 | */ |
---|
95 | private void addTaskToMap(ITask task) { |
---|
96 | TaskInfo taskInfo = taskMap.get(task); |
---|
97 | |
---|
98 | if (taskInfo == null) { |
---|
99 | taskInfo = new TaskInfo(task); |
---|
100 | taskMap.put(task, taskInfo); |
---|
101 | } |
---|
102 | |
---|
103 | if (task instanceof IStructuringTemporalRelationship) { |
---|
104 | for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
105 | addTaskToMap(child); |
---|
106 | } |
---|
107 | } |
---|
108 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
109 | addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask()); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | /* |
---|
114 | * (non-Javadoc) |
---|
115 | * |
---|
116 | * @see java.lang.Object#clone() |
---|
117 | */ |
---|
118 | @Override |
---|
119 | public TaskModel clone() { |
---|
120 | return new TaskModel(userSessions); |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|