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

# 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 jsr166 1.12 import java.util.*; // for javadoc (till 6280605 is fixed)
9 dl 1.1
10     /**
11     * A {@link SortedSet} extended with navigation methods reporting
12     * closest matches for given search targets. Methods <tt>lower</tt>,
13 jsr166 1.9 * <tt>floor</tt>, <tt>ceiling</tt>, and <tt>higher</tt> return elements
14 dl 1.1 * respectively less than, less than or equal, greater than or equal,
15 jsr166 1.9 * 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 dl 1.1 * in either ascending or descending order. The <tt>Collection</tt>
18     * <tt>iterator</tt> method returns an ascending <tt>Iterator</tt> and
19 jsr166 1.9 * the additional method <tt>descendingIterator</tt> returns a
20 dl 1.1 * 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 jsr166 1.9 * <tt>pollLast</tt> that return and remove the lowest and highest
24     * element, if one exists, else returning <tt>null</tt>.
25 dl 1.4 * Methods <tt>navigableSubSet</tt>, <tt>navigableHeadSet</tt>, and
26     * <tt>navigableTailSet</tt> differ from the similarly named
27 dl 1.11 * <tt>SortedSet</tt> methods only in their declared return types.
28 jsr166 1.12 * Subsets of any <tt>NavigableSet</tt> must implement the
29     * <tt>NavigableSet</tt> interface.
30 dl 1.1 *
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 jsr166 1.9 * this interface are encouraged to <em>not</em> permit insertion of
36 dl 1.1 * <tt>null</tt> elements. (Note that sorted sets of {@link
37     * Comparable} elements intrinsically do not permit <tt>null</tt>.)
38     *
39 jsr166 1.8 * <p>This interface is a member of the
40     * <a href="{@docRoot}/../guide/collections/index.html">
41     * Java Collections Framework</a>.
42     *
43 dl 1.1 * @author Doug Lea
44     * @param <E> the type of elements maintained by this set
45 jsr166 1.7 * @since 1.6
46 dl 1.1 */
47     public interface NavigableSet<E> extends SortedSet<E> {
48     /**
49 jsr166 1.9 * 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 jsr166 1.6 *
52 jsr166 1.5 * @param e the value to match
53 jsr166 1.9 * @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 dl 1.1 */
60 jsr166 1.9 E lower(E e);
61 dl 1.1
62     /**
63 jsr166 1.9 * 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 jsr166 1.6 *
66 jsr166 1.5 * @param e the value to match
67 jsr166 1.9 * @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 dl 1.1 */
74 jsr166 1.9 E floor(E e);
75 dl 1.1
76     /**
77 jsr166 1.9 * 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 jsr166 1.6 *
80 jsr166 1.5 * @param e the value to match
81 jsr166 1.9 * @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 dl 1.1 */
88 jsr166 1.9 E ceiling(E e);
89 dl 1.1
90     /**
91 jsr166 1.9 * 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 jsr166 1.6 *
94 jsr166 1.5 * @param e the value to match
95 jsr166 1.9 * @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 dl 1.1 */
102 jsr166 1.5 E higher(E e);
103 dl 1.1
104     /**
105     * Retrieves and removes the first (lowest) element.
106     *
107 jsr166 1.9 * @return the first element, or <tt>null</tt> if this set is empty
108 dl 1.1 */
109 dl 1.3 E pollFirst();
110 dl 1.1
111     /**
112     * Retrieves and removes the last (highest) element.
113     *
114 jsr166 1.9 * @return the last element, or <tt>null</tt> if this set is empty
115 dl 1.1 */
116 dl 1.3 E pollLast();
117 dl 1.1
118     /**
119 jsr166 1.10 * Returns an iterator over the elements in this set, in ascending order.
120 jsr166 1.6 *
121 jsr166 1.10 * @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 dl 1.1 */
130     Iterator<E> descendingIterator();
131    
132     /**
133 dl 1.3 * 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 jsr166 1.9 * 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 dl 1.3 *
141 jsr166 1.9 * <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 dl 1.1 * @return a view of the portion of this set whose elements range from
147 jsr166 1.9 * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
148 dl 1.1 * @throws ClassCastException if <tt>fromElement</tt> and
149 jsr166 1.9 * <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 dl 1.1 * @throws IllegalArgumentException if <tt>fromElement</tt> is
159 jsr166 1.9 * 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 dl 1.1 */
163 dl 1.3 NavigableSet<E> navigableSubSet(E fromElement, E toElement);
164 dl 1.1
165     /**
166 dl 1.3 * Returns a view of the portion of this set whose elements are
167 jsr166 1.9 * 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 dl 1.1 * @return a view of the portion of this set whose elements are strictly
177 jsr166 1.9 * less than <tt>toElement</tt>
178 dl 1.1 * @throws ClassCastException if <tt>toElement</tt> is not compatible
179     * with this set's comparator (or, if the set has no comparator,
180 jsr166 1.9 * 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 dl 1.1 */
190 dl 1.3 NavigableSet<E> navigableHeadSet(E toElement);
191 dl 1.1
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 jsr166 1.9 * 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 dl 1.1 */
217 dl 1.3 NavigableSet<E> navigableTailSet(E fromElement);
218 dl 1.1 }