source: trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/SymbolMap.java @ 1282

Last change on this file since 1282 was 1282, checked in by pharms, 11 years ago
  • added support for symbol management strategy in tries, especially for storing them
  • adapted comparator approach accordingly
  • provided default implementation for symbol management strategies
  • added, extended and improved java doc
File size: 5.0 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.usageprofiles;
16
17import java.io.Serializable;
18import java.util.Collection;
19
20/**
21 * <p>
22 * This interface defines a data structure for holding symbols. Its implementations can be used to
23 * improve the performance of a trie by tuning its internal symbol storage management.
24 * </p>
25 * <p>
26 * The interface is called a map, although it is not necessarily. It may contain the same element
27 * as separate keys. This is allowed for performance improvements. If it is required to really
28 * assure, that a key exists only once, then each call to the {@link #addSymbol(Object, Object)}
29 * method should be done only, if the {@link #containsSymbol(Object)} method for the same symbol
30 * returns false.
31 * </p>
32 * <p>
33 * Mapping a symbol to the value null is possible. In this case {@link #getValue(Object)} returns
34 * null for the symbol. But {@link #containsSymbol(Object)} returns true.
35 * </p>
36 *
37 * @author Patrick Harms
38 *
39 * @param <T>
40 *            Type of the symbols that are stored
41 * @param <V>
42 *            Type of the values associated with the symbols
43 *           
44 * @see SymbolStrategy
45 */
46public interface SymbolMap<K, V> extends Serializable {
47
48    /**
49     * <p>
50     * Returns the size of the map, i.e. the number of symbol entries
51     * </p>
52     *
53     * @return as described
54     */
55    public int size();
56
57    /**
58     * <p>
59     * Returns true if this map is empty, i.e. if {@link #size()} returns 0
60     * </p>
61     *
62     * @return as described
63     */
64    public boolean isEmpty();
65
66    /**
67     * <p>
68     * Returns true if the provided symbol was stored in this map.
69     * </p>
70     *
71     * @param symbol the symbol to check if it was stored in this map
72     *
73     * @return as described
74     *
75     * @throws IllegalArgumentException if the provided symbol is null
76     */
77    public boolean containsSymbol(K symbol);
78
79    /**
80     * <p>
81     * Returns the value associated to the provided symbol in this map. If there is no value
82     * associated to the given symbol or if the symbol is not stored in this map, the method
83     * returns null.
84     * </p>
85     *
86     * @param symbol the symbol to return the value for
87     *
88     * @return as described
89     *
90     * @throws IllegalArgumentException if the provided symbol is null
91     */
92    public V getValue(K symbol);
93
94    /**
95     * <p>
96     * Adds a symbol and an associated value to the map. If the value is null, the symbol is added,
97     * anyway and {@link #containsSymbol(Object)} will return true for that symbol. Adding the
98     * same symbol twice may produce two entries. This is contradictory to typical map
99     * implementations. To prevent this, the {@link #containsSymbol(Object)} and
100     * {@link #removeSymbol(Object)} methods should be used to ensure map behavior.
101     * </p>
102     *
103     * @param symbol the symbol to add to the map
104     * @param value  the value to associate to the symbol in this map
105     *
106     * @return as described
107     *
108     * @throws IllegalArgumentException if the provided symbol is null
109     */
110    public void addSymbol(K symbol, V value);
111
112    /**
113     * <p>
114     * Removes a symbol and its associated value from the map. If the symbol is stored several
115     * times, the first of its occurrences is removed.
116     * </p>
117     *
118     * @param symbol the symbol to be removed from the map
119     *
120     * @return as described
121     *
122     * @throws IllegalArgumentException if the provided symbol is null
123     */
124    public V removeSymbol(K symbol);
125
126    /**
127     * <p>
128     * Returns a collection of all symbols in this map.
129     * </p>
130     *
131     * @return as described
132     */
133    public Collection<K> getSymbols();
134   
135    /**
136     * <p>
137     * Returns a collection of all values associated to symbols in this map. May contain null
138     * values, if some of the symbols are mapped to null. The length of the returned collection
139     * is in any case the same as the size of the map.
140     * </p>
141     *
142     * @return as described
143     */
144    public Collection<V> getValues();
145   
146    /**
147     * <p>
148     * Removes all symbols and associated values from the map.
149     * </p>
150     */
151    public void clear();
152
153    /* (non-Javadoc)
154     * @see java.lang.Object#hashCode()
155     */
156    @Override
157    public int hashCode();
158
159    /* (non-Javadoc)
160     * @see java.lang.Object#equals(java.lang.Object)
161     */
162    @Override
163    public boolean equals(Object obj);
164
165}
Note: See TracBrowser for help on using the repository browser.