source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskSymbolIdentityMap.java @ 1285

Last change on this file since 1285 was 1285, checked in by pharms, 11 years ago
  • improved performance of task instance trie generation by using different symbol management strategies while creating the trie. This performance improvement is significant and allows to detect tasks now in a much faster manner.
File size: 5.1 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 * TODO comment
28 * </p>
29 *
30 * @author Patrick Harms
31 */
32public class TaskSymbolIdentityMap<V> implements SymbolMap<ITaskInstance, V> {
33
34    /**  */
35    private static final long serialVersionUID = 1L;
36
37    /**
38     *
39     */
40    private Map<ITask, V> delegate;
41
42    /**
43     *
44     */
45    private Map<ITask, ITaskInstance> symbols;
46
47    /**
48     * <p>
49     * TODO: comment
50     * </p>
51     *
52     * @param other
53     */
54    public TaskSymbolIdentityMap() {
55        delegate = new HashMap<ITask, V>();
56        symbols = new HashMap<ITask, ITaskInstance>();
57    }
58
59    /**
60     * <p>
61     * TODO: comment
62     * </p>
63     *
64     * @param other
65     */
66    public TaskSymbolIdentityMap(SymbolMap<ITaskInstance, V> other) {
67        if (other == null) {
68            throw new IllegalArgumentException("other map must not be null");
69        }
70       
71        delegate = new HashMap<ITask, V>();
72        symbols = new HashMap<ITask, ITaskInstance>();
73       
74        for (ITaskInstance symbol : other.getSymbols()) {
75            delegate.put(symbol.getTask(), other.getValue(symbol));
76            symbols.put(symbol.getTask(), symbol);
77        }
78    }
79
80    /* (non-Javadoc)
81     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#size()
82     */
83    @Override
84    public int size() {
85        return delegate.size();
86    }
87
88    /* (non-Javadoc)
89     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#isEmpty()
90     */
91    @Override
92    public boolean isEmpty() {
93        return delegate.isEmpty();
94    }
95
96    /* (non-Javadoc)
97     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#containsSymbol(java.lang.Object)
98     */
99    @Override
100    public boolean containsSymbol(ITaskInstance symbol) {
101        if (symbol == null) {
102            throw new IllegalArgumentException("symbol must not be null");
103        }
104       
105        return delegate.containsKey(symbol.getTask());
106    }
107
108    /* (non-Javadoc)
109     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#getValue(java.lang.Object)
110     */
111    @Override
112    public V getValue(ITaskInstance symbol) {
113        if (symbol == null) {
114            throw new IllegalArgumentException("symbol must not be null");
115        }
116       
117        return delegate.get(symbol.getTask());
118    }
119
120    /* (non-Javadoc)
121     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#addSymbol(java.lang.Object, java.lang.Object)
122     */
123    @Override
124    public void addSymbol(ITaskInstance symbol, V value) {
125        if (symbol == null) {
126            throw new IllegalArgumentException("symbol must not be null");
127        }
128       
129        delegate.put(symbol.getTask(), value);
130        symbols.put(symbol.getTask(), symbol);
131    }
132
133    /* (non-Javadoc)
134     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#removeSymbol(java.lang.Object)
135     */
136    @Override
137    public V removeSymbol(ITaskInstance symbol) {
138        if (symbol == null) {
139            throw new IllegalArgumentException("symbol must not be null");
140        }
141       
142        symbols.remove(symbol.getTask());
143        return delegate.remove(symbol.getTask());
144    }
145
146    /* (non-Javadoc)
147     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#getSymbols()
148     */
149    @Override
150    public Collection<ITaskInstance> getSymbols() {
151        return symbols.values();
152    }
153
154    /* (non-Javadoc)
155     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#getValues()
156     */
157    @Override
158    public Collection<V> getValues() {
159        return delegate.values();
160    }
161
162    /* (non-Javadoc)
163     * @see de.ugoe.cs.autoquest.usageprofiles.SymbolMap#clear()
164     */
165    @Override
166    public void clear() {
167        delegate.clear();
168    }
169
170    /* (non-Javadoc)
171     * @see java.lang.Object#hashCode()
172     */
173    @Override
174    public int hashCode() {
175        return delegate.hashCode();
176    }
177       
178    /* (non-Javadoc)
179     * @see java.lang.Object#equals(java.lang.Object)
180     */
181    @SuppressWarnings("unchecked")
182    @Override
183    public boolean equals(Object obj) {
184        if (this == obj) {
185            return true;
186        }
187        else if (this.getClass().isInstance(obj)) {
188            return delegate.equals(((TaskSymbolIdentityMap<V>) obj).delegate);
189        }
190        else {
191            return false;
192        }
193    }
194
195}
Note: See TracBrowser for help on using the repository browser.