ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/NavigableMap.java (file contents):
Revision 1.3 by dl, Tue Mar 22 01:30:10 2005 UTC vs.
Revision 1.10 by dl, Mon Jul 18 19:32:38 2005 UTC

# Line 25 | Line 25 | package java.util;
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>SubMap</tt>.
29 < *
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 their declared return types.
32 > * Submaps of any <tt>NavigableMap</tt> must obey
33 > * the <tt>NavigableMap</tt> interface.
34 > *
35   * <p>This interface additionally defines methods <tt>firstEntry</tt>,
36   * <tt>pollFirstEntry</tt>, <tt>lastEntry</tt>, and
37   * <tt>pollLastEntry</tt> that return and/or remove the least and
# Line 39 | Line 44 | package java.util;
44   * that it is possible to change mappings in the associated map using
45   * method <tt>put</tt>.
46   *
47 + * <p>This interface is a member of the
48 + * <a href="{@docRoot}/../guide/collections/index.html">
49 + * Java Collections Framework</a>.
50 + *
51   * @author Doug Lea
52   * @param <K> the type of keys maintained by this map
53 < * @param <V> the type of mapped values
53 > * @param <V> the type of mapped values
54 > * @since 1.6
55   */
56   public interface NavigableMap<K,V> extends SortedMap<K,V> {
57      /**
58 <     * Returns a key-value mapping associated with the least key
59 <     * greater than or equal to the given key, or <tt>null</tt> if there is
60 <     * no such entry.
61 <     *
62 <     * @param key the key.
63 <     * @return an Entry associated with ceiling of given key, or <tt>null</tt>
64 <     * if there is no such Entry.
65 <     * @throws ClassCastException if key cannot be compared with the keys
66 <     *            currently in the map.
67 <     * @throws NullPointerException if key is <tt>null</tt> and this map
68 <     * does not support <tt>null</tt> keys.
59 <     */
60 <    Map.Entry<K,V> ceilingEntry(K key);
61 <
62 <    /**
63 <     * Returns least key greater than or equal to the given key, or
64 <     * <tt>null</tt> if there is no such key.
65 <     *
66 <     * @param key the key.
67 <     * @return the ceiling key, or <tt>null</tt>
68 <     * if there is no such key.
69 <     * @throws ClassCastException if key cannot be compared with the keys
70 <     *            currently in the map.
71 <     * @throws NullPointerException if key is <tt>null</tt> and this map
72 <     * does not support <tt>null</tt> keys.
73 <     */
74 <    K ceilingKey(K key);
75 <
76 <    /**
77 <     * Returns a key-value mapping associated with the greatest
78 <     * key strictly less than the given key, or <tt>null</tt> if there is no
79 <     * such entry.
80 <     *
81 <     * @param key the key.
82 <     * @return an Entry with greatest key less than the given
83 <     * key, or <tt>null</tt> if there is no such Entry.
84 <     * @throws ClassCastException if key cannot be compared with the keys
85 <     *            currently in the map.
86 <     * @throws NullPointerException if key is <tt>null</tt> and this map
87 <     * does not support <tt>null</tt> keys.
58 >     * Returns a key-value mapping associated with the greatest key
59 >     * strictly less than the given key, or <tt>null</tt> if there is
60 >     * no such key.
61 >     *
62 >     * @param key the key
63 >     * @return an entry with the greatest key less than <tt>key</tt>,
64 >     *         or <tt>null</tt> if there is no such key
65 >     * @throws ClassCastException if the specified key cannot be compared
66 >     *         with the keys currently in the map
67 >     * @throws NullPointerException if the specified key is null
68 >     *         and this map does not permit null keys
69       */
70      Map.Entry<K,V> lowerEntry(K key);
71  
72      /**
73       * Returns the greatest key strictly less than the given key, or
74       * <tt>null</tt> if there is no such key.
75 <     *
76 <     * @param key the key.
77 <     * @return the greatest key less than the given
78 <     * key, or <tt>null</tt> if there is no such key.
79 <     * @throws ClassCastException if key cannot be compared with the keys
80 <     *            currently in the map.
81 <     * @throws NullPointerException if key is <tt>null</tt> and this map
82 <     * does not support <tt>null</tt> keys.
75 >     *
76 >     * @param key the key
77 >     * @return the greatest key less than <tt>key</tt>,
78 >     *         or <tt>null</tt> if there is no such key
79 >     * @throws ClassCastException if the specified key cannot be compared
80 >     *         with the keys currently in the map
81 >     * @throws NullPointerException if the specified key is null
82 >     *         and this map does not permit null keys
83       */
84      K lowerKey(K key);
85  
86      /**
87       * Returns a key-value mapping associated with the greatest key
88       * less than or equal to the given key, or <tt>null</tt> if there
89 <     * is no such entry.
90 <     *
91 <     * @param key the key.
92 <     * @return an Entry associated with floor of given key, or <tt>null</tt>
93 <     * if there is no such Entry.
94 <     * @throws ClassCastException if key cannot be compared with the keys
95 <     *            currently in the map.
96 <     * @throws NullPointerException if key is <tt>null</tt> and this map
97 <     * does not support <tt>null</tt> keys.
89 >     * is no such key.
90 >     *
91 >     * @param key the key
92 >     * @return an entry with the greatest key less than or equal to
93 >     *         <tt>key</tt>, or <tt>null</tt> if there is no such key
94 >     * @throws ClassCastException if the specified key cannot be compared
95 >     *         with the keys currently in the map
96 >     * @throws NullPointerException if the specified key is null
97 >     *         and this map does not permit null keys
98       */
99      Map.Entry<K,V> floorEntry(K key);
100  
101      /**
102 <     * Returns the greatest key
103 <     * less than or equal to the given key, or <tt>null</tt> if there
104 <     * is no such key.
105 <     *
106 <     * @param key the key.
107 <     * @return the floor of given key, or <tt>null</tt> if there is no
108 <     * such key.
109 <     * @throws ClassCastException if key cannot be compared with the keys
110 <     *            currently in the map.
111 <     * @throws NullPointerException if key is <tt>null</tt> and this map
131 <     * does not support <tt>null</tt> keys.
102 >     * Returns the greatest key less than or equal to the given key,
103 >     * or <tt>null</tt> if there is no such key.
104 >     *
105 >     * @param key the key
106 >     * @return the greatest key less than or equal to <tt>key</tt>,
107 >     *         or <tt>null</tt> if there is no such key
108 >     * @throws ClassCastException if the specified key cannot be compared
109 >     *         with the keys currently in the map
110 >     * @throws NullPointerException if the specified key is null
111 >     *         and this map does not permit null keys
112       */
113      K floorKey(K key);
114  
115      /**
116       * Returns a key-value mapping associated with the least key
117 +     * greater than or equal to the given key, or <tt>null</tt> if
118 +     * there is no such key.
119 +     *
120 +     * @param key the key
121 +     * @return an entry with the least key greater than or equal to
122 +     *         <tt>key</tt>, or <tt>null</tt> if there is no such key
123 +     * @throws ClassCastException if the specified key cannot be compared
124 +     *         with the keys currently in the map
125 +     * @throws NullPointerException if the specified key is null
126 +     *         and this map does not permit null keys
127 +     */
128 +    Map.Entry<K,V> ceilingEntry(K key);
129 +
130 +    /**
131 +     * Returns the least key greater than or equal to the given key,
132 +     * or <tt>null</tt> if there is no such key.
133 +     *
134 +     * @param key the key
135 +     * @return the least key greater than or equal to <tt>key</tt>,
136 +     *         or <tt>null</tt> if there is no such key
137 +     * @throws ClassCastException if the specified key cannot be compared
138 +     *         with the keys currently in the map
139 +     * @throws NullPointerException if the specified key is null
140 +     *         and this map does not permit null keys
141 +     */
142 +    K ceilingKey(K key);
143 +
144 +    /**
145 +     * Returns a key-value mapping associated with the least key
146       * strictly greater than the given key, or <tt>null</tt> if there
147 <     * is no such entry.
148 <     *
149 <     * @param key the key.
150 <     * @return an Entry with least key greater than the given key, or
151 <     * <tt>null</tt> if there is no such Entry.
152 <     * @throws ClassCastException if key cannot be compared with the keys
153 <     *            currently in the map.
154 <     * @throws NullPointerException if key is <tt>null</tt> and this map
155 <     * does not support <tt>null</tt> keys.
147 >     * is no such key.
148 >     *
149 >     * @param key the key
150 >     * @return an entry with the least key greater than <tt>key</tt>,
151 >     *         or <tt>null</tt> if there is no such key
152 >     * @throws ClassCastException if the specified key cannot be compared
153 >     *         with the keys currently in the map
154 >     * @throws NullPointerException if the specified key is null
155 >     *         and this map does not permit null keys
156       */
157      Map.Entry<K,V> higherEntry(K key);
158  
159      /**
160       * Returns the least key strictly greater than the given key, or
161       * <tt>null</tt> if there is no such key.
162 <     *
163 <     * @param key the key.
164 <     * @return the least key greater than the given key, or
165 <     * <tt>null</tt> if there is no such key.
166 <     * @throws ClassCastException if key cannot be compared with the keys
167 <     *            currently in the map.
168 <     * @throws NullPointerException if key is <tt>null</tt> and this map
169 <     * does not support <tt>null</tt> keys.
162 >     *
163 >     * @param key the key
164 >     * @return the least key greater than <tt>key</tt>,
165 >     *         or <tt>null</tt> if there is no such key
166 >     * @throws ClassCastException if the specified key cannot be compared
167 >     *         with the keys currently in the map
168 >     * @throws NullPointerException if the specified key is null
169 >     *         and this map does not permit null keys
170       */
171      K higherKey(K key);
172  
173      /**
174       * Returns a key-value mapping associated with the least
175       * key in this map, or <tt>null</tt> if the map is empty.
176 <     *
177 <     * @return an Entry with least key, or <tt>null</tt>
178 <     * if the map is empty.
176 >     *
177 >     * @return an entry with the least key,
178 >     *         or <tt>null</tt> if this map is empty
179       */
180      Map.Entry<K,V> firstEntry();
181  
182      /**
183       * Returns a key-value mapping associated with the greatest
184       * key in this map, or <tt>null</tt> if the map is empty.
185 <     *
186 <     * @return an Entry with greatest key, or <tt>null</tt>
187 <     * if the map is empty.
185 >     *
186 >     * @return an entry with the greatest key,
187 >     *         or <tt>null</tt> if this map is empty
188       */
189      Map.Entry<K,V> lastEntry();
190  
191      /**
192       * Removes and returns a key-value mapping associated with
193       * the least key in this map, or <tt>null</tt> if the map is empty.
194 <     *
195 <     * @return the removed first entry of this map, or <tt>null</tt>
196 <     * if the map is empty.
194 >     *
195 >     * @return the removed first entry of this map,
196 >     *         or <tt>null</tt> if this map is empty
197       */
198      Map.Entry<K,V> pollFirstEntry();
199  
200      /**
201       * Removes and returns a key-value mapping associated with
202       * the greatest key in this map, or <tt>null</tt> if the map is empty.
203 <     *
204 <     * @return the removed last entry of this map, or <tt>null</tt>
205 <     * if the map is empty.
203 >     *
204 >     * @return the removed last entry of this map,
205 >     *         or <tt>null</tt> if this map is empty
206       */
207      Map.Entry<K,V> pollLastEntry();
208  
209      /**
210 <     * Returns a set view of the keys contained in this map, in
211 <     * descending key order.  The set is backed by the map, so changes
212 <     * to the map are reflected in the set, and vice-versa.  If the
213 <     * map is modified while an iteration over the set is in progress
214 <     * (except through the iterator's own <tt>remove</tt> operation),
215 <     * the results of the iteration are undefined.  The set supports
216 <     * element removal, which removes the corresponding mapping from
217 <     * the map, via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
218 <     * <tt>removeAll</tt> <tt>retainAll</tt>, and <tt>clear</tt>
219 <     * operations.  It does not support the add or <tt>addAll</tt>
210 >     * Returns a {@link Set} view of the keys contained in this map.
211 >     * The set's iterator returns the keys in descending order.
212 >     * The set is backed by the map, so changes to the map are
213 >     * reflected in the set, and vice-versa.  If the map is modified
214 >     * while an iteration over the set is in progress (except through
215 >     * the iterator's own <tt>remove</tt> operation), the results of
216 >     * the iteration are undefined.  The set supports element removal,
217 >     * which removes the corresponding mapping from the map, via the
218 >     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
219 >     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
220 >     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
221       * operations.
222       *
223 <     * @return a set view of the keys contained in this map.
223 >     * @return a set view of the keys contained in this map, sorted in
224 >     *         descending order
225       */
226      Set<K> descendingKeySet();
227  
228      /**
229 <     * Returns a set view of the mappings contained in this map, in
230 <     * descending key order.  Each element in the returned set is a
231 <     * <tt>Map.Entry</tt>.  The set is backed by the map, so changes to
232 <     * the map are reflected in the set, and vice-versa.  If the map
233 <     * is modified while an iteration over the set is in progress
234 <     * (except through the iterator's own <tt>remove</tt> operation,
235 <     * or through the <tt>setValue</tt> operation on a map entry
236 <     * returned by the iterator) the results of the iteration are
237 <     * undefined.  The set supports element removal, which removes the
238 <     * corresponding mapping from the map, via the
239 <     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
240 <     * <tt>removeAll</tt>, <tt>retainAll</tt> and <tt>clear</tt>
241 <     * operations.  It does not support the <tt>add</tt> or
231 <     * <tt>addAll</tt> operations.
229 >     * Returns a {@link Set} view of the mappings contained in this map.
230 >     * The set's iterator returns the entries in descending key order.
231 >     * The set is backed by the map, so changes to the map are
232 >     * reflected in the set, and vice-versa.  If the map is modified
233 >     * while an iteration over the set is in progress (except through
234 >     * the iterator's own <tt>remove</tt> operation, or through the
235 >     * <tt>setValue</tt> operation on a map entry returned by the
236 >     * iterator) the results of the iteration are undefined.  The set
237 >     * supports element removal, which removes the corresponding
238 >     * mapping from the map, via the <tt>Iterator.remove</tt>,
239 >     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
240 >     * <tt>clear</tt> operations.  It does not support the
241 >     * <tt>add</tt> or <tt>addAll</tt> operations.
242       *
243 <     * @return a set view of the mappings contained in this map.
243 >     * @return a set view of the mappings contained in this map,
244 >     *         sorted in descending key order
245       */
246      Set<Map.Entry<K, V>> descendingEntrySet();
247  
248      /**
249       * Returns a view of the portion of this map whose keys range from
250       * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.  (If
251 <     * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned
252 <     * navigable map is empty.)  The returned navigable map is backed
253 <     * by this map, so changes in the returned navigable map are
254 <     * reflected in this map, and vice-versa. Note: This
255 <     * method differs from <tt>SortedMap.subMap</tt> only
245 <     * in that the returned map is guaranteed to support the
246 <     * <tt>NavigableMap</tt> interface.
251 >     * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned map
252 >     * is empty.)  The returned map is backed by this map, so changes
253 >     * in the returned map are reflected in this map, and vice-versa.
254 >     * The returned map supports all optional map operations that this
255 >     * map supports.
256       *
257 <     * @param fromKey low endpoint (inclusive) of the subMap.
258 <     * @param toKey high endpoint (exclusive) of the subMap.
257 >     * <p>The returned map will throw an <tt>IllegalArgumentException</tt>
258 >     * on an attempt to insert a key outside its range.
259       *
260 +     * @param fromKey low endpoint (inclusive) of the keys in the returned map
261 +     * @param toKey high endpoint (exclusive) of the keys in the returned map
262       * @return a view of the portion of this map whose keys range from
263 <     * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.
264 <     *
265 <     * @throws ClassCastException if <tt>fromKey</tt> and
266 <     * <tt>toKey</tt> cannot be compared to one another using this
267 <     * map's comparator (or, if the map has no comparator, using
268 <     * natural ordering).
269 <     * @throws IllegalArgumentException if <tt>fromKey</tt> is greater
270 <     * than <tt>toKey</tt>.
271 <     * @throws NullPointerException if <tt>fromKey</tt> or
272 <     * <tt>toKey</tt> is <tt>null</tt> and this map does not support
273 <     * <tt>null</tt> keys.
263 >     *         <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive
264 >     * @throws ClassCastException if <tt>fromKey</tt> and <tt>toKey</tt>
265 >     *         cannot be compared to one another using this map's comparator
266 >     *         (or, if the map has no comparator, using natural ordering).
267 >     *         Implementations may, but are not required to, throw this
268 >     *         exception if <tt>fromKey</tt> or <tt>toKey</tt>
269 >     *         cannot be compared to keys currently in the map.
270 >     * @throws NullPointerException if <tt>fromKey</tt> or <tt>toKey</tt>
271 >     *         is null and this map does not permit null keys
272 >     * @throws IllegalArgumentException if <tt>fromKey</tt> is greater than
273 >     *         <tt>toKey</tt>; or if this map itself has a restricted
274 >     *         range, and <tt>fromKey</tt> or <tt>toKey</tt> lies
275 >     *         outside the bounds of the range
276       */
277      NavigableMap<K,V> navigableSubMap(K fromKey, K toKey);
278  
279      /**
280 <     * Returns a view of the portion of this map whose keys are strictly less
281 <     * than <tt>toKey</tt>.  The returned navigable map is backed by this map, so
282 <     * changes in the returned navigable map are reflected in this map, and
283 <     * vice-versa.  
284 <     * @param toKey high endpoint (exclusive) of the headMap.
285 <     * @return a view of the portion of this map whose keys are strictly
286 <     *                less than <tt>toKey</tt>.
280 >     * Returns a view of the portion of this map whose keys are
281 >     * strictly less than <tt>toKey</tt>.  The returned map is backed
282 >     * by this map, so changes in the returned map are reflected in
283 >     * this map, and vice-versa.  The returned map supports all
284 >     * optional map operations that this map supports.
285 >     *
286 >     * <p>The returned map will throw an <tt>IllegalArgumentException</tt>
287 >     * on an attempt to insert a key outside its range.
288       *
289 +     * @param toKey high endpoint (exclusive) of the keys in the returned map
290 +     * @return a view of the portion of this map whose keys are strictly
291 +     *         less than <tt>toKey</tt>
292       * @throws ClassCastException if <tt>toKey</tt> is not compatible
293       *         with this map's comparator (or, if the map has no comparator,
294 <     *         if <tt>toKey</tt> does not implement <tt>Comparable</tt>).
295 <     * @throws NullPointerException if <tt>toKey</tt> is <tt>null</tt>
296 <     * and this map does not support <tt>null</tt> keys.
294 >     *         if <tt>toKey</tt> does not implement {@link Comparable}).
295 >     *         Implementations may, but are not required to, throw this
296 >     *         exception if <tt>toKey</tt> cannot be compared to keys
297 >     *         currently in the map.
298 >     * @throws NullPointerException if <tt>toKey</tt> is null
299 >     *         and this map does not permit null keys
300 >     * @throws IllegalArgumentException if this map itself has a
301 >     *         restricted range, and <tt>toKey</tt> lies outside the
302 >     *         bounds of the range
303       */
304      NavigableMap<K,V> navigableHeadMap(K toKey);
305  
306      /**
307       * Returns a view of the portion of this map whose keys are
308 <     * greater than or equal to <tt>fromKey</tt>.  The returned navigable
309 <     * map is backed by this map, so changes in the returned navigable
310 <     * map are reflected in this map, and vice-versa.
311 <     * @param fromKey low endpoint (inclusive) of the tailMap.
308 >     * greater than or equal to <tt>fromKey</tt>.  The returned map is
309 >     * backed by this map, so changes in the returned map are
310 >     * reflected in this map, and vice-versa.  The returned map
311 >     * supports all optional map operations that this map supports.
312 >     *
313 >     * <p>The returned map will throw an <tt>IllegalArgumentException</tt>
314 >     * on an attempt to insert a key outside its range.
315 >     *
316 >     * @param fromKey low endpoint (inclusive) of the keys in the returned map
317       * @return a view of the portion of this map whose keys are greater
318 <     *                than or equal to <tt>fromKey</tt>.
318 >     *         than or equal to <tt>fromKey</tt>
319       * @throws ClassCastException if <tt>fromKey</tt> is not compatible
320       *         with this map's comparator (or, if the map has no comparator,
321 <     *         if <tt>fromKey</tt> does not implement <tt>Comparable</tt>).
322 <     * @throws NullPointerException if <tt>fromKey</tt> is <tt>null</tt>
323 <     * and this map does not support <tt>null</tt> keys.
321 >     *         if <tt>fromKey</tt> does not implement {@link Comparable}).
322 >     *         Implementations may, but are not required to, throw this
323 >     *         exception if <tt>fromKey</tt> cannot be compared to keys
324 >     *         currently in the map.
325 >     * @throws NullPointerException if <tt>fromKey</tt> is null
326 >     *         and this map does not permit null keys
327 >     * @throws IllegalArgumentException if this map itself has a
328 >     *         restricted range, and <tt>fromKey</tt> lies outside the
329 >     *         bounds of the range
330       */
331 <    NavigableMap<K,V>  navigableTailMap(K fromKey);
331 >    NavigableMap<K,V> navigableTailMap(K fromKey);
332   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines