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.ITask; |
---|
24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
29 | |
---|
30 | /** |
---|
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> |
---|
35 | * |
---|
36 | * @author Patrick Harms |
---|
37 | */ |
---|
38 | class TaskModel implements ITaskModel { |
---|
39 | |
---|
40 | /** |
---|
41 | * <p> |
---|
42 | * default serial version UID |
---|
43 | * </p> |
---|
44 | */ |
---|
45 | private static final long serialVersionUID = 1L; |
---|
46 | |
---|
47 | /** |
---|
48 | * <p> |
---|
49 | * the user sessions belonging to the model |
---|
50 | * </p> |
---|
51 | */ |
---|
52 | private List<IUserSession> userSessions; |
---|
53 | |
---|
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 | */ |
---|
60 | private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); |
---|
61 | |
---|
62 | /** |
---|
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 |
---|
68 | */ |
---|
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) { |
---|
78 | addTasksToMap(taskInstance); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /* (non-Javadoc) |
---|
85 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() |
---|
86 | */ |
---|
87 | @Override |
---|
88 | public List<IUserSession> getUserSessions() { |
---|
89 | return Collections.unmodifiableList(userSessions); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | /* (non-Javadoc) |
---|
94 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() |
---|
95 | */ |
---|
96 | @Override |
---|
97 | public Collection<ITask> getTasks() { |
---|
98 | return Collections.unmodifiableCollection(taskMap.keySet()); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | /* (non-Javadoc) |
---|
103 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask) |
---|
104 | */ |
---|
105 | @Override |
---|
106 | public ITaskInfo getTaskInfo(ITask task) { |
---|
107 | return taskMap.get(task); |
---|
108 | } |
---|
109 | |
---|
110 | /* (non-Javadoc) |
---|
111 | * @see java.lang.Object#clone() |
---|
112 | */ |
---|
113 | @Override |
---|
114 | public TaskModel clone() { |
---|
115 | return new TaskModel(userSessions); |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | /** |
---|
120 | * <p> |
---|
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> |
---|
140 | * internal convenience method to build the task model during initialization |
---|
141 | * </p> |
---|
142 | */ |
---|
143 | private void addTaskToMap(ITask task) { |
---|
144 | TaskInfo taskInfo = taskMap.get(task); |
---|
145 | |
---|
146 | if (taskInfo == null) { |
---|
147 | taskInfo = new TaskInfo(task); |
---|
148 | taskMap.put(task, taskInfo); |
---|
149 | } |
---|
150 | |
---|
151 | taskInfo.increaseCount(); |
---|
152 | |
---|
153 | /*if (task instanceof IStructuringTemporalRelationship) { |
---|
154 | for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
155 | addTaskToMap(child); |
---|
156 | } |
---|
157 | } |
---|
158 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
159 | addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask()); |
---|
160 | }*/ |
---|
161 | } |
---|
162 | |
---|
163 | } |
---|