ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableSet.java
(Generate patch)

Comparing jsr166/src/main/java/util/NavigableSet.java (file contents):
Revision 1.3 by dl, Tue Mar 22 01:30:10 2005 UTC vs.
Revision 1.13 by jsr166, Thu Aug 11 08:54:39 2005 UTC

# Line 5 | Line 5
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 keys
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 key, returning <tt>null</tt> if there is
16 < * no such key.  A <tt>NavigableSet</tt> may be viewed and traversed
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
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 < * <t>pollLast</tt> that return and remove the lowest and highest key,
24 < * if one exists, else returning <tt>null</tt>.
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 <em>not</em> to permit insertion 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 an element greater than or equal to the given element, or
50 <     * <tt>null</tt> if there is no such element.
51 <     *
52 <     * @param o the value to match
53 <     * @return an element greater than or equal to given element, or
54 <     * <tt>null</tt> if there is no such element.
55 <     * @throws ClassCastException if o cannot be compared with the elements
56 <     *            currently in the set.
57 <     * @throws NullPointerException if o is <tt>null</tt>
58 <     * and this set does not permit <tt>null</tt> elements
59 <     */
60 <    E ceiling(E o);
61 <
62 <    /**
63 <     * Returns an element strictly less than the given element, or
64 <     * <tt>null</tt> if there is no such element.
65 <     *
66 <     * @param o the value to match
67 <     * @return the greatest element less than the given element, or
68 <     * <tt>null</tt> if there is no such element.
69 <     * @throws ClassCastException if o cannot be compared with the elements
70 <     *            currently in the set.
71 <     * @throws NullPointerException if o is <tt>null</tt>
72 <     * and this set does not permit <tt>null</tt> elements
73 <     */
74 <    E lower(E o);
75 <
76 <    /**
77 <     * Returns an element less than or equal to the given element, or
78 <     * <tt>null</tt> if there is no such element.
79 <     *
80 <     * @param o the value to match
81 <     * @return the greatest element less than or equal to given
82 <     * element, or <tt>null</tt> if there is no such element.
83 <     * @throws ClassCastException if o cannot be compared with the elements
84 <     *            currently in the set.
85 <     * @throws NullPointerException if o is <tt>null</tt>.
86 <     * and this set does not permit <tt>null</tt> elements
87 <     */
88 <    E floor(E o);
89 <
90 <    /**
91 <     * Returns an element strictly greater than the given element, or
92 <     * <tt>null</tt> if there is no such element.
93 <     *
94 <     * @param o the value to match
95 <     * @return the least element greater than the given element, or
96 <     * <tt>null</tt> if there is no such element.
97 <     * @throws ClassCastException if o cannot be compared with the elements
98 <     *            currently in the set.
99 <     * @throws NullPointerException if o is <tt>null</tt>
100 <     * and this set does not permit <tt>null</tt> elements
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 o);
102 >    E higher(E e);
103  
104      /**
105 <     * Retrieves and removes the first (lowest) element.
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 empty.
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.
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 empty.
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 collection, in
122 <     * descending order.  
123 <     *
124 <     * @return an <tt>Iterator</tt> over the elements in this collection
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  
# Line 116 | Line 135 | public interface NavigableSet<E> extends
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 navigable set is empty.)  The returned
139 <     * navigable set is backed by this set, so changes in the returned
140 <     * navigable set are reflected in this set, and vice-versa. Note:
141 <     * This method differs from <tt>SortedSet.subSet</tt> only in that
142 <     * the returned set is guaranteed to support the
143 <     * <tt>NavigableSet</tt> interface.
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 subSet.
147 <     * @param toElement high endpoint (exclusive) of the subSet.
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>,
130 <     *         exclusive.
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
152 <     *         this set's comparator (or, if the set has no comparator,
153 <     *         using natural ordering).
154 <     * @throws IllegalArgumentException if <tt>fromElement</tt> is
155 <     * greater than <tt>toElement</tt>.
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 <tt>null</tt>
159 <     * and this set does not permit <tt>null</tt> elements
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 navigable
170 <     * set is backed by this set, so changes in the returned navigable
171 <     * set are reflected in this set, and vice-versa.
172 <     * @param toElement high endpoint (exclusive) of the headSet.
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 toElement.
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 <tt>Comparable</tt>).
183 <     * @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt>
184 <     * and this set does not permit <tt>null</tt> elements
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 <     * navigable set is backed by this set, so changes in the returned
198 <     * navigable set are reflected in this set, and vice-versa.
199 <     * @param fromElement low endpoint (inclusive) of the tailSet.
200 <     * @return a view of the portion of this set whose elements are
201 <     * greater than or equal to <tt>fromElement</tt>.
202 <     * @throws ClassCastException if <tt>fromElement</tt> is not
203 <     * compatible with this set's comparator (or, if the set has no
204 <     * comparator, if <tt>fromElement</tt> does not implement
205 <     * <tt>Comparable</tt>).
206 <     * @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt>
207 <     * and this set does not permit <tt>null</tt> elements
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines