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 | * <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> |
---|
36 | * |
---|
37 | * @author Patrick Harms |
---|
38 | */ |
---|
39 | class TaskModel implements ITaskModel { |
---|
40 | |
---|
41 | /** |
---|
42 | * <p> |
---|
43 | * default serial version UID |
---|
44 | * </p> |
---|
45 | */ |
---|
46 | private static final long serialVersionUID = 1L; |
---|
47 | |
---|
48 | /** |
---|
49 | * <p> |
---|
50 | * the user sessions belonging to the model |
---|
51 | * </p> |
---|
52 | */ |
---|
53 | private List<IUserSession> userSessions; |
---|
54 | |
---|
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 | */ |
---|
61 | private Map<ITask, TaskInfo> taskMap = new HashMap<ITask, TaskInfo>(); |
---|
62 | |
---|
63 | /** |
---|
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 |
---|
69 | */ |
---|
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 | } |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /* (non-Javadoc) |
---|
86 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getUserSessions() |
---|
87 | */ |
---|
88 | @Override |
---|
89 | public List<IUserSession> getUserSessions() { |
---|
90 | return Collections.unmodifiableList(userSessions); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /* (non-Javadoc) |
---|
95 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTasks() |
---|
96 | */ |
---|
97 | @Override |
---|
98 | public Collection<ITask> getTasks() { |
---|
99 | return Collections.unmodifiableCollection(taskMap.keySet()); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | /* (non-Javadoc) |
---|
104 | * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel#getTaskInfo(ITask) |
---|
105 | */ |
---|
106 | @Override |
---|
107 | public ITaskInfo getTaskInfo(ITask task) { |
---|
108 | return taskMap.get(task); |
---|
109 | } |
---|
110 | |
---|
111 | /* (non-Javadoc) |
---|
112 | * @see java.lang.Object#clone() |
---|
113 | */ |
---|
114 | @Override |
---|
115 | public TaskModel clone() { |
---|
116 | return new TaskModel(userSessions); |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * <p> |
---|
121 | * internal convenience method to build the task model during initialization |
---|
122 | * </p> |
---|
123 | */ |
---|
124 | private void addTaskToMap(ITask task) { |
---|
125 | TaskInfo taskInfo = taskMap.get(task); |
---|
126 | |
---|
127 | if (taskInfo == null) { |
---|
128 | taskInfo = new TaskInfo(task); |
---|
129 | taskMap.put(task, taskInfo); |
---|
130 | } |
---|
131 | |
---|
132 | if (task instanceof IStructuringTemporalRelationship) { |
---|
133 | for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
134 | addTaskToMap(child); |
---|
135 | } |
---|
136 | } |
---|
137 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
138 | addTaskToMap(((IMarkingTemporalRelationship) task).getMarkedTask()); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | } |
---|