ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableSet.java
Revision: 1.13
Committed: Thu Aug 11 08:54:39 2005 UTC (18 years, 9 months ago) by jsr166
Branch: MAIN
Changes since 1.12: +4 -2 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 * or returns <tt>null</tt> if this set is empty.
107 *
108 * @return the first element, or <tt>null</tt> if this set is empty
109 */
110 E pollFirst();
111
112 /**
113 * Retrieves and removes the last (highest) element,
114 * or returns <tt>null</tt> if this set is empty.
115 *
116 * @return the last element, or <tt>null</tt> if this set is empty
117 */
118 E pollLast();
119
120 /**
121 * Returns an iterator over the elements in this set, in ascending order.
122 *
123 * @return an iterator over the elements in this set, in ascending order
124 */
125 Iterator<E> iterator();
126
127 /**
128 * Returns an iterator over the elements in this set, in descending order.
129 *
130 * @return an iterator over the elements in this set, in descending order
131 */
132 Iterator<E> descendingIterator();
133
134 /**
135 * Returns a view of the portion of this set whose elements range
136 * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
137 * exclusive. (If <tt>fromElement</tt> and <tt>toElement</tt> are
138 * equal, the returned set is empty.) The returned set is backed
139 * by this set, so changes in the returned set are reflected in
140 * this set, and vice-versa. The returned set supports all
141 * optional set operations that this set supports.
142 *
143 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
144 * on an attempt to insert an element outside its range.
145 *
146 * @param fromElement low endpoint (inclusive) of the returned set
147 * @param toElement high endpoint (exclusive) of the returned set
148 * @return a view of the portion of this set whose elements range from
149 * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
150 * @throws ClassCastException if <tt>fromElement</tt> and
151 * <tt>toElement</tt> cannot be compared to one another using this
152 * set's comparator (or, if the set has no comparator, using
153 * natural ordering). Implementations may, but are not required
154 * to, throw this exception if <tt>fromElement</tt> or
155 * <tt>toElement</tt> cannot be compared to elements currently in
156 * the set.
157 * @throws NullPointerException if <tt>fromElement</tt> or
158 * <tt>toElement</tt> is null and this set does
159 * not permit null elements
160 * @throws IllegalArgumentException if <tt>fromElement</tt> is
161 * greater than <tt>toElement</tt>; or if this set itself
162 * has a restricted range, and <tt>fromElement</tt> or
163 * <tt>toElement</tt> lies outside the bounds of the range.
164 */
165 NavigableSet<E> navigableSubSet(E fromElement, E toElement);
166
167 /**
168 * Returns a view of the portion of this set whose elements are
169 * strictly less than <tt>toElement</tt>. The returned set is
170 * backed by this set, so changes in the returned set are
171 * reflected in this set, and vice-versa. The returned set
172 * supports all optional set operations that this set supports.
173 *
174 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
175 * on an attempt to insert an element outside its range.
176 *
177 * @param toElement high endpoint (exclusive) of the returned set
178 * @return a view of the portion of this set whose elements are strictly
179 * less than <tt>toElement</tt>
180 * @throws ClassCastException if <tt>toElement</tt> is not compatible
181 * with this set's comparator (or, if the set has no comparator,
182 * if <tt>toElement</tt> does not implement {@link Comparable}).
183 * Implementations may, but are not required to, throw this
184 * exception if <tt>toElement</tt> cannot be compared to elements
185 * currently in the set.
186 * @throws NullPointerException if <tt>toElement</tt> is null and
187 * this set does not permit null elements
188 * @throws IllegalArgumentException if this set itself has a
189 * restricted range, and <tt>toElement</tt> lies outside the
190 * bounds of the range
191 */
192 NavigableSet<E> navigableHeadSet(E toElement);
193
194 /**
195 * Returns a view of the portion of this set whose elements are
196 * greater than or equal to <tt>fromElement</tt>. The returned
197 * set is backed by this set, so changes in the returned set are
198 * reflected in this set, and vice-versa. The returned set
199 * supports all optional set operations that this set supports.
200 *
201 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
202 * on an attempt to insert an element outside its range.
203 *
204 * @param fromElement low endpoint (inclusive) of the returned set
205 * @return a view of the portion of this set whose elements are greater
206 * than or equal to <tt>fromElement</tt>
207 * @throws ClassCastException if <tt>fromElement</tt> is not compatible
208 * with this set's comparator (or, if the set has no comparator,
209 * if <tt>fromElement</tt> does not implement {@link Comparable}).
210 * Implementations may, but are not required to, throw this
211 * exception if <tt>fromElement</tt> cannot be compared to elements
212 * currently in the set.
213 * @throws NullPointerException if <tt>fromElement</tt> is null
214 * and this set does not permit null elements
215 * @throws IllegalArgumentException if this set itself has a
216 * restricted range, and <tt>fromElement</tt> lies outside the
217 * bounds of the range
218 */
219 NavigableSet<E> navigableTailSet(E fromElement);
220 }