ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableSet.java
Revision: 1.12
Committed: Wed Jul 20 02:18:52 2005 UTC (18 years, 10 months ago) by jsr166
Branch: MAIN
Changes since 1.11: +3 -4 lines
Log Message:
doc fixes

File Contents

# Content
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 import java.util.*; // for javadoc (till 6280605 is fixed)
9
10 /**
11 * A {@link SortedSet} extended with navigation methods reporting
12 * closest matches for given search targets. Methods <tt>lower</tt>,
13 * <tt>floor</tt>, <tt>ceiling</tt>, and <tt>higher</tt> return elements
14 * respectively less than, less than or equal, greater than or equal,
15 * and greater than a given element, returning <tt>null</tt> if there is
16 * no such element. A <tt>NavigableSet</tt> may be viewed and traversed
17 * in either ascending or descending order. The <tt>Collection</tt>
18 * <tt>iterator</tt> method returns an ascending <tt>Iterator</tt> and
19 * the additional method <tt>descendingIterator</tt> returns a
20 * descending iterator. The performance of ascending traversals is
21 * likely to be faster than descending traversals. This interface
22 * additionally defines methods <tt>pollFirst</tt> and
23 * <tt>pollLast</tt> that return and remove the lowest and highest
24 * element, if one exists, else returning <tt>null</tt>.
25 * Methods <tt>navigableSubSet</tt>, <tt>navigableHeadSet</tt>, and
26 * <tt>navigableTailSet</tt> differ from the similarly named
27 * <tt>SortedSet</tt> methods only in their declared return types.
28 * Subsets of any <tt>NavigableSet</tt> must implement the
29 * <tt>NavigableSet</tt> interface.
30 *
31 * <p> The return values of navigation methods may be ambiguous in
32 * implementations that permit <tt>null</tt> elements. However, even
33 * in this case the result can be disambiguated by checking
34 * <tt>contains(null)</tt>. To avoid such issues, implementations of
35 * this interface are encouraged to <em>not</em> permit insertion of
36 * <tt>null</tt> elements. (Note that sorted sets of {@link
37 * Comparable} elements intrinsically do not permit <tt>null</tt>.)
38 *
39 * <p>This interface is a member of the
40 * <a href="{@docRoot}/../guide/collections/index.html">
41 * Java Collections Framework</a>.
42 *
43 * @author Doug Lea
44 * @param <E> the type of elements maintained by this set
45 * @since 1.6
46 */
47 public interface NavigableSet<E> extends SortedSet<E> {
48 /**
49 * Returns the greatest element in this set strictly less than the
50 * given element, or <tt>null</tt> if there is no such element.
51 *
52 * @param e the value to match
53 * @return the greatest element less than <tt>e</tt>,
54 * or <tt>null</tt> if there is no such element
55 * @throws ClassCastException if the specified element cannot be
56 * compared with the elements currently in the set
57 * @throws NullPointerException if the specified element is null
58 * and this set does not permit null elements
59 */
60 E lower(E e);
61
62 /**
63 * Returns the greatest element in this set less than or equal to
64 * the given element, or <tt>null</tt> if there is no such element.
65 *
66 * @param e the value to match
67 * @return the greatest element less than or equal to <tt>e</tt>,
68 * or <tt>null</tt> if there is no such element
69 * @throws ClassCastException if the specified element cannot be
70 * compared with the elements currently in the set
71 * @throws NullPointerException if the specified element is null
72 * and this set does not permit null elements
73 */
74 E floor(E e);
75
76 /**
77 * Returns the least element in this set greater than or equal to
78 * the given element, or <tt>null</tt> if there is no such element.
79 *
80 * @param e the value to match
81 * @return the least element greater than or equal to <tt>e</tt>,
82 * or <tt>null</tt> if there is no such element
83 * @throws ClassCastException if the specified element cannot be
84 * compared with the elements currently in the set
85 * @throws NullPointerException if the specified element is null
86 * and this set does not permit null elements
87 */
88 E ceiling(E e);
89
90 /**
91 * Returns the least element in this set strictly greater than the
92 * given element, or <tt>null</tt> if there is no such element.
93 *
94 * @param e the value to match
95 * @return the least element greater than <tt>e</tt>,
96 * or <tt>null</tt> if there is no such element
97 * @throws ClassCastException if the specified element cannot be
98 * compared with the elements currently in the set
99 * @throws NullPointerException if the specified element is null
100 * and this set does not permit null elements
101 */
102 E higher(E e);
103
104 /**
105 * Retrieves and removes the first (lowest) element.
106 *
107 * @return the first element, or <tt>null</tt> if this set is empty
108 */
109 E pollFirst();
110
111 /**
112 * Retrieves and removes the last (highest) element.
113 *
114 * @return the last element, or <tt>null</tt> if this set is empty
115 */
116 E pollLast();
117
118 /**
119 * Returns an iterator over the elements in this set, in ascending order.
120 *
121 * @return an iterator over the elements in this set, in ascending order
122 */
123 Iterator<E> iterator();
124
125 /**
126 * Returns an iterator over the elements in this set, in descending order.
127 *
128 * @return an iterator over the elements in this set, in descending order
129 */
130 Iterator<E> descendingIterator();
131
132 /**
133 * Returns a view of the portion of this set whose elements range
134 * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
135 * exclusive. (If <tt>fromElement</tt> and <tt>toElement</tt> are
136 * equal, the returned set is empty.) The returned set is backed
137 * by this set, so changes in the returned set are reflected in
138 * this set, and vice-versa. The returned set supports all
139 * optional set operations that this set supports.
140 *
141 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
142 * on an attempt to insert an element outside its range.
143 *
144 * @param fromElement low endpoint (inclusive) of the returned set
145 * @param toElement high endpoint (exclusive) of the returned set
146 * @return a view of the portion of this set whose elements range from
147 * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
148 * @throws ClassCastException if <tt>fromElement</tt> and
149 * <tt>toElement</tt> cannot be compared to one another using this
150 * set's comparator (or, if the set has no comparator, using
151 * natural ordering). Implementations may, but are not required
152 * to, throw this exception if <tt>fromElement</tt> or
153 * <tt>toElement</tt> cannot be compared to elements currently in
154 * the set.
155 * @throws NullPointerException if <tt>fromElement</tt> or
156 * <tt>toElement</tt> is null and this set does
157 * not permit null elements
158 * @throws IllegalArgumentException if <tt>fromElement</tt> is
159 * greater than <tt>toElement</tt>; or if this set itself
160 * has a restricted range, and <tt>fromElement</tt> or
161 * <tt>toElement</tt> lies outside the bounds of the range.
162 */
163 NavigableSet<E> navigableSubSet(E fromElement, E toElement);
164
165 /**
166 * Returns a view of the portion of this set whose elements are
167 * strictly less than <tt>toElement</tt>. The returned set is
168 * backed by this set, so changes in the returned set are
169 * reflected in this set, and vice-versa. The returned set
170 * supports all optional set operations that this set supports.
171 *
172 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
173 * on an attempt to insert an element outside its range.
174 *
175 * @param toElement high endpoint (exclusive) of the returned set
176 * @return a view of the portion of this set whose elements are strictly
177 * less than <tt>toElement</tt>
178 * @throws ClassCastException if <tt>toElement</tt> is not compatible
179 * with this set's comparator (or, if the set has no comparator,
180 * if <tt>toElement</tt> does not implement {@link Comparable}).
181 * Implementations may, but are not required to, throw this
182 * exception if <tt>toElement</tt> cannot be compared to elements
183 * currently in the set.
184 * @throws NullPointerException if <tt>toElement</tt> is null and
185 * this set does not permit null elements
186 * @throws IllegalArgumentException if this set itself has a
187 * restricted range, and <tt>toElement</tt> lies outside the
188 * bounds of the range
189 */
190 NavigableSet<E> navigableHeadSet(E toElement);
191
192 /**
193 * Returns a view of the portion of this set whose elements are
194 * greater than or equal to <tt>fromElement</tt>. The returned
195 * set is backed by this set, so changes in the returned set are
196 * reflected in this set, and vice-versa. The returned set
197 * supports all optional set operations that this set supports.
198 *
199 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
200 * on an attempt to insert an element outside its range.
201 *
202 * @param fromElement low endpoint (inclusive) of the returned set
203 * @return a view of the portion of this set whose elements are greater
204 * than or equal to <tt>fromElement</tt>
205 * @throws ClassCastException if <tt>fromElement</tt> is not compatible
206 * with this set's comparator (or, if the set has no comparator,
207 * if <tt>fromElement</tt> does not implement {@link Comparable}).
208 * Implementations may, but are not required to, throw this
209 * exception if <tt>fromElement</tt> cannot be compared to elements
210 * currently in the set.
211 * @throws NullPointerException if <tt>fromElement</tt> is null
212 * and this set does not permit null elements
213 * @throws IllegalArgumentException if this set itself has a
214 * restricted range, and <tt>fromElement</tt> lies outside the
215 * bounds of the range
216 */
217 NavigableSet<E> navigableTailSet(E fromElement);
218 }