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.6 by jsr166, Mon May 2 22:34:56 2005 UTC vs.
Revision 1.11 by jsr166, Wed Jul 20 02:18:52 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines