1 |
|
/* |
2 |
|
* Written by Doug Lea and Josh Bloch with assistance from members of JCP |
3 |
|
* JSR-166 Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package java.util; |
9 |
|
/** |
10 |
|
* A {@link SortedMap} extended with navigation methods returning the |
11 |
|
* closest matches for given search targets. Methods |
12 |
< |
* {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry}, |
13 |
< |
* and {@code higherEntry} return {@code Map.Entry} objects |
12 |
> |
* {@link #lowerEntry}, {@link #floorEntry}, {@link #ceilingEntry}, |
13 |
> |
* and {@link #higherEntry} return {@code Map.Entry} 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 |
|
* {@code null} if there is no such key. Similarly, methods |
17 |
< |
* {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and |
18 |
< |
* {@code higherKey} return only the associated keys. All of these |
17 |
> |
* {@link #lowerKey}, {@link #floorKey}, {@link #ceilingKey}, and |
18 |
> |
* {@link #higherKey} return only the associated keys. All of these |
19 |
|
* methods are designed for locating, not traversing entries. |
20 |
|
* |
21 |
|
* <p>A {@code NavigableMap} may be accessed and traversed in either |
30 |
|
* Submaps of any {@code NavigableMap} must implement the {@code |
31 |
|
* NavigableMap} interface. |
32 |
|
* |
33 |
< |
* <p>This interface additionally defines methods {@code firstEntry}, |
34 |
< |
* {@code pollFirstEntry}, {@code lastEntry}, and |
35 |
< |
* {@code pollLastEntry} that return and/or remove the least and |
33 |
> |
* <p>This interface additionally defines methods {@link #firstEntry}, |
34 |
> |
* {@link #pollFirstEntry}, {@link #lastEntry}, and |
35 |
> |
* {@link #pollLastEntry} that return and/or remove the least and |
36 |
|
* greatest mappings, if any exist, else returning {@code null}. |
37 |
|
* |
38 |
< |
* <p> Implementations of entry-returning methods are expected to |
38 |
> |
* <p>Implementations of entry-returning methods are expected to |
39 |
|
* return {@code Map.Entry} pairs representing snapshots of mappings |
40 |
|
* at the time they were produced, and thus generally do <em>not</em> |
41 |
|
* support the optional {@code Entry.setValue} method. Note however |
42 |
|
* that it is possible to change mappings in the associated map using |
43 |
|
* method {@code put}. |
44 |
|
* |
45 |
+ |
* <p>Methods |
46 |
+ |
* {@link #subMap(Object, Object) subMap(K, K)}, |
47 |
+ |
* {@link #headMap(Object) headMap(K)}, and |
48 |
+ |
* {@link #tailMap(Object) tailMap(K)} |
49 |
+ |
* are specified to return {@code SortedMap} to allow existing |
50 |
+ |
* implementations of {@code SortedMap} to be compatibly retrofitted to |
51 |
+ |
* implement {@code NavigableMap}, but extensions and implementations |
52 |
+ |
* of this interface are encouraged to override these methods to return |
53 |
+ |
* {@code NavigableMap}. Similarly, |
54 |
+ |
* {@link #keySet()} can be overridden to return {@code NavigableSet}. |
55 |
+ |
* |
56 |
|
* <p>This interface is a member of the |
57 |
< |
* <a href="{@docRoot}/../guide/collections/index.html"> |
57 |
> |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
58 |
|
* Java Collections Framework</a>. |
59 |
|
* |
60 |
|
* @author Doug Lea |
217 |
|
Map.Entry<K,V> pollLastEntry(); |
218 |
|
|
219 |
|
/** |
220 |
< |
* Returns a {@link NavigableMap} view of the mappings contained in this |
221 |
< |
* map in descending order. The descending map is backed by this map, so |
222 |
< |
* changes to the map are reflected in the descending set, and vice-versa. |
223 |
< |
* If either map is modified while an iteration over a collection view of |
224 |
< |
* the other map is in progress (except through the iterator's own |
225 |
< |
* {@code remove} operation), the results of the iteration are undefined. |
220 |
> |
* Returns a reverse order view of the mappings contained in this map. |
221 |
> |
* The descending map is backed by this map, so changes to the map are |
222 |
> |
* reflected in the descending map, and vice-versa. If either map is |
223 |
> |
* modified while an iteration over a collection view of either map |
224 |
> |
* is in progress (except through the iterator's own {@code remove} |
225 |
> |
* operation), the results of the iteration are undefined. |
226 |
> |
* |
227 |
> |
* <p>The returned map has an ordering equivalent to |
228 |
> |
* {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}{@code (comparator())}. |
229 |
> |
* The expression {@code m.descendingMap().descendingMap()} returns a |
230 |
> |
* view of {@code m} essentially equivalent to {@code m}. |
231 |
|
* |
232 |
< |
* @return a navigable map view of the mappings contained in this map, |
217 |
< |
* sorted in descending order |
232 |
> |
* @return a reverse order view of this map |
233 |
|
*/ |
234 |
|
NavigableMap<K,V> descendingMap(); |
235 |
|
|
236 |
|
/** |
237 |
< |
* Returns a navigable set view of the keys contained in this navigable |
238 |
< |
* map. The set is backed by the map, so changes to the map are reflected |
239 |
< |
* in the set, and vice-versa. If the map is modified while an iteration |
240 |
< |
* over the set is in progress (except through the iterator's own |
241 |
< |
* {@code remove} operation), the results of the iteration are undefined. |
242 |
< |
* The set supports element removal, which removes the corresponding |
243 |
< |
* mapping from the map, via the {@code Iterator.remove}, |
244 |
< |
* {@code Set.remove}, {@code removeAll} {@code retainAll}, and |
245 |
< |
* {@code clear} operations. It does not support the {@code add} or |
246 |
< |
* {@code addAll} operations. |
237 |
> |
* Returns a {@link NavigableSet} view of the keys contained in this map. |
238 |
> |
* The set's iterator returns the keys in ascending order. |
239 |
> |
* The set is backed by the map, so changes to the map are reflected in |
240 |
> |
* the set, and vice-versa. If the map is modified while an iteration |
241 |
> |
* over the set is in progress (except through the iterator's own {@code |
242 |
> |
* remove} operation), the results of the iteration are undefined. The |
243 |
> |
* set supports element removal, which removes the corresponding mapping |
244 |
> |
* from the map, via the {@code Iterator.remove}, {@code Set.remove}, |
245 |
> |
* {@code removeAll}, {@code retainAll}, and {@code clear} operations. |
246 |
> |
* It does not support the {@code add} or {@code addAll} operations. |
247 |
|
* |
248 |
< |
* @return a navigable set view of the keys contained in this navigable map |
248 |
> |
* @return a navigable set view of the keys in this map |
249 |
|
*/ |
250 |
|
NavigableSet<K> navigableKeySet(); |
251 |
|
|
252 |
|
/** |
253 |
< |
* Returns a {@link NavigableSet} view of the keys contained in this map. |
253 |
> |
* Returns a reverse order {@link NavigableSet} view of the keys contained in this map. |
254 |
|
* The set's iterator returns the keys in descending order. |
255 |
< |
* The set is backed by the map, so changes to the map are |
256 |
< |
* reflected in the set, and vice-versa. If the map is modified |
257 |
< |
* while an iteration over the set is in progress (except through |
258 |
< |
* the iterator's own <tt>remove</tt> operation), the results of |
259 |
< |
* the iteration are undefined. The set supports element removal, |
260 |
< |
* which removes the corresponding mapping from the map, via the |
261 |
< |
* <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, |
262 |
< |
* <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> |
248 |
< |
* operations. It does not support the <tt>add</tt> or <tt>addAll</tt> |
249 |
< |
* operations. |
255 |
> |
* The set is backed by the map, so changes to the map are reflected in |
256 |
> |
* the set, and vice-versa. If the map is modified while an iteration |
257 |
> |
* over the set is in progress (except through the iterator's own {@code |
258 |
> |
* remove} operation), the results of the iteration are undefined. The |
259 |
> |
* set supports element removal, which removes the corresponding mapping |
260 |
> |
* from the map, via the {@code Iterator.remove}, {@code Set.remove}, |
261 |
> |
* {@code removeAll}, {@code retainAll}, and {@code clear} operations. |
262 |
> |
* It does not support the {@code add} or {@code addAll} operations. |
263 |
|
* |
264 |
< |
* @return a set view of the keys contained in this map, sorted in |
252 |
< |
* descending order |
264 |
> |
* @return a reverse order navigable set view of the keys in this map |
265 |
|
*/ |
266 |
|
NavigableSet<K> descendingKeySet(); |
267 |
|
|
279 |
|
* submap either of whose endpoints lie outside its range. |
280 |
|
* |
281 |
|
* @param fromKey low endpoint of the keys in the returned map |
282 |
< |
* @param fromInclusive true if the low endpoint ({@code fromKey}) is |
283 |
< |
* to be included in the the returned view |
282 |
> |
* @param fromInclusive {@code true} if the low endpoint |
283 |
> |
* is to be included in the returned view |
284 |
|
* @param toKey high endpoint of the keys in the returned map |
285 |
< |
* @param toInclusive true if the high endpoint ({@code toKey}) is |
286 |
< |
* to be included in the the returned view |
285 |
> |
* @param toInclusive {@code true} if the high endpoint |
286 |
> |
* is to be included in the returned view |
287 |
|
* @return a view of the portion of this map whose keys range from |
288 |
|
* {@code fromKey} to {@code toKey} |
289 |
|
* @throws ClassCastException if {@code fromKey} and {@code toKey} |
313 |
|
* on an attempt to insert a key outside its range. |
314 |
|
* |
315 |
|
* @param toKey high endpoint of the keys in the returned map |
316 |
< |
* @param inclusive true if the high endpoint ({@code toKey}) is |
317 |
< |
* to be included in the the returned view |
316 |
> |
* @param inclusive {@code true} if the high endpoint |
317 |
> |
* is to be included in the returned view |
318 |
|
* @return a view of the portion of this map whose keys are less than |
319 |
|
* (or equal to, if {@code inclusive} is true) {@code toKey} |
320 |
|
* @throws ClassCastException if {@code toKey} is not compatible |
342 |
|
* on an attempt to insert a key outside its range. |
343 |
|
* |
344 |
|
* @param fromKey low endpoint of the keys in the returned map |
345 |
< |
* @param inclusive true if the low endpoint ({@code fromKey}) is |
346 |
< |
* to be included in the the returned view |
345 |
> |
* @param inclusive {@code true} if the low endpoint |
346 |
> |
* is to be included in the returned view |
347 |
|
* @return a view of the portion of this map whose keys are greater than |
348 |
|
* (or equal to, if {@code inclusive} is true) {@code fromKey} |
349 |
|
* @throws ClassCastException if {@code fromKey} is not compatible |
359 |
|
* bounds of the range |
360 |
|
*/ |
361 |
|
NavigableMap<K,V> tailMap(K fromKey, boolean inclusive); |
362 |
+ |
|
363 |
+ |
/** |
364 |
+ |
* {@inheritDoc} |
365 |
+ |
* |
366 |
+ |
* <p>Equivalent to {@code subMap(fromKey, true, toKey, false)}. |
367 |
+ |
* |
368 |
+ |
* @throws ClassCastException {@inheritDoc} |
369 |
+ |
* @throws NullPointerException {@inheritDoc} |
370 |
+ |
* @throws IllegalArgumentException {@inheritDoc} |
371 |
+ |
*/ |
372 |
+ |
SortedMap<K,V> subMap(K fromKey, K toKey); |
373 |
+ |
|
374 |
+ |
/** |
375 |
+ |
* {@inheritDoc} |
376 |
+ |
* |
377 |
+ |
* <p>Equivalent to {@code headMap(toKey, false)}. |
378 |
+ |
* |
379 |
+ |
* @throws ClassCastException {@inheritDoc} |
380 |
+ |
* @throws NullPointerException {@inheritDoc} |
381 |
+ |
* @throws IllegalArgumentException {@inheritDoc} |
382 |
+ |
*/ |
383 |
+ |
SortedMap<K,V> headMap(K toKey); |
384 |
+ |
|
385 |
+ |
/** |
386 |
+ |
* {@inheritDoc} |
387 |
+ |
* |
388 |
+ |
* <p>Equivalent to {@code tailMap(fromKey, true)}. |
389 |
+ |
* |
390 |
+ |
* @throws ClassCastException {@inheritDoc} |
391 |
+ |
* @throws NullPointerException {@inheritDoc} |
392 |
+ |
* @throws IllegalArgumentException {@inheritDoc} |
393 |
+ |
*/ |
394 |
+ |
SortedMap<K,V> tailMap(K fromKey); |
395 |
|
} |