[cvs] / jsr166 / src / main / java / util / NavigableMap.java Repository:
ViewVC logotype

Annotation of /jsr166/src/main/java/util/NavigableMap.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download)

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 :     * subrannge traversals in either direction using <tt>SubMap</tt>.
29 :     *
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 :     public 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 :     public 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.
88 :     */
89 :     public Map.Entry<K,V> lowerEntry(K key);
90 :    
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 :     public K lowerKey(K key);
104 :    
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 :     public Map.Entry<K,V> floorEntry(K key);
119 :    
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 :     public K floorKey(K key);
134 :    
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 :     public Map.Entry<K,V> higherEntry(K key);
149 :    
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 :     public K higherKey(K key);
163 :    
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 :     public Map.Entry<K,V> firstEntry();
172 :    
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 :     public Map.Entry<K,V> lastEntry();
181 :    
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 :     public Map.Entry<K,V> pollFirstEntry();
190 :    
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 :     public Map.Entry<K,V> pollLastEntry();
199 :    
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 :     * <tt>fromKey</tt> and <tt>toKey</tt> are equal, the returned sorted map
241 :     * is empty.) The returned sorted map is backed by this map, so changes
242 :     * in the returned sorted map are reflected in this map, and vice-versa.
243 :    
244 :     * @param fromKey low endpoint (inclusive) of the subMap.
245 :     * @param toKey high endpoint (exclusive) of the subMap.
246 :     *
247 :     * @return a view of the portion of this map whose keys range from
248 :     * <tt>fromKey</tt>, inclusive, to <tt>toKey</tt>, exclusive.
249 :     *
250 :     * @throws ClassCastException if <tt>fromKey</tt> and
251 :     * <tt>toKey</tt> cannot be compared to one another using this
252 :     * map's comparator (or, if the map has no comparator, using
253 :     * natural ordering).
254 :     * @throws IllegalArgumentException if <tt>fromKey</tt> is greater
255 :     * than <tt>toKey</tt>.
256 :     * @throws NullPointerException if <tt>fromKey</tt> or
257 :     * <tt>toKey</tt> is <tt>null</tt> and this map does not support
258 :     * <tt>null</tt> keys.
259 :     */
260 :     public NavigableMap<K,V> subMap(K fromKey, K toKey);
261 :    
262 :     /**
263 :     * Returns a view of the portion of this map whose keys are strictly less
264 :     * than <tt>toKey</tt>. The returned sorted map is backed by this map, so
265 :     * changes in the returned sorted map are reflected in this map, and
266 :     * vice-versa.
267 :     * @param toKey high endpoint (exclusive) of the headMap.
268 :     * @return a view of the portion of this map whose keys are strictly
269 :     * less than <tt>toKey</tt>.
270 :     *
271 :     * @throws ClassCastException if <tt>toKey</tt> is not compatible
272 :     * with this map's comparator (or, if the map has no comparator,
273 :     * if <tt>toKey</tt> does not implement <tt>Comparable</tt>).
274 :     * @throws NullPointerException if <tt>toKey</tt> is <tt>null</tt>
275 :     * and this map does not support <tt>null</tt> keys.
276 :     */
277 :     public NavigableMap<K,V> headMap(K toKey);
278 :    
279 :     /**
280 :     * Returns a view of the portion of this map whose keys are
281 :     * greater than or equal to <tt>fromKey</tt>. The returned sorted
282 :     * map is backed by this map, so changes in the returned sorted
283 :     * map are reflected in this map, and vice-versa.
284 :     * @param fromKey low endpoint (inclusive) of the tailMap.
285 :     * @return a view of the portion of this map whose keys are greater
286 :     * than or equal to <tt>fromKey</tt>.
287 :     * @throws ClassCastException if <tt>fromKey</tt> is not compatible
288 :     * with this map's comparator (or, if the map has no comparator,
289 :     * if <tt>fromKey</tt> does not implement <tt>Comparable</tt>).
290 :     * @throws NullPointerException if <tt>fromKey</tt> is <tt>null</tt>
291 :     * and this map does not support <tt>null</tt> keys.
292 :     */
293 :     public NavigableMap<K,V> tailMap(K fromKey);
294 :     }

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8