ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166x/NavigableSet.java
Revision: 1.12
Committed: Sun Jan 18 20:17:33 2015 UTC (9 years, 3 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +1 -0 lines
Log Message:
exactly one blank line before and after package statements

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