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 |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package jsr166x; |
9 |
|
import java.util.*; |
10 |
|
|
11 |
|
/** |
12 |
< |
* A {@link SortedMap} extended with navigation methods returning |
13 |
< |
* key-value pairs holding the closest matches for given search |
14 |
< |
* targets. Methods <tt>lowerEntry</tt>, <tt>floorEntry</tt>, |
15 |
< |
* <tt>ceilingEntry</tt>, and <tt>higherEntry</tt> return |
16 |
< |
* <tt>Map.Entry</tt> objects associated with keys respectively less |
17 |
< |
* than, less than or equal, greater than or equal, and greater than a |
18 |
< |
* given key, returning <tt>null</tt> if there is no such key. |
19 |
< |
* Similarly, methods <tt>lowerKey</tt>, <tt>floorKey</tt>, |
20 |
< |
* <tt>ceilingKey</tt>, and <tt>higherKey</tt> return only the |
21 |
< |
* associated keys. All of these methods are designed for locating, |
22 |
< |
* not traversing entries. |
12 |
> |
* A {@link SortedMap} extended with navigation methods returning the |
13 |
> |
* closest matches for given search targets. Methods |
14 |
> |
* <tt>lowerEntry</tt>, <tt>floorEntry</tt>, <tt>ceilingEntry</tt>, |
15 |
> |
* and <tt>higherEntry</tt> return <tt>Map.Entry</tt> objects |
16 |
> |
* associated with keys respectively less than, less than or equal, |
17 |
> |
* greater than or equal, and greater than a given key, returning |
18 |
> |
* <tt>null</tt> if there is no such key. Similarly, methods |
19 |
> |
* <tt>lowerKey</tt>, <tt>floorKey</tt>, <tt>ceilingKey</tt>, and |
20 |
> |
* <tt>higherKey</tt> return only the associated keys. All of these |
21 |
> |
* methods are designed for locating, not traversing entries. |
22 |
|
* |
23 |
|
* <p>A <tt>NavigableMap</tt> may be viewed and traversed in either |
24 |
|
* ascending or descending key order. The <tt>Map</tt> methods |
25 |
< |
* <tt>keySet</tt> and <tt>entrySet</tt>) return ascending views, and |
25 |
> |
* <tt>keySet</tt> and <tt>entrySet</tt> return ascending views, and |
26 |
|
* the additional methods <tt>descendingKeySet</tt> and |
27 |
< |
* <tt>descendingEntrySet</tt>) return descending views. The |
27 |
> |
* <tt>descendingEntrySet</tt> return descending views. The |
28 |
|
* performance of ascending traversals is likely to be faster than |
29 |
|
* descending traversals. Notice that it is possible to perform |
30 |
|
* subrannge traversals in either direction using <tt>SubMap</tt>. |
31 |
< |
* |
31 |
> |
* |
32 |
|
* <p>This interface additionally defines methods <tt>firstEntry</tt>, |
33 |
|
* <tt>pollFirstEntry</tt>, <tt>lastEntry</tt>, and |
34 |
|
* <tt>pollLastEntry</tt> that return and/or remove the least and |
43 |
|
* |
44 |
|
* @author Doug Lea |
45 |
|
* @param <K> the type of keys maintained by this map |
46 |
< |
* @param <V> the type of mapped values |
46 |
> |
* @param <V> the type of mapped values |
47 |
|
*/ |
48 |
|
public interface NavigableMap<K,V> extends SortedMap<K,V> { |
49 |
|
/** |
50 |
|
* Returns a key-value mapping associated with the least key |
51 |
|
* greater than or equal to the given key, or <tt>null</tt> if there is |
52 |
< |
* no such entry. |
53 |
< |
* |
52 |
> |
* no such entry. |
53 |
> |
* |
54 |
|
* @param key the key. |
55 |
|
* @return an Entry associated with ceiling of given key, or <tt>null</tt> |
56 |
|
* if there is no such Entry. |
64 |
|
/** |
65 |
|
* Returns least key greater than or equal to the given key, or |
66 |
|
* <tt>null</tt> if there is no such key. |
67 |
< |
* |
67 |
> |
* |
68 |
|
* @param key the key. |
69 |
|
* @return the ceiling key, or <tt>null</tt> |
70 |
|
* if there is no such key. |
78 |
|
/** |
79 |
|
* Returns a key-value mapping associated with the greatest |
80 |
|
* key strictly less than the given key, or <tt>null</tt> if there is no |
81 |
< |
* such entry. |
82 |
< |
* |
81 |
> |
* such entry. |
82 |
> |
* |
83 |
|
* @param key the key. |
84 |
|
* @return an Entry with greatest key less than the given |
85 |
|
* key, or <tt>null</tt> if there is no such Entry. |
93 |
|
/** |
94 |
|
* Returns the greatest key strictly less than the given key, or |
95 |
|
* <tt>null</tt> if there is no such key. |
96 |
< |
* |
96 |
> |
* |
97 |
|
* @param key the key. |
98 |
|
* @return the greatest key less than the given |
99 |
|
* key, or <tt>null</tt> if there is no such key. |
108 |
|
* Returns a key-value mapping associated with the greatest key |
109 |
|
* less than or equal to the given key, or <tt>null</tt> if there |
110 |
|
* is no such entry. |
111 |
< |
* |
111 |
> |
* |
112 |
|
* @param key the key. |
113 |
|
* @return an Entry associated with floor of given key, or <tt>null</tt> |
114 |
|
* if there is no such Entry. |
123 |
|
* Returns the greatest key |
124 |
|
* less than or equal to the given key, or <tt>null</tt> if there |
125 |
|
* is no such key. |
126 |
< |
* |
126 |
> |
* |
127 |
|
* @param key the key. |
128 |
|
* @return the floor of given key, or <tt>null</tt> if there is no |
129 |
|
* such key. |
138 |
|
* Returns a key-value mapping associated with the least key |
139 |
|
* strictly greater than the given key, or <tt>null</tt> if there |
140 |
|
* is no such entry. |
141 |
< |
* |
141 |
> |
* |
142 |
|
* @param key the key. |
143 |
|
* @return an Entry with least key greater than the given key, or |
144 |
|
* <tt>null</tt> if there is no such Entry. |
152 |
|
/** |
153 |
|
* Returns the least key strictly greater than the given key, or |
154 |
|
* <tt>null</tt> if there is no such key. |
155 |
< |
* |
155 |
> |
* |
156 |
|
* @param key the key. |
157 |
|
* @return the least key greater than the given key, or |
158 |
|
* <tt>null</tt> if there is no such key. |
166 |
|
/** |
167 |
|
* Returns a key-value mapping associated with the least |
168 |
|
* key in this map, or <tt>null</tt> if the map is empty. |
169 |
< |
* |
170 |
< |
* @return an Entry with least key, or <tt>null</tt> |
169 |
> |
* |
170 |
> |
* @return an Entry with least key, or <tt>null</tt> |
171 |
|
* if the map is empty. |
172 |
|
*/ |
173 |
|
public Map.Entry<K,V> firstEntry(); |
175 |
|
/** |
176 |
|
* Returns a key-value mapping associated with the greatest |
177 |
|
* key in this map, or <tt>null</tt> if the map is empty. |
178 |
< |
* |
178 |
> |
* |
179 |
|
* @return an Entry with greatest key, or <tt>null</tt> |
180 |
|
* if the map is empty. |
181 |
|
*/ |
184 |
|
/** |
185 |
|
* Removes and returns a key-value mapping associated with |
186 |
|
* the least key in this map, or <tt>null</tt> if the map is empty. |
187 |
< |
* |
187 |
> |
* |
188 |
|
* @return the removed first entry of this map, or <tt>null</tt> |
189 |
|
* if the map is empty. |
190 |
|
*/ |
193 |
|
/** |
194 |
|
* Removes and returns a key-value mapping associated with |
195 |
|
* the greatest key in this map, or <tt>null</tt> if the map is empty. |
196 |
< |
* |
196 |
> |
* |
197 |
|
* @return the removed last entry of this map, or <tt>null</tt> |
198 |
|
* if the map is empty. |
199 |
|
*/ |
219 |
|
/** |
220 |
|
* Returns a set view of the mappings contained in this map, in |
221 |
|
* descending key order. Each element in the returned set is a |
222 |
< |
* {@link Map.Entry}. The set is backed by the map, so changes to |
222 |
> |
* <tt>Map.Entry</tt>. The set is backed by the map, so changes to |
223 |
|
* the map are reflected in the set, and vice-versa. If the map |
224 |
|
* is modified while an iteration over the set is in progress |
225 |
|
* (except through the iterator's own <tt>remove</tt> operation, |
242 |
|
* <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned sorted map |
243 |
|
* is empty.) The returned sorted map is backed by this map, so changes |
244 |
|
* in the returned sorted map are reflected in this map, and vice-versa. |
245 |
< |
|
245 |
> |
* |
246 |
|
* @param fromKey low endpoint (inclusive) of the subMap. |
247 |
|
* @param toKey high endpoint (exclusive) of the subMap. |
248 |
|
* |
265 |
|
* Returns a view of the portion of this map whose keys are strictly less |
266 |
|
* than <tt>toKey</tt>. The returned sorted map is backed by this map, so |
267 |
|
* changes in the returned sorted map are reflected in this map, and |
268 |
< |
* vice-versa. |
268 |
> |
* vice-versa. |
269 |
|
* @param toKey high endpoint (exclusive) of the headMap. |
270 |
|
* @return a view of the portion of this map whose keys are strictly |
271 |
|
* less than <tt>toKey</tt>. |