ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableSet.java
Revision: 1.7
Committed: Mon May 2 22:34:56 2005 UTC (19 years ago) by jsr166
Branch: MAIN
Changes since 1.6: +1 -0 lines
Log Message:
Add missing @since 1.6

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
9 /**
10 * A {@link SortedSet} extended with navigation methods reporting
11 * closest matches for given search targets. Methods <tt>lower</tt>,
12 * <tt>floor</tt>, <tt>ceiling</tt>, and <tt>higher</tt> return keys
13 * respectively less than, less than or equal, greater than or equal,
14 * and greater than a given key, returning <tt>null</tt> if there is
15 * no such key. A <tt>NavigableSet</tt> may be viewed and traversed
16 * in either ascending or descending order. The <tt>Collection</tt>
17 * <tt>iterator</tt> method returns an ascending <tt>Iterator</tt> and
18 * the additional method <tt>descendingIterator</tt> returns
19 * 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 * <t>pollLast</tt> that return and remove the lowest and highest key,
23 * if one exists, else returning <tt>null</tt>.
24 * 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 *
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 * this interface are encouraged <em>not</em> to permit insertion of
34 * <tt>null</tt> elements. (Note that sorted sets of {@link
35 * Comparable} elements intrinsically do not permit <tt>null</tt>.)
36 *
37 * @author Doug Lea
38 * @param <E> the type of elements maintained by this set
39 * @since 1.6
40 */
41 public interface NavigableSet<E> extends SortedSet<E> {
42 /**
43 * Returns an element greater than or equal to the given element, or
44 * <tt>null</tt> if there is no such element.
45 *
46 * @param e the value to match
47 * @return an element greater than or equal to given element, or
48 * <tt>null</tt> if there is no such element.
49 * @throws ClassCastException if e cannot be compared with the elements
50 * currently in the set.
51 * @throws NullPointerException if e is <tt>null</tt>
52 * and this set does not permit <tt>null</tt> elements
53 */
54 E ceiling(E e);
55
56 /**
57 * Returns an element strictly less than the given element, or
58 * <tt>null</tt> if there is no such element.
59 *
60 * @param e the value to match
61 * @return the greatest element less than the given element, or
62 * <tt>null</tt> if there is no such element.
63 * @throws ClassCastException if e cannot be compared with the elements
64 * currently in the set.
65 * @throws NullPointerException if e is <tt>null</tt>
66 * and this set does not permit <tt>null</tt> elements
67 */
68 E lower(E e);
69
70 /**
71 * Returns an element less than or equal to the given element, or
72 * <tt>null</tt> if there is no such element.
73 *
74 * @param e the value to match
75 * @return the greatest element less than or equal to given
76 * element, or <tt>null</tt> if there is no such element.
77 * @throws ClassCastException if e cannot be compared with the elements
78 * currently in the set.
79 * @throws NullPointerException if e is <tt>null</tt>.
80 * and this set does not permit <tt>null</tt> elements
81 */
82 E floor(E e);
83
84 /**
85 * Returns an element strictly greater than the given element, or
86 * <tt>null</tt> if there is no such element.
87 *
88 * @param e the value to match
89 * @return the least element greater than the given element, or
90 * <tt>null</tt> if there is no such element.
91 * @throws ClassCastException if e cannot be compared with the elements
92 * currently in the set.
93 * @throws NullPointerException if e is <tt>null</tt>
94 * and this set does not permit <tt>null</tt> elements
95 */
96 E higher(E e);
97
98 /**
99 * Retrieves and removes the first (lowest) element.
100 *
101 * @return the first element, or <tt>null</tt> if empty.
102 */
103 E pollFirst();
104
105 /**
106 * Retrieves and removes the last (highest) element.
107 *
108 * @return the last element, or <tt>null</tt> if empty.
109 */
110 E pollLast();
111
112 /**
113 * Returns an iterator over the elements in this collection, in
114 * descending order.
115 *
116 * @return an <tt>Iterator</tt> over the elements in this collection
117 */
118 Iterator<E> descendingIterator();
119
120 /**
121 * Returns a view of the portion of this set whose elements range
122 * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
123 * exclusive. (If <tt>fromElement</tt> and <tt>toElement</tt> are
124 * equal, the returned navigable set is empty.) The returned
125 * navigable set is backed by this set, so changes in the returned
126 * navigable set are reflected in this set, and vice-versa.
127 *
128 * @param fromElement low endpoint (inclusive) of the subSet.
129 * @param toElement high endpoint (exclusive) of the subSet.
130 * @return a view of the portion of this set whose elements range from
131 * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
132 * exclusive.
133 * @throws ClassCastException if <tt>fromElement</tt> and
134 * <tt>toElement</tt> cannot be compared to one another using
135 * this set's comparator (or, if the set has no comparator,
136 * using natural ordering).
137 * @throws IllegalArgumentException if <tt>fromElement</tt> is
138 * greater than <tt>toElement</tt>.
139 * @throws NullPointerException if <tt>fromElement</tt> or
140 * <tt>toElement</tt> is <tt>null</tt>
141 * and this set does not permit <tt>null</tt> elements
142 */
143 NavigableSet<E> navigableSubSet(E fromElement, E toElement);
144
145 /**
146 * Returns a view of the portion of this set whose elements are
147 * strictly less than <tt>toElement</tt>. The returned navigable
148 * set is backed by this set, so changes in the returned navigable
149 * set are reflected in this set, and vice-versa.
150 * @param toElement high endpoint (exclusive) of the headSet.
151 * @return a view of the portion of this set whose elements are strictly
152 * less than toElement.
153 * @throws ClassCastException if <tt>toElement</tt> is not compatible
154 * with this set's comparator (or, if the set has no comparator,
155 * if <tt>toElement</tt> does not implement <tt>Comparable</tt>).
156 * @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt>
157 * and this set does not permit <tt>null</tt> elements
158 */
159 NavigableSet<E> navigableHeadSet(E toElement);
160
161 /**
162 * Returns a view of the portion of this set whose elements are
163 * greater than or equal to <tt>fromElement</tt>. The returned
164 * navigable set is backed by this set, so changes in the returned
165 * navigable set are reflected in this set, and vice-versa.
166 * @param fromElement low endpoint (inclusive) of the tailSet.
167 * @return a view of the portion of this set whose elements are
168 * greater than or equal to <tt>fromElement</tt>.
169 * @throws ClassCastException if <tt>fromElement</tt> is not
170 * compatible with this set's comparator (or, if the set has no
171 * comparator, if <tt>fromElement</tt> does not implement
172 * <tt>Comparable</tt>).
173 * @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt>
174 * and this set does not permit <tt>null</tt> elements
175 */
176 NavigableSet<E> navigableTailSet(E fromElement);
177 }