jaroslav@557
|
1 |
/*
|
jaroslav@557
|
2 |
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@557
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@557
|
4 |
*
|
jaroslav@557
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@557
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@557
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@557
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@557
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@557
|
10 |
*
|
jaroslav@557
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@557
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@557
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@557
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@557
|
15 |
* accompanied this code).
|
jaroslav@557
|
16 |
*
|
jaroslav@557
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@557
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@557
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@557
|
20 |
*
|
jaroslav@557
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@557
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@557
|
23 |
* questions.
|
jaroslav@557
|
24 |
*/
|
jaroslav@557
|
25 |
|
jaroslav@557
|
26 |
package java.util;
|
jaroslav@557
|
27 |
|
jaroslav@557
|
28 |
/**
|
jaroslav@557
|
29 |
* A collection that contains no duplicate elements. More formally, sets
|
jaroslav@557
|
30 |
* contain no pair of elements <code>e1</code> and <code>e2</code> such that
|
jaroslav@557
|
31 |
* <code>e1.equals(e2)</code>, and at most one null element. As implied by
|
jaroslav@557
|
32 |
* its name, this interface models the mathematical <i>set</i> abstraction.
|
jaroslav@557
|
33 |
*
|
jaroslav@557
|
34 |
* <p>The <tt>Set</tt> interface places additional stipulations, beyond those
|
jaroslav@557
|
35 |
* inherited from the <tt>Collection</tt> interface, on the contracts of all
|
jaroslav@557
|
36 |
* constructors and on the contracts of the <tt>add</tt>, <tt>equals</tt> and
|
jaroslav@557
|
37 |
* <tt>hashCode</tt> methods. Declarations for other inherited methods are
|
jaroslav@557
|
38 |
* also included here for convenience. (The specifications accompanying these
|
jaroslav@557
|
39 |
* declarations have been tailored to the <tt>Set</tt> interface, but they do
|
jaroslav@557
|
40 |
* not contain any additional stipulations.)
|
jaroslav@557
|
41 |
*
|
jaroslav@557
|
42 |
* <p>The additional stipulation on constructors is, not surprisingly,
|
jaroslav@557
|
43 |
* that all constructors must create a set that contains no duplicate elements
|
jaroslav@557
|
44 |
* (as defined above).
|
jaroslav@557
|
45 |
*
|
jaroslav@557
|
46 |
* <p>Note: Great care must be exercised if mutable objects are used as set
|
jaroslav@557
|
47 |
* elements. The behavior of a set is not specified if the value of an object
|
jaroslav@557
|
48 |
* is changed in a manner that affects <tt>equals</tt> comparisons while the
|
jaroslav@557
|
49 |
* object is an element in the set. A special case of this prohibition is
|
jaroslav@557
|
50 |
* that it is not permissible for a set to contain itself as an element.
|
jaroslav@557
|
51 |
*
|
jaroslav@557
|
52 |
* <p>Some set implementations have restrictions on the elements that
|
jaroslav@557
|
53 |
* they may contain. For example, some implementations prohibit null elements,
|
jaroslav@557
|
54 |
* and some have restrictions on the types of their elements. Attempting to
|
jaroslav@557
|
55 |
* add an ineligible element throws an unchecked exception, typically
|
jaroslav@557
|
56 |
* <tt>NullPointerException</tt> or <tt>ClassCastException</tt>. Attempting
|
jaroslav@557
|
57 |
* to query the presence of an ineligible element may throw an exception,
|
jaroslav@557
|
58 |
* or it may simply return false; some implementations will exhibit the former
|
jaroslav@557
|
59 |
* behavior and some will exhibit the latter. More generally, attempting an
|
jaroslav@557
|
60 |
* operation on an ineligible element whose completion would not result in
|
jaroslav@557
|
61 |
* the insertion of an ineligible element into the set may throw an
|
jaroslav@557
|
62 |
* exception or it may succeed, at the option of the implementation.
|
jaroslav@557
|
63 |
* Such exceptions are marked as "optional" in the specification for this
|
jaroslav@557
|
64 |
* interface.
|
jaroslav@557
|
65 |
*
|
jaroslav@557
|
66 |
* <p>This interface is a member of the
|
jaroslav@557
|
67 |
* <a href="{@docRoot}/../technotes/guides/collections/index.html">
|
jaroslav@557
|
68 |
* Java Collections Framework</a>.
|
jaroslav@557
|
69 |
*
|
jaroslav@557
|
70 |
* @param <E> the type of elements maintained by this set
|
jaroslav@557
|
71 |
*
|
jaroslav@557
|
72 |
* @author Josh Bloch
|
jaroslav@557
|
73 |
* @author Neal Gafter
|
jaroslav@557
|
74 |
* @see Collection
|
jaroslav@557
|
75 |
* @see List
|
jaroslav@557
|
76 |
* @see SortedSet
|
jaroslav@557
|
77 |
* @see HashSet
|
jaroslav@557
|
78 |
* @see TreeSet
|
jaroslav@557
|
79 |
* @see AbstractSet
|
jaroslav@557
|
80 |
* @see Collections#singleton(java.lang.Object)
|
jaroslav@557
|
81 |
* @see Collections#EMPTY_SET
|
jaroslav@557
|
82 |
* @since 1.2
|
jaroslav@557
|
83 |
*/
|
jaroslav@557
|
84 |
|
jaroslav@557
|
85 |
public interface Set<E> extends Collection<E> {
|
jaroslav@557
|
86 |
// Query Operations
|
jaroslav@557
|
87 |
|
jaroslav@557
|
88 |
/**
|
jaroslav@557
|
89 |
* Returns the number of elements in this set (its cardinality). If this
|
jaroslav@557
|
90 |
* set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
|
jaroslav@557
|
91 |
* <tt>Integer.MAX_VALUE</tt>.
|
jaroslav@557
|
92 |
*
|
jaroslav@557
|
93 |
* @return the number of elements in this set (its cardinality)
|
jaroslav@557
|
94 |
*/
|
jaroslav@557
|
95 |
int size();
|
jaroslav@557
|
96 |
|
jaroslav@557
|
97 |
/**
|
jaroslav@557
|
98 |
* Returns <tt>true</tt> if this set contains no elements.
|
jaroslav@557
|
99 |
*
|
jaroslav@557
|
100 |
* @return <tt>true</tt> if this set contains no elements
|
jaroslav@557
|
101 |
*/
|
jaroslav@557
|
102 |
boolean isEmpty();
|
jaroslav@557
|
103 |
|
jaroslav@557
|
104 |
/**
|
jaroslav@557
|
105 |
* Returns <tt>true</tt> if this set contains the specified element.
|
jaroslav@557
|
106 |
* More formally, returns <tt>true</tt> if and only if this set
|
jaroslav@557
|
107 |
* contains an element <tt>e</tt> such that
|
jaroslav@557
|
108 |
* <tt>(o==null ? e==null : o.equals(e))</tt>.
|
jaroslav@557
|
109 |
*
|
jaroslav@557
|
110 |
* @param o element whose presence in this set is to be tested
|
jaroslav@557
|
111 |
* @return <tt>true</tt> if this set contains the specified element
|
jaroslav@557
|
112 |
* @throws ClassCastException if the type of the specified element
|
jaroslav@557
|
113 |
* is incompatible with this set
|
jaroslav@557
|
114 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
115 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@557
|
116 |
* set does not permit null elements
|
jaroslav@557
|
117 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
118 |
*/
|
jaroslav@557
|
119 |
boolean contains(Object o);
|
jaroslav@557
|
120 |
|
jaroslav@557
|
121 |
/**
|
jaroslav@557
|
122 |
* Returns an iterator over the elements in this set. The elements are
|
jaroslav@557
|
123 |
* returned in no particular order (unless this set is an instance of some
|
jaroslav@557
|
124 |
* class that provides a guarantee).
|
jaroslav@557
|
125 |
*
|
jaroslav@557
|
126 |
* @return an iterator over the elements in this set
|
jaroslav@557
|
127 |
*/
|
jaroslav@557
|
128 |
Iterator<E> iterator();
|
jaroslav@557
|
129 |
|
jaroslav@557
|
130 |
/**
|
jaroslav@557
|
131 |
* Returns an array containing all of the elements in this set.
|
jaroslav@557
|
132 |
* If this set makes any guarantees as to what order its elements
|
jaroslav@557
|
133 |
* are returned by its iterator, this method must return the
|
jaroslav@557
|
134 |
* elements in the same order.
|
jaroslav@557
|
135 |
*
|
jaroslav@557
|
136 |
* <p>The returned array will be "safe" in that no references to it
|
jaroslav@557
|
137 |
* are maintained by this set. (In other words, this method must
|
jaroslav@557
|
138 |
* allocate a new array even if this set is backed by an array).
|
jaroslav@557
|
139 |
* The caller is thus free to modify the returned array.
|
jaroslav@557
|
140 |
*
|
jaroslav@557
|
141 |
* <p>This method acts as bridge between array-based and collection-based
|
jaroslav@557
|
142 |
* APIs.
|
jaroslav@557
|
143 |
*
|
jaroslav@557
|
144 |
* @return an array containing all the elements in this set
|
jaroslav@557
|
145 |
*/
|
jaroslav@557
|
146 |
Object[] toArray();
|
jaroslav@557
|
147 |
|
jaroslav@557
|
148 |
/**
|
jaroslav@557
|
149 |
* Returns an array containing all of the elements in this set; the
|
jaroslav@557
|
150 |
* runtime type of the returned array is that of the specified array.
|
jaroslav@557
|
151 |
* If the set fits in the specified array, it is returned therein.
|
jaroslav@557
|
152 |
* Otherwise, a new array is allocated with the runtime type of the
|
jaroslav@557
|
153 |
* specified array and the size of this set.
|
jaroslav@557
|
154 |
*
|
jaroslav@557
|
155 |
* <p>If this set fits in the specified array with room to spare
|
jaroslav@557
|
156 |
* (i.e., the array has more elements than this set), the element in
|
jaroslav@557
|
157 |
* the array immediately following the end of the set is set to
|
jaroslav@557
|
158 |
* <tt>null</tt>. (This is useful in determining the length of this
|
jaroslav@557
|
159 |
* set <i>only</i> if the caller knows that this set does not contain
|
jaroslav@557
|
160 |
* any null elements.)
|
jaroslav@557
|
161 |
*
|
jaroslav@557
|
162 |
* <p>If this set makes any guarantees as to what order its elements
|
jaroslav@557
|
163 |
* are returned by its iterator, this method must return the elements
|
jaroslav@557
|
164 |
* in the same order.
|
jaroslav@557
|
165 |
*
|
jaroslav@557
|
166 |
* <p>Like the {@link #toArray()} method, this method acts as bridge between
|
jaroslav@557
|
167 |
* array-based and collection-based APIs. Further, this method allows
|
jaroslav@557
|
168 |
* precise control over the runtime type of the output array, and may,
|
jaroslav@557
|
169 |
* under certain circumstances, be used to save allocation costs.
|
jaroslav@557
|
170 |
*
|
jaroslav@557
|
171 |
* <p>Suppose <tt>x</tt> is a set known to contain only strings.
|
jaroslav@557
|
172 |
* The following code can be used to dump the set into a newly allocated
|
jaroslav@557
|
173 |
* array of <tt>String</tt>:
|
jaroslav@557
|
174 |
*
|
jaroslav@557
|
175 |
* <pre>
|
jaroslav@557
|
176 |
* String[] y = x.toArray(new String[0]);</pre>
|
jaroslav@557
|
177 |
*
|
jaroslav@557
|
178 |
* Note that <tt>toArray(new Object[0])</tt> is identical in function to
|
jaroslav@557
|
179 |
* <tt>toArray()</tt>.
|
jaroslav@557
|
180 |
*
|
jaroslav@557
|
181 |
* @param a the array into which the elements of this set are to be
|
jaroslav@557
|
182 |
* stored, if it is big enough; otherwise, a new array of the same
|
jaroslav@557
|
183 |
* runtime type is allocated for this purpose.
|
jaroslav@557
|
184 |
* @return an array containing all the elements in this set
|
jaroslav@557
|
185 |
* @throws ArrayStoreException if the runtime type of the specified array
|
jaroslav@557
|
186 |
* is not a supertype of the runtime type of every element in this
|
jaroslav@557
|
187 |
* set
|
jaroslav@557
|
188 |
* @throws NullPointerException if the specified array is null
|
jaroslav@557
|
189 |
*/
|
jaroslav@557
|
190 |
<T> T[] toArray(T[] a);
|
jaroslav@557
|
191 |
|
jaroslav@557
|
192 |
|
jaroslav@557
|
193 |
// Modification Operations
|
jaroslav@557
|
194 |
|
jaroslav@557
|
195 |
/**
|
jaroslav@557
|
196 |
* Adds the specified element to this set if it is not already present
|
jaroslav@557
|
197 |
* (optional operation). More formally, adds the specified element
|
jaroslav@557
|
198 |
* <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
|
jaroslav@557
|
199 |
* such that
|
jaroslav@557
|
200 |
* <tt>(e==null ? e2==null : e.equals(e2))</tt>.
|
jaroslav@557
|
201 |
* If this set already contains the element, the call leaves the set
|
jaroslav@557
|
202 |
* unchanged and returns <tt>false</tt>. In combination with the
|
jaroslav@557
|
203 |
* restriction on constructors, this ensures that sets never contain
|
jaroslav@557
|
204 |
* duplicate elements.
|
jaroslav@557
|
205 |
*
|
jaroslav@557
|
206 |
* <p>The stipulation above does not imply that sets must accept all
|
jaroslav@557
|
207 |
* elements; sets may refuse to add any particular element, including
|
jaroslav@557
|
208 |
* <tt>null</tt>, and throw an exception, as described in the
|
jaroslav@557
|
209 |
* specification for {@link Collection#add Collection.add}.
|
jaroslav@557
|
210 |
* Individual set implementations should clearly document any
|
jaroslav@557
|
211 |
* restrictions on the elements that they may contain.
|
jaroslav@557
|
212 |
*
|
jaroslav@557
|
213 |
* @param e element to be added to this set
|
jaroslav@557
|
214 |
* @return <tt>true</tt> if this set did not already contain the specified
|
jaroslav@557
|
215 |
* element
|
jaroslav@557
|
216 |
* @throws UnsupportedOperationException if the <tt>add</tt> operation
|
jaroslav@557
|
217 |
* is not supported by this set
|
jaroslav@557
|
218 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@557
|
219 |
* prevents it from being added to this set
|
jaroslav@557
|
220 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@557
|
221 |
* set does not permit null elements
|
jaroslav@557
|
222 |
* @throws IllegalArgumentException if some property of the specified element
|
jaroslav@557
|
223 |
* prevents it from being added to this set
|
jaroslav@557
|
224 |
*/
|
jaroslav@557
|
225 |
boolean add(E e);
|
jaroslav@557
|
226 |
|
jaroslav@557
|
227 |
|
jaroslav@557
|
228 |
/**
|
jaroslav@557
|
229 |
* Removes the specified element from this set if it is present
|
jaroslav@557
|
230 |
* (optional operation). More formally, removes an element <tt>e</tt>
|
jaroslav@557
|
231 |
* such that
|
jaroslav@557
|
232 |
* <tt>(o==null ? e==null : o.equals(e))</tt>, if
|
jaroslav@557
|
233 |
* this set contains such an element. Returns <tt>true</tt> if this set
|
jaroslav@557
|
234 |
* contained the element (or equivalently, if this set changed as a
|
jaroslav@557
|
235 |
* result of the call). (This set will not contain the element once the
|
jaroslav@557
|
236 |
* call returns.)
|
jaroslav@557
|
237 |
*
|
jaroslav@557
|
238 |
* @param o object to be removed from this set, if present
|
jaroslav@557
|
239 |
* @return <tt>true</tt> if this set contained the specified element
|
jaroslav@557
|
240 |
* @throws ClassCastException if the type of the specified element
|
jaroslav@557
|
241 |
* is incompatible with this set
|
jaroslav@557
|
242 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
243 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@557
|
244 |
* set does not permit null elements
|
jaroslav@557
|
245 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
246 |
* @throws UnsupportedOperationException if the <tt>remove</tt> operation
|
jaroslav@557
|
247 |
* is not supported by this set
|
jaroslav@557
|
248 |
*/
|
jaroslav@557
|
249 |
boolean remove(Object o);
|
jaroslav@557
|
250 |
|
jaroslav@557
|
251 |
|
jaroslav@557
|
252 |
// Bulk Operations
|
jaroslav@557
|
253 |
|
jaroslav@557
|
254 |
/**
|
jaroslav@557
|
255 |
* Returns <tt>true</tt> if this set contains all of the elements of the
|
jaroslav@557
|
256 |
* specified collection. If the specified collection is also a set, this
|
jaroslav@557
|
257 |
* method returns <tt>true</tt> if it is a <i>subset</i> of this set.
|
jaroslav@557
|
258 |
*
|
jaroslav@557
|
259 |
* @param c collection to be checked for containment in this set
|
jaroslav@557
|
260 |
* @return <tt>true</tt> if this set contains all of the elements of the
|
jaroslav@557
|
261 |
* specified collection
|
jaroslav@557
|
262 |
* @throws ClassCastException if the types of one or more elements
|
jaroslav@557
|
263 |
* in the specified collection are incompatible with this
|
jaroslav@557
|
264 |
* set
|
jaroslav@557
|
265 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
266 |
* @throws NullPointerException if the specified collection contains one
|
jaroslav@557
|
267 |
* or more null elements and this set does not permit null
|
jaroslav@557
|
268 |
* elements
|
jaroslav@557
|
269 |
* (<a href="Collection.html#optional-restrictions">optional</a>),
|
jaroslav@557
|
270 |
* or if the specified collection is null
|
jaroslav@557
|
271 |
* @see #contains(Object)
|
jaroslav@557
|
272 |
*/
|
jaroslav@557
|
273 |
boolean containsAll(Collection<?> c);
|
jaroslav@557
|
274 |
|
jaroslav@557
|
275 |
/**
|
jaroslav@557
|
276 |
* Adds all of the elements in the specified collection to this set if
|
jaroslav@557
|
277 |
* they're not already present (optional operation). If the specified
|
jaroslav@557
|
278 |
* collection is also a set, the <tt>addAll</tt> operation effectively
|
jaroslav@557
|
279 |
* modifies this set so that its value is the <i>union</i> of the two
|
jaroslav@557
|
280 |
* sets. The behavior of this operation is undefined if the specified
|
jaroslav@557
|
281 |
* collection is modified while the operation is in progress.
|
jaroslav@557
|
282 |
*
|
jaroslav@557
|
283 |
* @param c collection containing elements to be added to this set
|
jaroslav@557
|
284 |
* @return <tt>true</tt> if this set changed as a result of the call
|
jaroslav@557
|
285 |
*
|
jaroslav@557
|
286 |
* @throws UnsupportedOperationException if the <tt>addAll</tt> operation
|
jaroslav@557
|
287 |
* is not supported by this set
|
jaroslav@557
|
288 |
* @throws ClassCastException if the class of an element of the
|
jaroslav@557
|
289 |
* specified collection prevents it from being added to this set
|
jaroslav@557
|
290 |
* @throws NullPointerException if the specified collection contains one
|
jaroslav@557
|
291 |
* or more null elements and this set does not permit null
|
jaroslav@557
|
292 |
* elements, or if the specified collection is null
|
jaroslav@557
|
293 |
* @throws IllegalArgumentException if some property of an element of the
|
jaroslav@557
|
294 |
* specified collection prevents it from being added to this set
|
jaroslav@557
|
295 |
* @see #add(Object)
|
jaroslav@557
|
296 |
*/
|
jaroslav@557
|
297 |
boolean addAll(Collection<? extends E> c);
|
jaroslav@557
|
298 |
|
jaroslav@557
|
299 |
/**
|
jaroslav@557
|
300 |
* Retains only the elements in this set that are contained in the
|
jaroslav@557
|
301 |
* specified collection (optional operation). In other words, removes
|
jaroslav@557
|
302 |
* from this set all of its elements that are not contained in the
|
jaroslav@557
|
303 |
* specified collection. If the specified collection is also a set, this
|
jaroslav@557
|
304 |
* operation effectively modifies this set so that its value is the
|
jaroslav@557
|
305 |
* <i>intersection</i> of the two sets.
|
jaroslav@557
|
306 |
*
|
jaroslav@557
|
307 |
* @param c collection containing elements to be retained in this set
|
jaroslav@557
|
308 |
* @return <tt>true</tt> if this set changed as a result of the call
|
jaroslav@557
|
309 |
* @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
|
jaroslav@557
|
310 |
* is not supported by this set
|
jaroslav@557
|
311 |
* @throws ClassCastException if the class of an element of this set
|
jaroslav@557
|
312 |
* is incompatible with the specified collection
|
jaroslav@557
|
313 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
314 |
* @throws NullPointerException if this set contains a null element and the
|
jaroslav@557
|
315 |
* specified collection does not permit null elements
|
jaroslav@557
|
316 |
* (<a href="Collection.html#optional-restrictions">optional</a>),
|
jaroslav@557
|
317 |
* or if the specified collection is null
|
jaroslav@557
|
318 |
* @see #remove(Object)
|
jaroslav@557
|
319 |
*/
|
jaroslav@557
|
320 |
boolean retainAll(Collection<?> c);
|
jaroslav@557
|
321 |
|
jaroslav@557
|
322 |
/**
|
jaroslav@557
|
323 |
* Removes from this set all of its elements that are contained in the
|
jaroslav@557
|
324 |
* specified collection (optional operation). If the specified
|
jaroslav@557
|
325 |
* collection is also a set, this operation effectively modifies this
|
jaroslav@557
|
326 |
* set so that its value is the <i>asymmetric set difference</i> of
|
jaroslav@557
|
327 |
* the two sets.
|
jaroslav@557
|
328 |
*
|
jaroslav@557
|
329 |
* @param c collection containing elements to be removed from this set
|
jaroslav@557
|
330 |
* @return <tt>true</tt> if this set changed as a result of the call
|
jaroslav@557
|
331 |
* @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
|
jaroslav@557
|
332 |
* is not supported by this set
|
jaroslav@557
|
333 |
* @throws ClassCastException if the class of an element of this set
|
jaroslav@557
|
334 |
* is incompatible with the specified collection
|
jaroslav@557
|
335 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@557
|
336 |
* @throws NullPointerException if this set contains a null element and the
|
jaroslav@557
|
337 |
* specified collection does not permit null elements
|
jaroslav@557
|
338 |
* (<a href="Collection.html#optional-restrictions">optional</a>),
|
jaroslav@557
|
339 |
* or if the specified collection is null
|
jaroslav@557
|
340 |
* @see #remove(Object)
|
jaroslav@557
|
341 |
* @see #contains(Object)
|
jaroslav@557
|
342 |
*/
|
jaroslav@557
|
343 |
boolean removeAll(Collection<?> c);
|
jaroslav@557
|
344 |
|
jaroslav@557
|
345 |
/**
|
jaroslav@557
|
346 |
* Removes all of the elements from this set (optional operation).
|
jaroslav@557
|
347 |
* The set will be empty after this call returns.
|
jaroslav@557
|
348 |
*
|
jaroslav@557
|
349 |
* @throws UnsupportedOperationException if the <tt>clear</tt> method
|
jaroslav@557
|
350 |
* is not supported by this set
|
jaroslav@557
|
351 |
*/
|
jaroslav@557
|
352 |
void clear();
|
jaroslav@557
|
353 |
|
jaroslav@557
|
354 |
|
jaroslav@557
|
355 |
// Comparison and hashing
|
jaroslav@557
|
356 |
|
jaroslav@557
|
357 |
/**
|
jaroslav@557
|
358 |
* Compares the specified object with this set for equality. Returns
|
jaroslav@557
|
359 |
* <tt>true</tt> if the specified object is also a set, the two sets
|
jaroslav@557
|
360 |
* have the same size, and every member of the specified set is
|
jaroslav@557
|
361 |
* contained in this set (or equivalently, every member of this set is
|
jaroslav@557
|
362 |
* contained in the specified set). This definition ensures that the
|
jaroslav@557
|
363 |
* equals method works properly across different implementations of the
|
jaroslav@557
|
364 |
* set interface.
|
jaroslav@557
|
365 |
*
|
jaroslav@557
|
366 |
* @param o object to be compared for equality with this set
|
jaroslav@557
|
367 |
* @return <tt>true</tt> if the specified object is equal to this set
|
jaroslav@557
|
368 |
*/
|
jaroslav@557
|
369 |
boolean equals(Object o);
|
jaroslav@557
|
370 |
|
jaroslav@557
|
371 |
/**
|
jaroslav@557
|
372 |
* Returns the hash code value for this set. The hash code of a set is
|
jaroslav@557
|
373 |
* defined to be the sum of the hash codes of the elements in the set,
|
jaroslav@557
|
374 |
* where the hash code of a <tt>null</tt> element is defined to be zero.
|
jaroslav@557
|
375 |
* This ensures that <tt>s1.equals(s2)</tt> implies that
|
jaroslav@557
|
376 |
* <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
|
jaroslav@557
|
377 |
* and <tt>s2</tt>, as required by the general contract of
|
jaroslav@557
|
378 |
* {@link Object#hashCode}.
|
jaroslav@557
|
379 |
*
|
jaroslav@557
|
380 |
* @return the hash code value for this set
|
jaroslav@557
|
381 |
* @see Object#equals(Object)
|
jaroslav@557
|
382 |
* @see Set#equals(Object)
|
jaroslav@557
|
383 |
*/
|
jaroslav@557
|
384 |
int hashCode();
|
jaroslav@557
|
385 |
}
|