source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/UserSession.java

Last change on this file was 1734, checked in by rkrimmel, 10 years ago

Added automatically created javadoc, still needs to be commented properly though

File size: 4.3 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.treeimpl;
16
17import java.util.ArrayList;
18import java.util.Collections;
19import java.util.Iterator;
20import java.util.LinkedList;
21import java.util.List;
22
23import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
25
26// TODO: Auto-generated Javadoc
27/**
28 * <p>
29 * this is the default implementation of the interface {@link IUserSession}. It
30 * does not do anything fancy except implementing the interface.
31 * </p>
32 *
33 * @author Patrick Harms
34 */
35class UserSession implements IUserSession {
36
37        /** <p> default serial version UID </p>. */
38        private static final long serialVersionUID = 1L;
39
40        /** <p> the task instances belonging to the user session </p>. */
41        private List<ITaskInstance> executedTasks = new ArrayList<ITaskInstance>();
42
43        /**
44         * <p>
45         * used internally to add a task instance to the user session at a specific
46         * position
47         * </p>.
48         *
49         * @param index            the index the task instance shall be added to
50         * @param taskInstance            the task instance to be added
51         */
52        void addExecutedTask(int index, ITaskInstance taskInstance) {
53                executedTasks.add(index, taskInstance);
54        }
55
56        /**
57         * <p>
58         * used internally to add a task instance to the user session
59         * </p>.
60         *
61         * @param taskInstance            the task instance to be added
62         */
63        void addExecutedTask(ITaskInstance taskInstance) {
64                executedTasks.add(taskInstance);
65        }
66
67        /*
68         * (non-Javadoc)
69         *
70         * @see java.lang.Object#clone()
71         */
72        @Override
73        public synchronized IUserSession clone() {
74                UserSession clone = null;
75                try {
76                        clone = (UserSession) super.clone();
77
78                        clone.executedTasks = new LinkedList<ITaskInstance>();
79
80                        for (final ITaskInstance child : executedTasks) {
81                                clone.executedTasks.add(child.clone());
82                        }
83
84                } catch (final CloneNotSupportedException e) {
85                        // this should never happen. Therefore simply dump the exception
86                        e.printStackTrace();
87                }
88
89                return clone;
90        }
91
92        /*
93         * (non-Javadoc)
94         *
95         * @see
96         * de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#equals(IUserSession)
97         */
98        @Override
99        public boolean equals(IUserSession userSession) {
100                // task instances are only equal if they are identical or if they have
101                // the same id
102                // (may happen, if they are cloned)
103                return (this == userSession)
104                                || (this.hashCode() == userSession.hashCode());
105        }
106
107        /*
108         * (non-Javadoc)
109         *
110         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int)
111         */
112        @Override
113        public ITaskInstance get(int index) {
114                return executedTasks.get(index);
115        }
116
117        /*
118         * (non-Javadoc)
119         *
120         * @see
121         * de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#getExecutedTasks()
122         */
123        @Override
124        public List<ITaskInstance> getExecutedTasks() {
125                return Collections.unmodifiableList(executedTasks);
126        }
127
128        /*
129         * (non-Javadoc)
130         *
131         * @see java.lang.Object#hashCode()
132         */
133        @Override
134        public synchronized int hashCode() {
135                return super.hashCode();
136        }
137
138        /*
139         * (non-Javadoc)
140         *
141         * @see java.lang.Iterable#iterator()
142         */
143        @Override
144        public Iterator<ITaskInstance> iterator() {
145                return executedTasks.iterator();
146        }
147
148        /**
149         * <p>
150         * used internally to remove a task instance from the user session
151         * </p>.
152         *
153         * @param index            the index of the task instance to be removed
154         */
155        void removeExecutedTask(int index) {
156                executedTasks.remove(index);
157        }
158
159        /*
160         * (non-Javadoc)
161         *
162         * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size()
163         */
164        @Override
165        public int size() {
166                return executedTasks.size();
167        }
168
169        /*
170         * (non-Javadoc)
171         *
172         * @see java.lang.Object#toString()
173         */
174        @Override
175        public synchronized String toString() {
176                return "session (" + executedTasks.size() + " task instances)";
177        }
178
179}
Note: See TracBrowser for help on using the repository browser.