[1251] | 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 | |
---|
| 15 | package de.ugoe.cs.autoquest.usageprofiles; |
---|
| 16 | |
---|
| 17 | import java.io.Serializable; |
---|
| 18 | import java.util.Collection; |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * <p> |
---|
[1282] | 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. |
---|
[1251] | 24 | * </p> |
---|
| 25 | * <p> |
---|
[1282] | 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. |
---|
[1251] | 31 | * </p> |
---|
[1282] | 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> |
---|
[1251] | 36 | * |
---|
[1282] | 37 | * @author Patrick Harms |
---|
[1251] | 38 | * |
---|
[2218] | 39 | * @param <K> |
---|
[1282] | 40 | * Type of the symbols that are stored |
---|
| 41 | * @param <V> |
---|
| 42 | * Type of the values associated with the symbols |
---|
| 43 | * |
---|
| 44 | * @see SymbolStrategy |
---|
[1251] | 45 | */ |
---|
[1282] | 46 | public interface SymbolMap<K, V> extends Serializable { |
---|
[1251] | 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 | */ |
---|
[1282] | 55 | public int size(); |
---|
[1251] | 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 | */ |
---|
[1282] | 64 | public boolean isEmpty(); |
---|
[1251] | 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 | */ |
---|
[1282] | 77 | public boolean containsSymbol(K symbol); |
---|
[1251] | 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 | */ |
---|
[1282] | 92 | public V getValue(K symbol); |
---|
[1251] | 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 |
---|
[1282] | 98 | * same symbol twice may produce two entries. This is contradictory to typical map |
---|
[1251] | 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 | * @throws IllegalArgumentException if the provided symbol is null |
---|
| 107 | */ |
---|
[1282] | 108 | public void addSymbol(K symbol, V value); |
---|
[1251] | 109 | |
---|
| 110 | /** |
---|
| 111 | * <p> |
---|
| 112 | * Removes a symbol and its associated value from the map. If the symbol is stored several |
---|
| 113 | * times, the first of its occurrences is removed. |
---|
| 114 | * </p> |
---|
| 115 | * |
---|
| 116 | * @param symbol the symbol to be removed from the map |
---|
| 117 | * |
---|
| 118 | * @return as described |
---|
| 119 | * |
---|
| 120 | * @throws IllegalArgumentException if the provided symbol is null |
---|
| 121 | */ |
---|
[1282] | 122 | public V removeSymbol(K symbol); |
---|
[1251] | 123 | |
---|
| 124 | /** |
---|
| 125 | * <p> |
---|
| 126 | * Returns a collection of all symbols in this map. |
---|
| 127 | * </p> |
---|
| 128 | * |
---|
| 129 | * @return as described |
---|
| 130 | */ |
---|
[1282] | 131 | public Collection<K> getSymbols(); |
---|
[1251] | 132 | |
---|
| 133 | /** |
---|
| 134 | * <p> |
---|
| 135 | * Returns a collection of all values associated to symbols in this map. May contain null |
---|
| 136 | * values, if some of the symbols are mapped to null. The length of the returned collection |
---|
| 137 | * is in any case the same as the size of the map. |
---|
| 138 | * </p> |
---|
| 139 | * |
---|
| 140 | * @return as described |
---|
| 141 | */ |
---|
[1282] | 142 | public Collection<V> getValues(); |
---|
[1251] | 143 | |
---|
| 144 | /** |
---|
| 145 | * <p> |
---|
| 146 | * Removes all symbols and associated values from the map. |
---|
| 147 | * </p> |
---|
| 148 | */ |
---|
[1282] | 149 | public void clear(); |
---|
[1251] | 150 | |
---|
| 151 | /* (non-Javadoc) |
---|
| 152 | * @see java.lang.Object#hashCode() |
---|
| 153 | */ |
---|
| 154 | @Override |
---|
[1282] | 155 | public int hashCode(); |
---|
[1251] | 156 | |
---|
| 157 | /* (non-Javadoc) |
---|
| 158 | * @see java.lang.Object#equals(java.lang.Object) |
---|
| 159 | */ |
---|
| 160 | @Override |
---|
[1282] | 161 | public boolean equals(Object obj); |
---|
[1251] | 162 | |
---|
| 163 | } |
---|