source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/UserSession.java @ 1155

Last change on this file since 1155 was 1146, checked in by pharms, 11 years ago
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
File size: 3.8 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.Collections;
18import java.util.Iterator;
19import java.util.LinkedList;
20import java.util.List;
21
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
23import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
24
25/**
26 * <p>
27 * TODO comment
28 * </p>
29 *
30 * @author Patrick Harms
31 */
32class UserSession implements IUserSession {
33   
34    /**  */
35    private static final long serialVersionUID = 1L;
36    /**
37     *
38     */
39    private List<ITaskInstance> executedTasks = new LinkedList<ITaskInstance>();
40
41    /* (non-Javadoc)
42     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#get(int)
43     */
44    @Override
45    public ITaskInstance get(int index) {
46        return executedTasks.get(index);
47    }
48
49    /* (non-Javadoc)
50     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList#size()
51     */
52    @Override
53    public int size() {
54        return executedTasks.size();
55    }
56
57    /* (non-Javadoc)
58     * @see java.lang.Iterable#iterator()
59     */
60    @Override
61    public Iterator<ITaskInstance> iterator() {
62        return executedTasks.iterator();
63    }
64
65    /* (non-Javadoc)
66     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession#getExecutedTasks()
67     */
68    @Override
69    public List<ITaskInstance> getExecutedTasks() {
70        return Collections.unmodifiableList(executedTasks);
71    }
72
73    /*
74     * (non-Javadoc)
75     *
76     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeNode#equals(TaskTreeNode)
77     */
78    @Override
79    public boolean equals(IUserSession userSession) {
80        // task instances are only equal if they are identical or if they have the same id
81        // (may happen, if they are cloned)
82        return (this == userSession) || (this.hashCode() == userSession.hashCode());
83    }
84
85    /*
86     * (non-Javadoc)
87     *
88     * @see java.lang.Object#hashCode()
89     */
90    @Override
91    public synchronized int hashCode() {
92        return super.hashCode();
93    }
94
95    /*
96     * (non-Javadoc)
97     *
98     * @see java.lang.Object#toString()
99     */
100    @Override
101    public synchronized String toString() {
102        return "session (" + executedTasks.size() + " task instances)";
103    }
104
105    /*
106     * (non-Javadoc)
107     *
108     * @see java.lang.Object#clone()
109     */
110    @Override
111    public synchronized IUserSession clone() {
112        UserSession clone = null;
113        try {
114            clone = (UserSession) super.clone();
115
116            clone.executedTasks = new LinkedList<ITaskInstance>();
117           
118            for (ITaskInstance child : executedTasks) {
119                clone.executedTasks.add(child.clone());
120            }
121
122        }
123        catch (CloneNotSupportedException e) {
124            // this should never happen. Therefore simply dump the exception
125            e.printStackTrace();
126        }
127
128        return clone;
129    }
130
131    /**
132     *
133     */
134    void addExecutedTask(ITaskInstance taskInstance) {
135        executedTasks.add(taskInstance);
136    }
137
138    /**
139     *
140     */
141    void addExecutedTask(int index, ITaskInstance taskInstance) {
142        executedTasks.add(index, taskInstance);
143    }
144
145    /**
146     *
147     */
148    void removeExecutedTask(int index) {
149        executedTasks.remove(index);
150    }
151
152}
Note: See TracBrowser for help on using the repository browser.