ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableMap.java
Revision: 1.3
Committed: Tue Mar 22 01:30:10 2005 UTC (19 years, 1 month ago) by dl
Branch: MAIN
Changes since 1.2: +27 -23 lines
Log Message:
NavigableMap.subMap -> NavigableMap.navigableSubMap, and associated changes

File Contents

# User Rev Content
1 dl 1.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 dl 1.2 * subrange traversals in either direction using <tt>SubMap</tt>.
29 dl 1.1 *
30     * <p>This interface additionally defines methods <tt>firstEntry</tt>,
31     * <tt>pollFirstEntry</tt>, <tt>lastEntry</tt>, and
32     * <tt>pollLastEntry</tt> that return and/or remove the least and
33     * greatest mappings, if any exist, else returning <tt>null</tt>.
34     *
35     * <p> Implementations of entry-returning methods are expected to
36     * return <tt>Map.Entry</tt> pairs representing snapshots of mappings
37     * at the time they were produced, and thus generally do <em>not</em>
38     * support the optional <tt>Entry.setValue</tt> method. Note however
39     * that it is possible to change mappings in the associated map using
40     * method <tt>put</tt>.
41     *
42     * @author Doug Lea
43     * @param <K> the type of keys maintained by this map
44     * @param <V> the type of mapped values
45     */
46     public interface NavigableMap<K,V> extends SortedMap<K,V> {
47     /**
48     * Returns a key-value mapping associated with the least key
49     * greater than or equal to the given key, or <tt>null</tt> if there is
50     * no such entry.
51     *
52     * @param key the key.
53     * @return an Entry associated with ceiling of given key, or <tt>null</tt>
54     * if there is no such Entry.
55     * @throws ClassCastException if key cannot be compared with the keys
56     * currently in the map.
57     * @throws NullPointerException if key is <tt>null</tt> and this map
58     * does not support <tt>null</tt> keys.
59     */
60 dl 1.3 Map.Entry<K,V> ceilingEntry(K key);
61 dl 1.1
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 dl 1.3 K ceilingKey(K key);
75 dl 1.1
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.
88     */
89 dl 1.3 Map.Entry<K,V> lowerEntry(K key);
90 dl 1.1
91     /**
92     * Returns the greatest key strictly less than the given key, or
93     * <tt>null</tt> if there is no such key.
94     *
95     * @param key the key.
96     * @return the greatest key less than the given
97     * key, or <tt>null</tt> if there is no such key.
98     * @throws ClassCastException if key cannot be compared with the keys
99     * currently in the map.
100     * @throws NullPointerException if key is <tt>null</tt> and this map
101     * does not support <tt>null</tt> keys.
102     */
103 dl 1.3 K lowerKey(K key);
104 dl 1.1
105     /**
106     * Returns a key-value mapping associated with the greatest key
107     * less than or equal to the given key, or <tt>null</tt> if there
108     * is no such entry.
109     *
110     * @param key the key.
111     * @return an Entry associated with floor of given key, or <tt>null</tt>
112     * if there is no such Entry.
113     * @throws ClassCastException if key cannot be compared with the keys
114     * currently in the map.
115     * @throws NullPointerException if key is <tt>null</tt> and this map
116     * does not support <tt>null</tt> keys.
117     */
118 dl 1.3 Map.Entry<K,V> floorEntry(K key);
119 dl 1.1
120     /**
121     * Returns the greatest key
122     * less than or equal to the given key, or <tt>null</tt> if there
123     * is no such key.
124     *
125     * @param key the key.
126     * @return the floor of given key, or <tt>null</tt> if there is no
127     * such key.
128     * @throws ClassCastException if key cannot be compared with the keys
129     * currently in the map.
130     * @throws NullPointerException if key is <tt>null</tt> and this map
131     * does not support <tt>null</tt> keys.
132     */
133 dl 1.3 K floorKey(K key);
134 dl 1.1
135     /**
136     * Returns a key-value mapping associated with the least key
137     * strictly greater than the given key, or <tt>null</tt> if there
138     * is no such entry.
139     *
140     * @param key the key.
141     * @return an Entry with least key greater than the given key, or
142     * <tt>null</tt> if there is no such Entry.
143     * @throws ClassCastException if key cannot be compared with the keys
144     * currently in the map.
145     * @throws NullPointerException if key is <tt>null</tt> and this map
146     * does not support <tt>null</tt> keys.
147     */
148 dl 1.3 Map.Entry<K,V> higherEntry(K key);
149 dl 1.1
150     /**
151     * Returns the least key strictly greater than the given key, or
152     * <tt>null</tt> if there is no such key.
153     *
154     * @param key the key.
155     * @return the least key greater than the given key, or
156     * <tt>null</tt> if there is no such key.
157     * @throws ClassCastException if key cannot be compared with the keys
158     * currently in the map.
159     * @throws NullPointerException if key is <tt>null</tt> and this map
160     * does not support <tt>null</tt> keys.
161     */
162 dl 1.3 K higherKey(K key);
163 dl 1.1
164     /**
165     * Returns a key-value mapping associated with the least
166     * key in this map, or <tt>null</tt> if the map is empty.
167     *
168     * @return an Entry with least key, or <tt>null</tt>
169     * if the map is empty.
170     */
171 dl 1.3 Map.Entry<K,V> firstEntry();
172 dl 1.1
173     /**
174     * Returns a key-value mapping associated with the greatest
175     * key in this map, or <tt>null</tt> if the map is empty.
176     *
177     * @return an Entry with greatest key, or <tt>null</tt>
178     * if the map is empty.
179     */
180 dl 1.3 Map.Entry<K,V> lastEntry();
181 dl 1.1
182     /**
183     * Removes and returns a key-value mapping associated with
184     * the least key in this map, or <tt>null</tt> if the map is empty.
185     *
186     * @return the removed first entry of this map, or <tt>null</tt>
187     * if the map is empty.
188     */
189 dl 1.3 Map.Entry<K,V> pollFirstEntry();
190 dl 1.1
191     /**
192     * Removes and returns a key-value mapping associated with
193     * the greatest key in this map, or <tt>null</tt> if the map is empty.
194     *
195     * @return the removed last entry of this map, or <tt>null</tt>
196     * if the map is empty.
197     */
198 dl 1.3 Map.Entry<K,V> pollLastEntry();
199 dl 1.1
200     /**
201     * Returns a set view of the keys contained in this map, in
202     * descending key order. The set is backed by the map, so changes
203     * to the map are reflected in the set, and vice-versa. If the
204     * map is modified while an iteration over the set is in progress
205     * (except through the iterator's own <tt>remove</tt> operation),
206     * the results of the iteration are undefined. The set supports
207     * element removal, which removes the corresponding mapping from
208     * the map, via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
209     * <tt>removeAll</tt> <tt>retainAll</tt>, and <tt>clear</tt>
210     * operations. It does not support the add or <tt>addAll</tt>
211     * operations.
212     *
213     * @return a set view of the keys contained in this map.
214     */
215     Set<K> descendingKeySet();
216    
217     /**
218     * Returns a set view of the mappings contained in this map, in
219     * descending key order. Each element in the returned set is a
220     * <tt>Map.Entry</tt>. The set is backed by the map, so changes to
221     * the map are reflected in the set, and vice-versa. If the map
222     * is modified while an iteration over the set is in progress
223     * (except through the iterator's own <tt>remove</tt> operation,
224     * or through the <tt>setValue</tt> operation on a map entry
225     * returned by the iterator) the results of the iteration are
226     * undefined. The set supports element removal, which removes the
227     * corresponding mapping from the map, via the
228     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
229     * <tt>removeAll</tt>, <tt>retainAll</tt> and <tt>clear</tt>
230     * operations. It does not support the <tt>add</tt> or
231     * <tt>addAll</tt> operations.
232     *
233     * @return a set view of the mappings contained in this map.
234     */
235     Set<Map.Entry<K, V>> descendingEntrySet();
236    
237     /**
238     * Returns a view of the portion of this map whose keys range from
239     * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive. (If
240 dl 1.3 * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned
241     * navigable map is empty.) The returned navigable map is backed
242     * by this map, so changes in the returned navigable map are
243     * reflected in this map, and vice-versa. Note: This
244     * method differs from <tt>SortedMap.subMap</tt> only
245     * in that the returned map is guaranteed to support the
246     * <tt>NavigableMap</tt> interface.
247     *
248 dl 1.1 * @param fromKey low endpoint (inclusive) of the subMap.
249     * @param toKey high endpoint (exclusive) of the subMap.
250     *
251     * @return a view of the portion of this map whose keys range from
252     * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.
253     *
254     * @throws ClassCastException if <tt>fromKey</tt> and
255     * <tt>toKey</tt> cannot be compared to one another using this
256     * map's comparator (or, if the map has no comparator, using
257     * natural ordering).
258     * @throws IllegalArgumentException if <tt>fromKey</tt> is greater
259     * than <tt>toKey</tt>.
260     * @throws NullPointerException if <tt>fromKey</tt> or
261     * <tt>toKey</tt> is <tt>null</tt> and this map does not support
262     * <tt>null</tt> keys.
263     */
264 dl 1.3 NavigableMap<K,V> navigableSubMap(K fromKey, K toKey);
265 dl 1.1
266     /**
267     * Returns a view of the portion of this map whose keys are strictly less
268 dl 1.3 * than <tt>toKey</tt>. The returned navigable map is backed by this map, so
269     * changes in the returned navigable map are reflected in this map, and
270 dl 1.1 * vice-versa.
271     * @param toKey high endpoint (exclusive) of the headMap.
272     * @return a view of the portion of this map whose keys are strictly
273     * less than <tt>toKey</tt>.
274     *
275     * @throws ClassCastException if <tt>toKey</tt> is not compatible
276     * with this map's comparator (or, if the map has no comparator,
277     * if <tt>toKey</tt> does not implement <tt>Comparable</tt>).
278     * @throws NullPointerException if <tt>toKey</tt> is <tt>null</tt>
279     * and this map does not support <tt>null</tt> keys.
280     */
281 dl 1.3 NavigableMap<K,V> navigableHeadMap(K toKey);
282 dl 1.1
283     /**
284     * Returns a view of the portion of this map whose keys are
285 dl 1.3 * greater than or equal to <tt>fromKey</tt>. The returned navigable
286     * map is backed by this map, so changes in the returned navigable
287 dl 1.1 * map are reflected in this map, and vice-versa.
288     * @param fromKey low endpoint (inclusive) of the tailMap.
289     * @return a view of the portion of this map whose keys are greater
290     * than or equal to <tt>fromKey</tt>.
291     * @throws ClassCastException if <tt>fromKey</tt> is not compatible
292     * with this map's comparator (or, if the map has no comparator,
293     * if <tt>fromKey</tt> does not implement <tt>Comparable</tt>).
294     * @throws NullPointerException if <tt>fromKey</tt> is <tt>null</tt>
295     * and this map does not support <tt>null</tt> keys.
296     */
297 dl 1.3 NavigableMap<K,V> navigableTailMap(K fromKey);
298 dl 1.1 }