ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166x/NavigableSet.java
Revision: 1.1
Committed: Mon Sep 6 17:01:54 2004 UTC (19 years, 9 months ago) by dl
Branch: MAIN
Log Message:
Add Navigable interfaces for concurrent skip list classes; adjust accordingly

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 jsr166x;
8 import java.util.*;
9
10 /**
11 * A {@link SortedSet} extended with methods reporting closest matches
12 * for given search targets. Methods <tt>lower</tt>, <tt>floor</tt>,
13 * <tt>ceiling</tt>, and <tt>higher</tt> return keys respectively
14 * less, less than or equal, greater than or equal, and greater than a
15 * given key, returning <tt>null</tt> if there is no such key. These
16 * methods are designed for locating, not traversing entries. To
17 * traverse, use view iterators and/or <tt>subset</tt>. This interface
18 * additionally defines methods <tt>pollFirst</tt> and
19 * <t>pollLast</tt> that return and remove the lowest and highest key,
20 * if one exists, else returning <tt>null</tt>.
21 *
22 * <p> The return values of these methods may be ambiguous in
23 * implementations that permit <tt>null</tt> elements. However, even
24 * in this case the result can be diambiguated by checking
25 * <tt>contains(null)</tt>.
26 *
27 * @author Doug Lea
28 * @param <E> the type of elements maintained by this set
29 */
30 public interface NavigableSet<E> extends SortedSet<E> {
31 /**
32 * Returns an element greater than or equal to the given element, or
33 * null if there is no such element.
34 *
35 * @param o the value to match
36 * @return an element greater than or equal to given element, or null
37 * if there is no such element.
38 * @throws ClassCastException if o cannot be compared with the elements
39 * currently in the set.
40 * @throws NullPointerException if o is <tt>null</tt>
41 * and this set deas not permit <tt>null</tt> elements
42 */
43 public E ceiling(E o);
44
45 /**
46 * Returns an element strictly less than the given element, or null if
47 * there is no such element.
48 *
49 * @param o the value to match
50 * @return the greatest element less than the given element, or
51 * null if there is no such element.
52 * @throws ClassCastException if o cannot be compared with the elements
53 * currently in the set.
54 * @throws NullPointerException if o is <tt>null</tt>
55 * and this set deas not permit <tt>null</tt> elements
56 */
57 public E lower(E o);
58
59 /**
60 * Returns an element less than or equal to the given element, or null
61 * if there is no such element.
62 *
63 * @param o the value to match
64 * @return the greatest element less than or equal to given
65 * element, or null if there is no such element.
66 * @throws ClassCastException if o cannot be compared with the elements
67 * currently in the set.
68 * @throws NullPointerException if o is <tt>null</tt>.
69 * and this set deas not permit <tt>null</tt> elements
70 */
71 public E floor(E o);
72
73 /**
74 * Returns an element strictly greater than the given element, or null
75 * if there is no such element.
76 *
77 * @param o the value to match
78 * @return the least element greater than the given element, or
79 * null if there is no such element.
80 * @throws ClassCastException if o cannot be compared with the elements
81 * currently in the set.
82 * @throws NullPointerException if o is <tt>null</tt>
83 * and this set deas not permit <tt>null</tt> elements
84 */
85 public E higher(E o);
86
87 /**
88 * Retrieves and removes the first (lowest) element.
89 *
90 * @return the first element, or <tt>null</tt> if empty.
91 */
92 public E pollFirst();
93
94 /**
95 * Retrieves and removes the last (highest) element.
96 *
97 * @return the last element, or <tt>null</tt> if empty.
98 */
99 public E pollLast();
100
101 /**
102 * Returns a view of the portion of this set whose elements range from
103 * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive. (If
104 * <tt>fromElement</tt> and <tt>toElement</tt> are equal, the returned
105 * sorted set is empty.) The returned sorted set is backed by this set,
106 * so changes in the returned sorted set are reflected in this set, and
107 * vice-versa.
108 * @param fromElement low endpoint (inclusive) of the subSet.
109 * @param toElement high endpoint (exclusive) of the subSet.
110 * @return a view of the portion of this set whose elements range from
111 * <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
112 * exclusive.
113 * @throws ClassCastException if <tt>fromElement</tt> and
114 * <tt>toElement</tt> cannot be compared to one another using
115 * this set's comparator (or, if the set has no comparator,
116 * using natural ordering).
117 * @throws IllegalArgumentException if <tt>fromElement</tt> is
118 * greater than <tt>toElement</tt>.
119 * @throws NullPointerException if <tt>fromElement</tt> or
120 * <tt>toElement</tt> is <tt>null</tt>.
121 */
122 public NavigableSet<E> subSet(E fromElement, E toElement);
123
124 /**
125 * Returns a view of the portion of this set whose elements are strictly
126 * less than <tt>toElement</tt>. The returned sorted set is backed by
127 * this set, so changes in the returned sorted set are reflected in this
128 * set, and vice-versa.
129 * @param toElement high endpoint (exclusive) of the headSet.
130 * @return a view of the portion of this set whose elements are strictly
131 * less than toElement.
132 * @throws ClassCastException if <tt>toElement</tt> is not compatible
133 * with this set's comparator (or, if the set has no comparator,
134 * if <tt>toElement</tt> does not implement <tt>Comparable</tt>).
135 * @throws NullPointerException if <tt>toElement</tt> is <tt>null</tt>.
136 */
137 public NavigableSet<E> headSet(E toElement);
138
139 /**
140 * Returns a view of the portion of this set whose elements are
141 * greater than or equal to <tt>fromElement</tt>. The returned
142 * sorted set is backed by this set, so changes in the returned
143 * sorted set are reflected in this set, and vice-versa.
144 * @param fromElement low endpoint (inclusive) of the tailSet.
145 * @return a view of the portion of this set whose elements are
146 * greater than or equal to <tt>fromElement</tt>.
147 * @throws ClassCastException if <tt>fromElement</tt> is not
148 * compatible with this set's comparator (or, if the set has no
149 * comparator, if <tt>fromElement</tt> does not implement
150 * <tt>Comparable</tt>).
151 * @throws NullPointerException if <tt>fromElement</tt> is <tt>null</tt>.
152 */
153 public NavigableSet<E> tailSet(E fromElement);
154 }