ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableMap.java
Revision: 1.5
Committed: Mon May 2 18:38:53 2005 UTC (19 years ago) by jsr166
Branch: MAIN
Changes since 1.4: +19 -19 lines
Log Message:
remove trailing whitespace

File Contents

# Content
1 /*
2 * Written by Doug Lea with assistance from members of JCP JSR-166
3 * Expert Group and released to the public domain, as explained at
4 * http://creativecommons.org/licenses/publicdomain
5 */
6
7 package java.util;
8
9 /**
10 * A {@link SortedMap} extended with navigation methods returning the
11 * closest matches for given search targets. Methods
12 * <tt>lowerEntry</tt>, <tt>floorEntry</tt>, <tt>ceilingEntry</tt>,
13 * and <tt>higherEntry</tt> return <tt>Map.Entry</tt> objects
14 * associated with keys respectively less than, less than or equal,
15 * greater than or equal, and greater than a given key, returning
16 * <tt>null</tt> if there is no such key. Similarly, methods
17 * <tt>lowerKey</tt>, <tt>floorKey</tt>, <tt>ceilingKey</tt>, and
18 * <tt>higherKey</tt> return only the associated keys. All of these
19 * methods are designed for locating, not traversing entries.
20 *
21 * <p>A <tt>NavigableMap</tt> may be viewed and traversed in either
22 * ascending or descending key order. The <tt>Map</tt> methods
23 * <tt>keySet</tt> and <tt>entrySet</tt> return ascending views, and
24 * the additional methods <tt>descendingKeySet</tt> and
25 * <tt>descendingEntrySet</tt> return descending views. The
26 * performance of ascending traversals is likely to be faster than
27 * descending traversals. Notice that it is possible to perform
28 * subrange traversals in either direction using <tt>navigableSubMap</tt>.
29 * Methods <tt>navigableSubMap</tt>, <tt>navigableHeadMap</tt>, and
30 * <tt>navigableTailMap</tt> differ from the similarly named
31 * <tt>SortedMap</tt> methods only in that the returned maps
32 * are guaranteed to obey the <tt>NavigableMap</tt> interface.
33 *
34 * <p>This interface additionally defines methods <tt>firstEntry</tt>,
35 * <tt>pollFirstEntry</tt>, <tt>lastEntry</tt>, and
36 * <tt>pollLastEntry</tt> that return and/or remove the least and
37 * greatest mappings, if any exist, else returning <tt>null</tt>.
38 *
39 * <p> Implementations of entry-returning methods are expected to
40 * return <tt>Map.Entry</tt> pairs representing snapshots of mappings
41 * at the time they were produced, and thus generally do <em>not</em>
42 * support the optional <tt>Entry.setValue</tt> method. Note however
43 * that it is possible to change mappings in the associated map using
44 * method <tt>put</tt>.
45 *
46 * @author Doug Lea
47 * @param <K> the type of keys maintained by this map
48 * @param <V> the type of mapped values
49 */
50 public interface NavigableMap<K,V> extends SortedMap<K,V> {
51 /**
52 * Returns a key-value mapping associated with the least key
53 * greater than or equal to the given key, or <tt>null</tt> if there is
54 * no such entry.
55 *
56 * @param key the key.
57 * @return an Entry associated with ceiling of given key, or <tt>null</tt>
58 * if there is no such Entry.
59 * @throws ClassCastException if key cannot be compared with the keys
60 * currently in the map.
61 * @throws NullPointerException if key is <tt>null</tt> and this map
62 * does not support <tt>null</tt> keys.
63 */
64 Map.Entry<K,V> ceilingEntry(K key);
65
66 /**
67 * Returns least key greater than or equal to the given key, or
68 * <tt>null</tt> if there is no such key.
69 *
70 * @param key the key.
71 * @return the ceiling key, or <tt>null</tt>
72 * if there is no such key.
73 * @throws ClassCastException if key cannot be compared with the keys
74 * currently in the map.
75 * @throws NullPointerException if key is <tt>null</tt> and this map
76 * does not support <tt>null</tt> keys.
77 */
78 K ceilingKey(K key);
79
80 /**
81 * Returns a key-value mapping associated with the greatest
82 * key strictly less than the given key, or <tt>null</tt> if there is no
83 * such entry.
84 *
85 * @param key the key.
86 * @return an Entry with greatest key less than the given
87 * key, or <tt>null</tt> if there is no such Entry.
88 * @throws ClassCastException if key cannot be compared with the keys
89 * currently in the map.
90 * @throws NullPointerException if key is <tt>null</tt> and this map
91 * does not support <tt>null</tt> keys.
92 */
93 Map.Entry<K,V> lowerEntry(K key);
94
95 /**
96 * Returns the greatest key strictly less than the given key, or
97 * <tt>null</tt> if there is no such key.
98 *
99 * @param key the key.
100 * @return the greatest key less than the given
101 * key, or <tt>null</tt> if there is no such key.
102 * @throws ClassCastException if key cannot be compared with the keys
103 * currently in the map.
104 * @throws NullPointerException if key is <tt>null</tt> and this map
105 * does not support <tt>null</tt> keys.
106 */
107 K lowerKey(K key);
108
109 /**
110 * Returns a key-value mapping associated with the greatest key
111 * less than or equal to the given key, or <tt>null</tt> if there
112 * is no such entry.
113 *
114 * @param key the key.
115 * @return an Entry associated with floor of given key, or <tt>null</tt>
116 * if there is no such Entry.
117 * @throws ClassCastException if key cannot be compared with the keys
118 * currently in the map.
119 * @throws NullPointerException if key is <tt>null</tt> and this map
120 * does not support <tt>null</tt> keys.
121 */
122 Map.Entry<K,V> floorEntry(K key);
123
124 /**
125 * Returns the greatest key
126 * less than or equal to the given key, or <tt>null</tt> if there
127 * is no such key.
128 *
129 * @param key the key.
130 * @return the floor of given key, or <tt>null</tt> if there is no
131 * such key.
132 * @throws ClassCastException if key cannot be compared with the keys
133 * currently in the map.
134 * @throws NullPointerException if key is <tt>null</tt> and this map
135 * does not support <tt>null</tt> keys.
136 */
137 K floorKey(K key);
138
139 /**
140 * Returns a key-value mapping associated with the least key
141 * strictly greater than the given key, or <tt>null</tt> if there
142 * is no such entry.
143 *
144 * @param key the key.
145 * @return an Entry with least key greater than the given key, or
146 * <tt>null</tt> if there is no such Entry.
147 * @throws ClassCastException if key cannot be compared with the keys
148 * currently in the map.
149 * @throws NullPointerException if key is <tt>null</tt> and this map
150 * does not support <tt>null</tt> keys.
151 */
152 Map.Entry<K,V> higherEntry(K key);
153
154 /**
155 * Returns the least key strictly greater than the given key, or
156 * <tt>null</tt> if there is no such key.
157 *
158 * @param key the key.
159 * @return the least key greater than the given key, or
160 * <tt>null</tt> if there is no such key.
161 * @throws ClassCastException if key cannot be compared with the keys
162 * currently in the map.
163 * @throws NullPointerException if key is <tt>null</tt> and this map
164 * does not support <tt>null</tt> keys.
165 */
166 K higherKey(K key);
167
168 /**
169 * Returns a key-value mapping associated with the least
170 * key in this map, or <tt>null</tt> if the map is empty.
171 *
172 * @return an Entry with least key, or <tt>null</tt>
173 * if the map is empty.
174 */
175 Map.Entry<K,V> firstEntry();
176
177 /**
178 * Returns a key-value mapping associated with the greatest
179 * key in this map, or <tt>null</tt> if the map is empty.
180 *
181 * @return an Entry with greatest key, or <tt>null</tt>
182 * if the map is empty.
183 */
184 Map.Entry<K,V> lastEntry();
185
186 /**
187 * Removes and returns a key-value mapping associated with
188 * the least key in this map, or <tt>null</tt> if the map is empty.
189 *
190 * @return the removed first entry of this map, or <tt>null</tt>
191 * if the map is empty.
192 */
193 Map.Entry<K,V> pollFirstEntry();
194
195 /**
196 * Removes and returns a key-value mapping associated with
197 * the greatest key in this map, or <tt>null</tt> if the map is empty.
198 *
199 * @return the removed last entry of this map, or <tt>null</tt>
200 * if the map is empty.
201 */
202 Map.Entry<K,V> pollLastEntry();
203
204 /**
205 * Returns a set view of the keys contained in this map, in
206 * descending key order. The set is backed by the map, so changes
207 * to the map are reflected in the set, and vice-versa. If the
208 * map is modified while an iteration over the set is in progress
209 * (except through the iterator's own <tt>remove</tt> operation),
210 * the results of the iteration are undefined. The set supports
211 * element removal, which removes the corresponding mapping from
212 * the map, via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
213 * <tt>removeAll</tt> <tt>retainAll</tt>, and <tt>clear</tt>
214 * operations. It does not support the add or <tt>addAll</tt>
215 * operations.
216 *
217 * @return a set view of the keys contained in this map.
218 */
219 Set<K> descendingKeySet();
220
221 /**
222 * Returns a set view of the mappings contained in this map, in
223 * descending key order. Each element in the returned set is a
224 * <tt>Map.Entry</tt>. The set is backed by the map, so changes to
225 * the map are reflected in the set, and vice-versa. If the map
226 * is modified while an iteration over the set is in progress
227 * (except through the iterator's own <tt>remove</tt> operation,
228 * or through the <tt>setValue</tt> operation on a map entry
229 * returned by the iterator) the results of the iteration are
230 * undefined. The set supports element removal, which removes the
231 * corresponding mapping from the map, via the
232 * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
233 * <tt>removeAll</tt>, <tt>retainAll</tt> and <tt>clear</tt>
234 * operations. It does not support the <tt>add</tt> or
235 * <tt>addAll</tt> operations.
236 *
237 * @return a set view of the mappings contained in this map.
238 */
239 Set<Map.Entry<K, V>> descendingEntrySet();
240
241 /**
242 * Returns a view of the portion of this map whose keys range from
243 * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive. (If
244 * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned
245 * navigable map is empty.) The returned navigable map is backed
246 * by this map, so changes in the returned navigable map are
247 * reflected in this map, and vice-versa.
248 *
249 * @param fromKey low endpoint (inclusive) of the subMap.
250 * @param toKey high endpoint (exclusive) of the subMap.
251 *
252 * @return a view of the portion of this map whose keys range from
253 * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.
254 *
255 * @throws ClassCastException if <tt>fromKey</tt> and
256 * <tt>toKey</tt> cannot be compared to one another using this
257 * map's comparator (or, if the map has no comparator, using
258 * natural ordering).
259 * @throws IllegalArgumentException if <tt>fromKey</tt> is greater
260 * than <tt>toKey</tt>.
261 * @throws NullPointerException if <tt>fromKey</tt> or
262 * <tt>toKey</tt> is <tt>null</tt> and this map does not support
263 * <tt>null</tt> keys.
264 */
265 NavigableMap<K,V> navigableSubMap(K fromKey, K toKey);
266
267 /**
268 * Returns a view of the portion of this map whose keys are strictly less
269 * than <tt>toKey</tt>. The returned navigable map is backed by this map, so
270 * changes in the returned navigable map are reflected in this map, and
271 * vice-versa.
272 * @param toKey high endpoint (exclusive) of the headMap.
273 * @return a view of the portion of this map whose keys are strictly
274 * less than <tt>toKey</tt>.
275 *
276 * @throws ClassCastException if <tt>toKey</tt> is not compatible
277 * with this map's comparator (or, if the map has no comparator,
278 * if <tt>toKey</tt> does not implement <tt>Comparable</tt>).
279 * @throws NullPointerException if <tt>toKey</tt> is <tt>null</tt>
280 * and this map does not support <tt>null</tt> keys.
281 */
282 NavigableMap<K,V> navigableHeadMap(K toKey);
283
284 /**
285 * Returns a view of the portion of this map whose keys are
286 * greater than or equal to <tt>fromKey</tt>. The returned navigable
287 * map is backed by this map, so changes in the returned navigable
288 * map are reflected in this map, and vice-versa.
289 * @param fromKey low endpoint (inclusive) of the tailMap.
290 * @return a view of the portion of this map whose keys are greater
291 * than or equal to <tt>fromKey</tt>.
292 * @throws ClassCastException if <tt>fromKey</tt> is not compatible
293 * with this map's comparator (or, if the map has no comparator,
294 * if <tt>fromKey</tt> does not implement <tt>Comparable</tt>).
295 * @throws NullPointerException if <tt>fromKey</tt> is <tt>null</tt>
296 * and this map does not support <tt>null</tt> keys.
297 */
298 NavigableMap<K,V> navigableTailMap(K fromKey);
299 }