ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableSet.java
Revision: 1.10
Committed: Tue May 17 07:29:01 2005 UTC (19 years ago) by jsr166
Branch: MAIN
Changes since 1.9: +9 -3 lines
Log Message:
doc fixes

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