2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / util / SortedSet.java
blob401edb97395754d552b6e7673112ed49943978f0
1 /* SortedSet.java -- A set that makes guarantees about the order of its
2 elements
3 Copyright (C) 1998, 2001 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package java.util;
42 /**
43 * A set which guarantees its iteration order. The elements in the set
44 * are related by the <i>natural ordering</i> if they are Comparable, or
45 * by the provided Comparator. Additional operations take advantage of
46 * the sorted nature of the set.
47 * <p>
49 * All elements entered in the set must be mutually comparable; in other words,
50 * <code>k1.compareTo(k2)</code> or <code>comparator.compare(k1, k2)</code>
51 * must not throw a ClassCastException. The ordering must be <i>consistent
52 * with equals</i> (see {@link Comparator} for this definition), if the
53 * map is to obey the general contract of the Set interface. If not,
54 * the results are well-defined, but probably not what you wanted.
55 * <p>
57 * It is recommended that all implementing classes provide four constructors:
58 * 1) one that takes no arguments and builds an empty set sorted by natural
59 * order of the elements; 2) one that takes a Comparator for the sorting order;
60 * 3) one that takes a Set and sorts according to the natural order of its
61 * elements; and 4) one that takes a SortedSet and sorts by the same
62 * comparator. Unfortunately, the Java language does not provide a way to
63 * enforce this.
65 * @author Original author unknown
66 * @author Eric Blake <ebb9@email.byu.edu>
67 * @see Set
68 * @see TreeSet
69 * @see SortedMap
70 * @see Collection
71 * @see Comparable
72 * @see Comparator
73 * @see ClassCastException
74 * @since 1.2
75 * @status updated to 1.4
77 public interface SortedSet extends Set
79 /**
80 * Returns the comparator used in sorting this set, or null if it is
81 * the elements' natural ordering.
83 * @return the sorting comparator
85 Comparator comparator();
87 /**
88 * Returns the first (lowest sorted) element in the map.
90 * @return the first element
92 Object first();
94 /**
95 * Returns a view of the portion of the set strictly less than toElement. The
96 * view is backed by this set, so changes in one show up in the other.
97 * The subset supports all optional operations of the original.
98 * <p>
100 * The returned set throws an IllegalArgumentException any time an element is
101 * used which is out of the range of toElement. Note that the endpoint is not
102 * included; if you want the endpoint, pass the successor object in to
103 * toElement. For example, for Strings, you can request
104 * <code>headSet(limit + "\0")</code>.
106 * @param toElement the exclusive upper range of the subset
107 * @return the subset
108 * @throws ClassCastException if toElement is not comparable to the set
109 * contents
110 * @throws IllegalArgumentException if this is a subSet, and toElement is out
111 * of range
112 * @throws NullPointerException if toElement is null but the map does not
113 * allow null elements
115 SortedSet headSet(Object toElement);
118 * Returns the last (highest sorted) element in the map.
120 * @return the last element
122 Object last();
125 * Returns a view of the portion of the set greater than or equal to
126 * fromElement, and strictly less than toElement. The view is backed by
127 * this set, so changes in one show up in the other. The subset supports all
128 * optional operations of the original.
129 * <p>
131 * The returned set throws an IllegalArgumentException any time an element is
132 * used which is out of the range of fromElement and toElement. Note that the
133 * lower endpoint is included, but the upper is not; if you want to
134 * change the inclusion or exclusion of an endpoint, pass the successor
135 * object in instead. For example, for Strings, you can request
136 * <code>subSet(lowlimit + "\0", highlimit + "\0")</code> to reverse
137 * the inclusiveness of both endpoints.
139 * @param fromElement the inclusive lower range of the subset
140 * @param toElement the exclusive upper range of the subset
141 * @return the subset
142 * @throws ClassCastException if fromElement or toElement is not comparable
143 * to the set contents
144 * @throws IllegalArgumentException if this is a subSet, and fromElement or
145 * toElement is out of range
146 * @throws NullPointerException if fromElement or toElement is null but the
147 * set does not allow null elements
149 SortedSet subSet(Object fromElement, Object toElement);
152 * Returns a view of the portion of the set greater than or equal to
153 * fromElement. The view is backed by this set, so changes in one show up
154 * in the other. The subset supports all optional operations of the original.
155 * <p>
157 * The returned set throws an IllegalArgumentException any time an element is
158 * used which is out of the range of fromElement. Note that the endpoint is
159 * included; if you do not want the endpoint, pass the successor object in
160 * to fromElement. For example, for Strings, you can request
161 * <code>tailSet(limit + "\0")</code>.
163 * @param fromElement the inclusive lower range of the subset
164 * @return the subset
165 * @throws ClassCastException if fromElement is not comparable to the set
166 * contents
167 * @throws IllegalArgumentException if this is a subSet, and fromElement is
168 * out of range
169 * @throws NullPointerException if fromElement is null but the set does not
170 * allow null elements
172 SortedSet tailSet(Object fromElement);