ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166x/NavigableMap.java
Revision: 1.11
Committed: Wed Jan 16 00:51:11 2013 UTC (11 years, 3 months ago) by jsr166
Branch: MAIN
Changes since 1.10: +91 -91 lines
Log Message:
<tt> -> {@code

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 jsr166 1.6 * http://creativecommons.org/publicdomain/zero/1.0/
5 dl 1.1 */
6    
7     package jsr166x;
8    
9     import java.util.*;
10    
11     /**
12 dl 1.4 * A {@link SortedMap} extended with navigation methods returning the
13     * closest matches for given search targets. Methods
14 jsr166 1.11 * {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry},
15     * and {@code higherEntry} return {@code Map.Entry} objects
16 dl 1.4 * associated with keys respectively less than, less than or equal,
17     * greater than or equal, and greater than a given key, returning
18 jsr166 1.11 * {@code null} if there is no such key. Similarly, methods
19     * {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and
20     * {@code higherKey} return only the associated keys. All of these
21 dl 1.4 * methods are designed for locating, not traversing entries.
22 dl 1.3 *
23 jsr166 1.11 * <p>A {@code NavigableMap} may be viewed and traversed in either
24     * ascending or descending key order. The {@code Map} methods
25     * {@code keySet} and {@code entrySet} return ascending views, and
26     * the additional methods {@code descendingKeySet} and
27     * {@code descendingEntrySet} return descending views. The
28 dl 1.3 * performance of ascending traversals is likely to be faster than
29     * descending traversals. Notice that it is possible to perform
30 jsr166 1.11 * subrannge traversals in either direction using {@code SubMap}.
31 jsr166 1.5 *
32 jsr166 1.11 * <p>This interface additionally defines methods {@code firstEntry},
33     * {@code pollFirstEntry}, {@code lastEntry}, and
34     * {@code pollLastEntry} that return and/or remove the least and
35     * greatest mappings, if any exist, else returning {@code null}.
36 dl 1.1 *
37 jsr166 1.9 * <p>Implementations of entry-returning methods are expected to
38 jsr166 1.11 * return {@code Map.Entry} pairs representing snapshots of mappings
39 dl 1.3 * at the time they were produced, and thus generally do <em>not</em>
40 jsr166 1.11 * support the optional {@code Entry.setValue} method. Note however
41 dl 1.3 * that it is possible to change mappings in the associated map using
42 jsr166 1.11 * method {@code put}.
43 dl 1.1 *
44     * @author Doug Lea
45     * @param <K> the type of keys maintained by this map
46 jsr166 1.5 * @param <V> the type of mapped values
47 dl 1.1 */
48     public interface NavigableMap<K,V> extends SortedMap<K,V> {
49     /**
50     * Returns a key-value mapping associated with the least key
51 jsr166 1.11 * greater than or equal to the given key, or {@code null} if there is
52 jsr166 1.5 * no such entry.
53     *
54 jsr166 1.10 * @param key the key
55 jsr166 1.11 * @return an Entry associated with ceiling of given key, or {@code null}
56 jsr166 1.10 * if there is no such Entry
57 dl 1.1 * @throws ClassCastException if key cannot be compared with the keys
58 jsr166 1.10 * currently in the map
59 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
60     * does not support {@code null} keys
61 dl 1.1 */
62     public Map.Entry<K,V> ceilingEntry(K key);
63    
64     /**
65 dl 1.3 * Returns least key greater than or equal to the given key, or
66 jsr166 1.11 * {@code null} if there is no such key.
67 jsr166 1.5 *
68 jsr166 1.10 * @param key the key
69 jsr166 1.11 * @return the ceiling key, or {@code null}
70 jsr166 1.10 * if there is no such key
71 dl 1.3 * @throws ClassCastException if key cannot be compared with the keys
72 jsr166 1.10 * currently in the map
73 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
74     * does not support {@code null} keys
75 dl 1.3 */
76     public K ceilingKey(K key);
77    
78     /**
79 dl 1.1 * Returns a key-value mapping associated with the greatest
80 jsr166 1.11 * key strictly less than the given key, or {@code null} if there is no
81 jsr166 1.5 * such entry.
82     *
83 jsr166 1.10 * @param key the key
84 dl 1.1 * @return an Entry with greatest key less than the given
85 jsr166 1.11 * key, or {@code null} if there is no such Entry
86 dl 1.1 * @throws ClassCastException if key cannot be compared with the keys
87 jsr166 1.10 * currently in the map
88 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
89     * does not support {@code null} keys
90 dl 1.1 */
91     public Map.Entry<K,V> lowerEntry(K key);
92    
93     /**
94 dl 1.3 * Returns the greatest key strictly less than the given key, or
95 jsr166 1.11 * {@code null} if there is no such key.
96 jsr166 1.5 *
97 jsr166 1.10 * @param key the key
98 dl 1.3 * @return the greatest key less than the given
99 jsr166 1.11 * key, or {@code null} if there is no such key
100 dl 1.3 * @throws ClassCastException if key cannot be compared with the keys
101 jsr166 1.10 * currently in the map
102 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
103     * does not support {@code null} keys
104 dl 1.3 */
105     public K lowerKey(K key);
106    
107     /**
108     * Returns a key-value mapping associated with the greatest key
109 jsr166 1.11 * less than or equal to the given key, or {@code null} if there
110 dl 1.3 * is no such entry.
111 jsr166 1.5 *
112 jsr166 1.10 * @param key the key
113 jsr166 1.11 * @return an Entry associated with floor of given key, or {@code null}
114 jsr166 1.10 * if there is no such Entry
115 dl 1.1 * @throws ClassCastException if key cannot be compared with the keys
116 jsr166 1.10 * currently in the map
117 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
118     * does not support {@code null} keys
119 dl 1.1 */
120     public Map.Entry<K,V> floorEntry(K key);
121    
122     /**
123 dl 1.3 * Returns the greatest key
124 jsr166 1.11 * less than or equal to the given key, or {@code null} if there
125 dl 1.3 * is no such key.
126 jsr166 1.5 *
127 jsr166 1.10 * @param key the key
128 jsr166 1.11 * @return the floor of given key, or {@code null} if there is no
129 jsr166 1.10 * such key
130 dl 1.3 * @throws ClassCastException if key cannot be compared with the keys
131 jsr166 1.10 * currently in the map
132 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
133     * does not support {@code null} keys
134 dl 1.3 */
135     public K floorKey(K key);
136    
137     /**
138     * Returns a key-value mapping associated with the least key
139 jsr166 1.11 * strictly greater than the given key, or {@code null} if there
140 dl 1.3 * is no such entry.
141 jsr166 1.5 *
142 jsr166 1.10 * @param key the key
143 dl 1.1 * @return an Entry with least key greater than the given key, or
144 jsr166 1.11 * {@code null} if there is no such Entry
145 dl 1.1 * @throws ClassCastException if key cannot be compared with the keys
146 jsr166 1.10 * currently in the map
147 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
148     * does not support {@code null} keys
149 dl 1.1 */
150     public Map.Entry<K,V> higherEntry(K key);
151    
152     /**
153 dl 1.3 * Returns the least key strictly greater than the given key, or
154 jsr166 1.11 * {@code null} if there is no such key.
155 jsr166 1.5 *
156 jsr166 1.10 * @param key the key
157 dl 1.3 * @return the least key greater than the given key, or
158 jsr166 1.11 * {@code null} if there is no such key
159 dl 1.3 * @throws ClassCastException if key cannot be compared with the keys
160 jsr166 1.10 * currently in the map
161 jsr166 1.11 * @throws NullPointerException if key is {@code null} and this map
162     * does not support {@code null} keys
163 dl 1.3 */
164     public K higherKey(K key);
165    
166     /**
167 dl 1.1 * Returns a key-value mapping associated with the least
168 jsr166 1.11 * key in this map, or {@code null} if the map is empty.
169 jsr166 1.5 *
170 jsr166 1.11 * @return an Entry with least key, or {@code null}
171 jsr166 1.10 * if the map is empty
172 dl 1.1 */
173     public Map.Entry<K,V> firstEntry();
174    
175     /**
176     * Returns a key-value mapping associated with the greatest
177 jsr166 1.11 * key in this map, or {@code null} if the map is empty.
178 jsr166 1.5 *
179 jsr166 1.11 * @return an Entry with greatest key, or {@code null}
180 jsr166 1.10 * if the map is empty
181 dl 1.1 */
182     public Map.Entry<K,V> lastEntry();
183    
184     /**
185     * Removes and returns a key-value mapping associated with
186 jsr166 1.11 * the least key in this map, or {@code null} if the map is empty.
187 jsr166 1.5 *
188 jsr166 1.11 * @return the removed first entry of this map, or {@code null}
189 jsr166 1.10 * if the map is empty
190 dl 1.1 */
191     public Map.Entry<K,V> pollFirstEntry();
192    
193     /**
194     * Removes and returns a key-value mapping associated with
195 jsr166 1.11 * the greatest key in this map, or {@code null} if the map is empty.
196 jsr166 1.5 *
197 jsr166 1.11 * @return the removed last entry of this map, or {@code null}
198 jsr166 1.10 * if the map is empty
199 dl 1.1 */
200     public Map.Entry<K,V> pollLastEntry();
201    
202     /**
203 dl 1.3 * Returns a set view of the keys contained in this map, in
204     * descending key order. The set is backed by the map, so changes
205     * to the map are reflected in the set, and vice-versa. If the
206     * map is modified while an iteration over the set is in progress
207 jsr166 1.11 * (except through the iterator's own {@code remove} operation),
208 dl 1.3 * the results of the iteration are undefined. The set supports
209     * element removal, which removes the corresponding mapping from
210 jsr166 1.11 * the map, via the {@code Iterator.remove}, {@code Set.remove},
211     * {@code removeAll} {@code retainAll}, and {@code clear}
212     * operations. It does not support the add or {@code addAll}
213 dl 1.3 * operations.
214     *
215 jsr166 1.10 * @return a set view of the keys contained in this map
216 dl 1.3 */
217     Set<K> descendingKeySet();
218    
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 jsr166 1.11 * {@code Map.Entry}. The set is backed by the map, so changes to
223 dl 1.3 * 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 jsr166 1.11 * (except through the iterator's own {@code remove} operation,
226     * or through the {@code setValue} operation on a map entry
227 dl 1.3 * returned by the iterator) the results of the iteration are
228     * undefined. The set supports element removal, which removes the
229     * corresponding mapping from the map, via the
230 jsr166 1.11 * {@code Iterator.remove}, {@code Set.remove},
231     * {@code removeAll}, {@code retainAll} and {@code clear}
232     * operations. It does not support the {@code add} or
233     * {@code addAll} operations.
234 dl 1.3 *
235 jsr166 1.10 * @return a set view of the mappings contained in this map
236 dl 1.3 */
237     Set<Map.Entry<K, V>> descendingEntrySet();
238    
239     /**
240 dl 1.1 * Returns a view of the portion of this map whose keys range from
241 jsr166 1.11 * {@code fromKey}, inclusive, to {@code toKey}, exclusive. (If
242     * {@code fromKey} and {@code toKey} are equal, the returned sorted map
243 dl 1.1 * 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 jsr166 1.7 *
246 jsr166 1.10 * @param fromKey low endpoint (inclusive) of the subMap
247     * @param toKey high endpoint (exclusive) of the subMap
248 dl 1.1 *
249     * @return a view of the portion of this map whose keys range from
250 jsr166 1.11 * {@code fromKey}, inclusive, to {@code toKey}, exclusive
251 dl 1.1 *
252 jsr166 1.11 * @throws ClassCastException if {@code fromKey} and
253     * {@code toKey} cannot be compared to one another using this
254 dl 1.1 * map's comparator (or, if the map has no comparator, using
255 jsr166 1.10 * natural ordering)
256 jsr166 1.11 * @throws IllegalArgumentException if {@code fromKey} is greater
257     * than {@code toKey}
258     * @throws NullPointerException if {@code fromKey} or
259     * {@code toKey} is {@code null} and this map does not support
260     * {@code null} keys
261 dl 1.1 */
262     public NavigableMap<K,V> subMap(K fromKey, K toKey);
263    
264     /**
265     * Returns a view of the portion of this map whose keys are strictly less
266 jsr166 1.11 * than {@code toKey}. The returned sorted map is backed by this map, so
267 dl 1.1 * changes in the returned sorted map are reflected in this map, and
268 jsr166 1.5 * vice-versa.
269 jsr166 1.10 * @param toKey high endpoint (exclusive) of the headMap
270 dl 1.1 * @return a view of the portion of this map whose keys are strictly
271 jsr166 1.11 * less than {@code toKey}
272 dl 1.1 *
273 jsr166 1.11 * @throws ClassCastException if {@code toKey} is not compatible
274 dl 1.1 * with this map's comparator (or, if the map has no comparator,
275 jsr166 1.11 * if {@code toKey} does not implement {@code Comparable})
276     * @throws NullPointerException if {@code toKey} is {@code null}
277     * and this map does not support {@code null} keys
278 dl 1.1 */
279     public NavigableMap<K,V> headMap(K toKey);
280    
281     /**
282     * Returns a view of the portion of this map whose keys are
283 jsr166 1.11 * greater than or equal to {@code fromKey}. The returned sorted
284 dl 1.1 * map is backed by this map, so changes in the returned sorted
285     * map are reflected in this map, and vice-versa.
286 jsr166 1.10 * @param fromKey low endpoint (inclusive) of the tailMap
287 dl 1.1 * @return a view of the portion of this map whose keys are greater
288 jsr166 1.11 * than or equal to {@code fromKey}
289     * @throws ClassCastException if {@code fromKey} is not compatible
290 dl 1.1 * with this map's comparator (or, if the map has no comparator,
291 jsr166 1.11 * if {@code fromKey} does not implement {@code Comparable})
292     * @throws NullPointerException if {@code fromKey} is {@code null}
293     * and this map does not support {@code null} keys
294 dl 1.1 */
295 jsr166 1.8 public NavigableMap<K,V> tailMap(K fromKey);
296 dl 1.1 }