source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolIdentityMap.java @ 1733

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

Used Eclipse code cleanup

File size: 4.9 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.temporalrelation;
16
17import java.util.Collection;
18import java.util.HashMap;
19import java.util.Map;
20
21import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
23import de.ugoe.cs.autoquest.usageprofiles.SymbolMap;
24
25/**
26 * <p>
27 * symbol map implementation for task instances considering two task instances
28 * as equal if their tasks are identical
29 * </p>
30 *
31 * @author Patrick Harms
32 */
33public class TaskSymbolIdentityMap<V> implements SymbolMap<ITaskInstance, V> {
34
35        /**  */
36        private static final long serialVersionUID = 1L;
37
38        /**
39         * <p>
40         * internally used map for implementing the symbol map interface
41         * </p>
42         */
43        private final Map<ITask, V> delegate;
44
45        /**
46         * <p>
47         * mapping between the tasks and the real symbols stored in the map, i.e.
48         * the task instances
49         * </p>
50         */
51        private final Map<ITask, ITaskInstance> symbols;
52
53        /**
54         * <p>
55         * initializes this map
56         * </p>
57         */
58        public TaskSymbolIdentityMap() {
59                delegate = new HashMap<ITask, V>();
60                symbols = new HashMap<ITask, ITaskInstance>();
61        }
62
63        /**
64         * <p>
65         * copy constructor
66         * </p>
67         *
68         * @param other
69         *            the map to be copied
70         */
71        public TaskSymbolIdentityMap(SymbolMap<ITaskInstance, V> other) {
72                if (other == null) {
73                        throw new IllegalArgumentException("other map must not be null");
74                }
75
76                delegate = new HashMap<ITask, V>();
77                symbols = new HashMap<ITask, ITaskInstance>();
78
79                for (final ITaskInstance symbol : other.getSymbols()) {
80                        delegate.put(symbol.getTask(), other.getValue(symbol));
81                        symbols.put(symbol.getTask(), symbol);
82                }
83        }
84
85        /*
86         * (non-Javadoc)
87         *
88         * @see
89         * de.ugoe.cs.autoquest.usageprofiles.SymbolMap#addSymbol(java.lang.Object,
90         * java.lang.Object)
91         */
92        @Override
93        public void addSymbol(ITaskInstance symbol, V value) {
94                if (symbol == null) {
95                        throw new IllegalArgumentException("symbol must not be null");
96                }
97
98                delegate.put(symbol.getTask(), value);
99                symbols.put(symbol.getTask(), symbol);
100        }
101
102        /*
103         * (non-Javadoc)
104         *
105         * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#clear()
106         */
107        @Override
108        public void clear() {
109                delegate.clear();
110        }
111
112        /*
113         * (non-Javadoc)
114         *
115         * @see
116         * de.ugoe.cs.autoquest.usageprofiles.SymbolMap#containsSymbol(java.lang
117         * .Object)
118         */
119        @Override
120        public boolean containsSymbol(ITaskInstance symbol) {
121                if (symbol == null) {
122                        throw new IllegalArgumentException("symbol must not be null");
123                }
124
125                return delegate.containsKey(symbol.getTask());
126        }
127
128        /*
129         * (non-Javadoc)
130         *
131         * @see java.lang.Object#equals(java.lang.Object)
132         */
133        @SuppressWarnings("unchecked")
134        @Override
135        public boolean equals(Object obj) {
136                if (this == obj) {
137                        return true;
138                } else if (this.getClass().isInstance(obj)) {
139                        return delegate.equals(((TaskSymbolIdentityMap<V>) obj).delegate);
140                } else {
141                        return false;
142                }
143        }
144
145        /*
146         * (non-Javadoc)
147         *
148         * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#getSymbols()
149         */
150        @Override
151        public Collection<ITaskInstance> getSymbols() {
152                return symbols.values();
153        }
154
155        /*
156         * (non-Javadoc)
157         *
158         * @see
159         * de.ugoe.cs.autoquest.usageprofiles.SymbolMap#getValue(java.lang.Object)
160         */
161        @Override
162        public V getValue(ITaskInstance symbol) {
163                if (symbol == null) {
164                        throw new IllegalArgumentException("symbol must not be null");
165                }
166
167                return delegate.get(symbol.getTask());
168        }
169
170        /*
171         * (non-Javadoc)
172         *
173         * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#getValues()
174         */
175        @Override
176        public Collection<V> getValues() {
177                return delegate.values();
178        }
179
180        /*
181         * (non-Javadoc)
182         *
183         * @see java.lang.Object#hashCode()
184         */
185        @Override
186        public int hashCode() {
187                return delegate.hashCode();
188        }
189
190        /*
191         * (non-Javadoc)
192         *
193         * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#isEmpty()
194         */
195        @Override
196        public boolean isEmpty() {
197                return delegate.isEmpty();
198        }
199
200        /*
201         * (non-Javadoc)
202         *
203         * @see
204         * de.ugoe.cs.autoquest.usageprofiles.SymbolMap#removeSymbol(java.lang.Object
205         * )
206         */
207        @Override
208        public V removeSymbol(ITaskInstance symbol) {
209                if (symbol == null) {
210                        throw new IllegalArgumentException("symbol must not be null");
211                }
212
213                symbols.remove(symbol.getTask());
214                return delegate.remove(symbol.getTask());
215        }
216
217        /*
218         * (non-Javadoc)
219         *
220         * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#size()
221         */
222        @Override
223        public int size() {
224                return delegate.size();
225        }
226
227}
Note: See TracBrowser for help on using the repository browser.