author | smarks |
Tue, 08 Dec 2015 13:48:22 -0800 | |
changeset 34527 | e3caf3a43d09 |
parent 32108 | aa5490a167ee |
child 37802 | 91fc9ac7b8b3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util; |
|
27 |
||
28 |
/** |
|
29 |
* A collection that contains no duplicate elements. More formally, sets |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
30 |
* contain no pair of elements {@code e1} and {@code e2} such that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
31 |
* {@code e1.equals(e2)}, and at most one null element. As implied by |
2 | 32 |
* its name, this interface models the mathematical <i>set</i> abstraction. |
33 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
34 |
* <p>The {@code Set} interface places additional stipulations, beyond those |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
35 |
* inherited from the {@code Collection} interface, on the contracts of all |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
36 |
* constructors and on the contracts of the {@code add}, {@code equals} and |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
37 |
* {@code hashCode} methods. Declarations for other inherited methods are |
2 | 38 |
* also included here for convenience. (The specifications accompanying these |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
39 |
* declarations have been tailored to the {@code Set} interface, but they do |
2 | 40 |
* not contain any additional stipulations.) |
41 |
* |
|
42 |
* <p>The additional stipulation on constructors is, not surprisingly, |
|
43 |
* that all constructors must create a set that contains no duplicate elements |
|
44 |
* (as defined above). |
|
45 |
* |
|
46 |
* <p>Note: Great care must be exercised if mutable objects are used as set |
|
47 |
* elements. The behavior of a set is not specified if the value of an object |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
48 |
* is changed in a manner that affects {@code equals} comparisons while the |
2 | 49 |
* object is an element in the set. A special case of this prohibition is |
50 |
* that it is not permissible for a set to contain itself as an element. |
|
51 |
* |
|
52 |
* <p>Some set implementations have restrictions on the elements that |
|
53 |
* they may contain. For example, some implementations prohibit null elements, |
|
54 |
* and some have restrictions on the types of their elements. Attempting to |
|
55 |
* add an ineligible element throws an unchecked exception, typically |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
56 |
* {@code NullPointerException} or {@code ClassCastException}. Attempting |
2 | 57 |
* to query the presence of an ineligible element may throw an exception, |
58 |
* or it may simply return false; some implementations will exhibit the former |
|
59 |
* behavior and some will exhibit the latter. More generally, attempting an |
|
60 |
* operation on an ineligible element whose completion would not result in |
|
61 |
* the insertion of an ineligible element into the set may throw an |
|
62 |
* exception or it may succeed, at the option of the implementation. |
|
63 |
* Such exceptions are marked as "optional" in the specification for this |
|
64 |
* interface. |
|
65 |
* |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
66 |
* <h2><a name="immutable">Immutable Set Static Factory Methods</a></h2> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
67 |
* <p>The {@link Set#of(Object...) Set.of()} static factory methods |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
68 |
* provide a convenient way to create immutable sets. The {@code Set} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
69 |
* instances created by these methods have the following characteristics: |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
70 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
71 |
* <ul> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
72 |
* <li>They are <em>structurally immutable</em>. Elements cannot be added or |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
73 |
* removed. Attempts to do so result in {@code UnsupportedOperationException}. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
74 |
* However, if the contained elements are themselves mutable, this may cause the |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
75 |
* Set to behave inconsistently or its contents to appear to change. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
76 |
* <li>They disallow {@code null} elements. Attempts to create them with |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
77 |
* {@code null} elements result in {@code NullPointerException}. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
78 |
* <li>They are serializable if all elements are serializable. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
79 |
* <li>They reject duplicate elements at creation time. Duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
80 |
* passed to a static factory method result in {@code IllegalArgumentException}. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
81 |
* <li>The iteration order of set elements is unspecified and is subject to change. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
82 |
* <li>They are <a href="../lang/doc-files/ValueBased.html">value-based</a>. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
83 |
* Callers should make no assumptions about the identity of the returned instances. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
84 |
* Factories are free to create new instances or reuse existing ones. Therefore, |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
85 |
* identity-sensitive operations on these instances (reference equality ({@code ==}), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
86 |
* identity hash code, and synchronization) are unreliable and should be avoided. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
87 |
* </ul> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
88 |
* |
2 | 89 |
* <p>This interface is a member of the |
90 |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
|
91 |
* Java Collections Framework</a>. |
|
92 |
* |
|
93 |
* @param <E> the type of elements maintained by this set |
|
94 |
* |
|
95 |
* @author Josh Bloch |
|
96 |
* @author Neal Gafter |
|
97 |
* @see Collection |
|
98 |
* @see List |
|
99 |
* @see SortedSet |
|
100 |
* @see HashSet |
|
101 |
* @see TreeSet |
|
102 |
* @see AbstractSet |
|
103 |
* @see Collections#singleton(java.lang.Object) |
|
104 |
* @see Collections#EMPTY_SET |
|
105 |
* @since 1.2 |
|
106 |
*/ |
|
107 |
||
108 |
public interface Set<E> extends Collection<E> { |
|
109 |
// Query Operations |
|
110 |
||
111 |
/** |
|
112 |
* Returns the number of elements in this set (its cardinality). If this |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
113 |
* set contains more than {@code Integer.MAX_VALUE} elements, returns |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
114 |
* {@code Integer.MAX_VALUE}. |
2 | 115 |
* |
116 |
* @return the number of elements in this set (its cardinality) |
|
117 |
*/ |
|
118 |
int size(); |
|
119 |
||
120 |
/** |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
121 |
* Returns {@code true} if this set contains no elements. |
2 | 122 |
* |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
123 |
* @return {@code true} if this set contains no elements |
2 | 124 |
*/ |
125 |
boolean isEmpty(); |
|
126 |
||
127 |
/** |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
128 |
* Returns {@code true} if this set contains the specified element. |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
129 |
* More formally, returns {@code true} if and only if this set |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
130 |
* contains an element {@code e} such that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
131 |
* {@code Objects.equals(o, e)}. |
2 | 132 |
* |
133 |
* @param o element whose presence in this set is to be tested |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
134 |
* @return {@code true} if this set contains the specified element |
2 | 135 |
* @throws ClassCastException if the type of the specified element |
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
136 |
* is incompatible with this set |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
137 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 138 |
* @throws NullPointerException if the specified element is null and this |
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
139 |
* set does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
140 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 141 |
*/ |
142 |
boolean contains(Object o); |
|
143 |
||
144 |
/** |
|
145 |
* Returns an iterator over the elements in this set. The elements are |
|
146 |
* returned in no particular order (unless this set is an instance of some |
|
147 |
* class that provides a guarantee). |
|
148 |
* |
|
149 |
* @return an iterator over the elements in this set |
|
150 |
*/ |
|
151 |
Iterator<E> iterator(); |
|
152 |
||
153 |
/** |
|
154 |
* Returns an array containing all of the elements in this set. |
|
155 |
* If this set makes any guarantees as to what order its elements |
|
156 |
* are returned by its iterator, this method must return the |
|
157 |
* elements in the same order. |
|
158 |
* |
|
159 |
* <p>The returned array will be "safe" in that no references to it |
|
160 |
* are maintained by this set. (In other words, this method must |
|
161 |
* allocate a new array even if this set is backed by an array). |
|
162 |
* The caller is thus free to modify the returned array. |
|
163 |
* |
|
164 |
* <p>This method acts as bridge between array-based and collection-based |
|
165 |
* APIs. |
|
166 |
* |
|
167 |
* @return an array containing all the elements in this set |
|
168 |
*/ |
|
169 |
Object[] toArray(); |
|
170 |
||
171 |
/** |
|
172 |
* Returns an array containing all of the elements in this set; the |
|
173 |
* runtime type of the returned array is that of the specified array. |
|
174 |
* If the set fits in the specified array, it is returned therein. |
|
175 |
* Otherwise, a new array is allocated with the runtime type of the |
|
176 |
* specified array and the size of this set. |
|
177 |
* |
|
178 |
* <p>If this set fits in the specified array with room to spare |
|
179 |
* (i.e., the array has more elements than this set), the element in |
|
180 |
* the array immediately following the end of the set is set to |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
181 |
* {@code null}. (This is useful in determining the length of this |
2 | 182 |
* set <i>only</i> if the caller knows that this set does not contain |
183 |
* any null elements.) |
|
184 |
* |
|
185 |
* <p>If this set makes any guarantees as to what order its elements |
|
186 |
* are returned by its iterator, this method must return the elements |
|
187 |
* in the same order. |
|
188 |
* |
|
189 |
* <p>Like the {@link #toArray()} method, this method acts as bridge between |
|
190 |
* array-based and collection-based APIs. Further, this method allows |
|
191 |
* precise control over the runtime type of the output array, and may, |
|
192 |
* under certain circumstances, be used to save allocation costs. |
|
193 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
194 |
* <p>Suppose {@code x} is a set known to contain only strings. |
2 | 195 |
* The following code can be used to dump the set into a newly allocated |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
196 |
* array of {@code String}: |
2 | 197 |
* |
198 |
* <pre> |
|
199 |
* String[] y = x.toArray(new String[0]);</pre> |
|
200 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
201 |
* Note that {@code toArray(new Object[0])} is identical in function to |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
202 |
* {@code toArray()}. |
2 | 203 |
* |
204 |
* @param a the array into which the elements of this set are to be |
|
205 |
* stored, if it is big enough; otherwise, a new array of the same |
|
206 |
* runtime type is allocated for this purpose. |
|
207 |
* @return an array containing all the elements in this set |
|
208 |
* @throws ArrayStoreException if the runtime type of the specified array |
|
209 |
* is not a supertype of the runtime type of every element in this |
|
210 |
* set |
|
211 |
* @throws NullPointerException if the specified array is null |
|
212 |
*/ |
|
213 |
<T> T[] toArray(T[] a); |
|
214 |
||
215 |
||
216 |
// Modification Operations |
|
217 |
||
218 |
/** |
|
219 |
* Adds the specified element to this set if it is not already present |
|
220 |
* (optional operation). More formally, adds the specified element |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
221 |
* {@code e} to this set if the set contains no element {@code e2} |
2 | 222 |
* such that |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
223 |
* {@code Objects.equals(e, e2)}. |
2 | 224 |
* If this set already contains the element, the call leaves the set |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
225 |
* unchanged and returns {@code false}. In combination with the |
2 | 226 |
* restriction on constructors, this ensures that sets never contain |
227 |
* duplicate elements. |
|
228 |
* |
|
229 |
* <p>The stipulation above does not imply that sets must accept all |
|
230 |
* elements; sets may refuse to add any particular element, including |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
231 |
* {@code null}, and throw an exception, as described in the |
2 | 232 |
* specification for {@link Collection#add Collection.add}. |
233 |
* Individual set implementations should clearly document any |
|
234 |
* restrictions on the elements that they may contain. |
|
235 |
* |
|
236 |
* @param e element to be added to this set |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
237 |
* @return {@code true} if this set did not already contain the specified |
2 | 238 |
* element |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
239 |
* @throws UnsupportedOperationException if the {@code add} operation |
2 | 240 |
* is not supported by this set |
241 |
* @throws ClassCastException if the class of the specified element |
|
242 |
* prevents it from being added to this set |
|
243 |
* @throws NullPointerException if the specified element is null and this |
|
244 |
* set does not permit null elements |
|
245 |
* @throws IllegalArgumentException if some property of the specified element |
|
246 |
* prevents it from being added to this set |
|
247 |
*/ |
|
248 |
boolean add(E e); |
|
249 |
||
250 |
||
251 |
/** |
|
252 |
* Removes the specified element from this set if it is present |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
253 |
* (optional operation). More formally, removes an element {@code e} |
2 | 254 |
* such that |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
255 |
* {@code Objects.equals(o, e)}, if |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
256 |
* this set contains such an element. Returns {@code true} if this set |
2 | 257 |
* contained the element (or equivalently, if this set changed as a |
258 |
* result of the call). (This set will not contain the element once the |
|
259 |
* call returns.) |
|
260 |
* |
|
261 |
* @param o object to be removed from this set, if present |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
262 |
* @return {@code true} if this set contained the specified element |
2 | 263 |
* @throws ClassCastException if the type of the specified element |
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
264 |
* is incompatible with this set |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
265 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 266 |
* @throws NullPointerException if the specified element is null and this |
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
267 |
* set does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
268 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
269 |
* @throws UnsupportedOperationException if the {@code remove} operation |
2 | 270 |
* is not supported by this set |
271 |
*/ |
|
272 |
boolean remove(Object o); |
|
273 |
||
274 |
||
275 |
// Bulk Operations |
|
276 |
||
277 |
/** |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
278 |
* Returns {@code true} if this set contains all of the elements of the |
2 | 279 |
* specified collection. If the specified collection is also a set, this |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
280 |
* method returns {@code true} if it is a <i>subset</i> of this set. |
2 | 281 |
* |
282 |
* @param c collection to be checked for containment in this set |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
283 |
* @return {@code true} if this set contains all of the elements of the |
2 | 284 |
* specified collection |
285 |
* @throws ClassCastException if the types of one or more elements |
|
286 |
* in the specified collection are incompatible with this |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
287 |
* set |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
288 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 289 |
* @throws NullPointerException if the specified collection contains one |
290 |
* or more null elements and this set does not permit null |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
291 |
* elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
292 |
* (<a href="Collection.html#optional-restrictions">optional</a>), |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
293 |
* or if the specified collection is null |
2 | 294 |
* @see #contains(Object) |
295 |
*/ |
|
296 |
boolean containsAll(Collection<?> c); |
|
297 |
||
298 |
/** |
|
299 |
* Adds all of the elements in the specified collection to this set if |
|
300 |
* they're not already present (optional operation). If the specified |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
301 |
* collection is also a set, the {@code addAll} operation effectively |
2 | 302 |
* modifies this set so that its value is the <i>union</i> of the two |
303 |
* sets. The behavior of this operation is undefined if the specified |
|
304 |
* collection is modified while the operation is in progress. |
|
305 |
* |
|
306 |
* @param c collection containing elements to be added to this set |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
307 |
* @return {@code true} if this set changed as a result of the call |
2 | 308 |
* |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
309 |
* @throws UnsupportedOperationException if the {@code addAll} operation |
2 | 310 |
* is not supported by this set |
311 |
* @throws ClassCastException if the class of an element of the |
|
312 |
* specified collection prevents it from being added to this set |
|
313 |
* @throws NullPointerException if the specified collection contains one |
|
314 |
* or more null elements and this set does not permit null |
|
315 |
* elements, or if the specified collection is null |
|
316 |
* @throws IllegalArgumentException if some property of an element of the |
|
317 |
* specified collection prevents it from being added to this set |
|
318 |
* @see #add(Object) |
|
319 |
*/ |
|
320 |
boolean addAll(Collection<? extends E> c); |
|
321 |
||
322 |
/** |
|
323 |
* Retains only the elements in this set that are contained in the |
|
324 |
* specified collection (optional operation). In other words, removes |
|
325 |
* from this set all of its elements that are not contained in the |
|
326 |
* specified collection. If the specified collection is also a set, this |
|
327 |
* operation effectively modifies this set so that its value is the |
|
328 |
* <i>intersection</i> of the two sets. |
|
329 |
* |
|
330 |
* @param c collection containing elements to be retained in this set |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
331 |
* @return {@code true} if this set changed as a result of the call |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
332 |
* @throws UnsupportedOperationException if the {@code retainAll} operation |
2 | 333 |
* is not supported by this set |
334 |
* @throws ClassCastException if the class of an element of this set |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
335 |
* is incompatible with the specified collection |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
336 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 337 |
* @throws NullPointerException if this set contains a null element and the |
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
338 |
* specified collection does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
339 |
* (<a href="Collection.html#optional-restrictions">optional</a>), |
2 | 340 |
* or if the specified collection is null |
341 |
* @see #remove(Object) |
|
342 |
*/ |
|
343 |
boolean retainAll(Collection<?> c); |
|
344 |
||
345 |
/** |
|
346 |
* Removes from this set all of its elements that are contained in the |
|
347 |
* specified collection (optional operation). If the specified |
|
348 |
* collection is also a set, this operation effectively modifies this |
|
349 |
* set so that its value is the <i>asymmetric set difference</i> of |
|
350 |
* the two sets. |
|
351 |
* |
|
352 |
* @param c collection containing elements to be removed from this set |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
353 |
* @return {@code true} if this set changed as a result of the call |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
354 |
* @throws UnsupportedOperationException if the {@code removeAll} operation |
2 | 355 |
* is not supported by this set |
356 |
* @throws ClassCastException if the class of an element of this set |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
357 |
* is incompatible with the specified collection |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
358 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 359 |
* @throws NullPointerException if this set contains a null element and the |
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
360 |
* specified collection does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
5506
diff
changeset
|
361 |
* (<a href="Collection.html#optional-restrictions">optional</a>), |
2 | 362 |
* or if the specified collection is null |
363 |
* @see #remove(Object) |
|
364 |
* @see #contains(Object) |
|
365 |
*/ |
|
366 |
boolean removeAll(Collection<?> c); |
|
367 |
||
368 |
/** |
|
369 |
* Removes all of the elements from this set (optional operation). |
|
370 |
* The set will be empty after this call returns. |
|
371 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
372 |
* @throws UnsupportedOperationException if the {@code clear} method |
2 | 373 |
* is not supported by this set |
374 |
*/ |
|
375 |
void clear(); |
|
376 |
||
377 |
||
378 |
// Comparison and hashing |
|
379 |
||
380 |
/** |
|
381 |
* Compares the specified object with this set for equality. Returns |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
382 |
* {@code true} if the specified object is also a set, the two sets |
2 | 383 |
* have the same size, and every member of the specified set is |
384 |
* contained in this set (or equivalently, every member of this set is |
|
385 |
* contained in the specified set). This definition ensures that the |
|
386 |
* equals method works properly across different implementations of the |
|
387 |
* set interface. |
|
388 |
* |
|
389 |
* @param o object to be compared for equality with this set |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
390 |
* @return {@code true} if the specified object is equal to this set |
2 | 391 |
*/ |
392 |
boolean equals(Object o); |
|
393 |
||
394 |
/** |
|
395 |
* Returns the hash code value for this set. The hash code of a set is |
|
396 |
* defined to be the sum of the hash codes of the elements in the set, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
397 |
* where the hash code of a {@code null} element is defined to be zero. |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
398 |
* This ensures that {@code s1.equals(s2)} implies that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
399 |
* {@code s1.hashCode()==s2.hashCode()} for any two sets {@code s1} |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
400 |
* and {@code s2}, as required by the general contract of |
2 | 401 |
* {@link Object#hashCode}. |
402 |
* |
|
403 |
* @return the hash code value for this set |
|
404 |
* @see Object#equals(Object) |
|
405 |
* @see Set#equals(Object) |
|
406 |
*/ |
|
407 |
int hashCode(); |
|
16929
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
408 |
|
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
409 |
/** |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
410 |
* Creates a {@code Spliterator} over the elements in this set. |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
411 |
* |
20489
cce02e4a6cbe
8024408: Specifications for Collection/List/Set/SortedSet.spliterator() need to document if all the (subclass) instances are required to return SIZED spliterators
psandoz
parents:
19435
diff
changeset
|
412 |
* <p>The {@code Spliterator} reports {@link Spliterator#DISTINCT}. |
cce02e4a6cbe
8024408: Specifications for Collection/List/Set/SortedSet.spliterator() need to document if all the (subclass) instances are required to return SIZED spliterators
psandoz
parents:
19435
diff
changeset
|
413 |
* Implementations should document the reporting of additional |
cce02e4a6cbe
8024408: Specifications for Collection/List/Set/SortedSet.spliterator() need to document if all the (subclass) instances are required to return SIZED spliterators
psandoz
parents:
19435
diff
changeset
|
414 |
* characteristic values. |
16929
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
415 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
416 |
* @implSpec |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
417 |
* The default implementation creates a |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
418 |
* <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
419 |
* from the set's {@code Iterator}. The spliterator inherits the |
19435
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
16929
diff
changeset
|
420 |
* <em>fail-fast</em> properties of the set's iterator. |
20489
cce02e4a6cbe
8024408: Specifications for Collection/List/Set/SortedSet.spliterator() need to document if all the (subclass) instances are required to return SIZED spliterators
psandoz
parents:
19435
diff
changeset
|
421 |
* <p> |
cce02e4a6cbe
8024408: Specifications for Collection/List/Set/SortedSet.spliterator() need to document if all the (subclass) instances are required to return SIZED spliterators
psandoz
parents:
19435
diff
changeset
|
422 |
* The created {@code Spliterator} additionally reports |
cce02e4a6cbe
8024408: Specifications for Collection/List/Set/SortedSet.spliterator() need to document if all the (subclass) instances are required to return SIZED spliterators
psandoz
parents:
19435
diff
changeset
|
423 |
* {@link Spliterator#SIZED}. |
16929
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
424 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
425 |
* @implNote |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
426 |
* The created {@code Spliterator} additionally reports |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
427 |
* {@link Spliterator#SUBSIZED}. |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
428 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
429 |
* @return a {@code Spliterator} over the elements in this set |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
430 |
* @since 1.8 |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
431 |
*/ |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
432 |
@Override |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
433 |
default Spliterator<E> spliterator() { |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
434 |
return Spliterators.spliterator(this, Spliterator.DISTINCT); |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
435 |
} |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
436 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
437 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
438 |
* Returns an immutable set containing zero elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
439 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
440 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
441 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
442 |
* @return an empty {@code Set} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
443 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
444 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
445 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
446 |
static <E> Set<E> of() { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
447 |
return Collections.emptySet(); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
448 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
449 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
450 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
451 |
* Returns an immutable set containing one element. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
452 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
453 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
454 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
455 |
* @param e1 the single element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
456 |
* @return a {@code Set} containing the specified element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
457 |
* @throws NullPointerException if the element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
458 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
459 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
460 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
461 |
static <E> Set<E> of(E e1) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
462 |
return Collections.singleton(Objects.requireNonNull(e1)); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
463 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
464 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
465 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
466 |
* Returns an immutable set containing two elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
467 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
468 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
469 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
470 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
471 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
472 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
473 |
* @throws IllegalArgumentException if the elements are duplicates |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
474 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
475 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
476 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
477 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
478 |
static <E> Set<E> of(E e1, E e2) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
479 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
480 |
Objects.requireNonNull(e2))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
481 |
if (set.size() != 2) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
482 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
483 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
484 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
485 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
486 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
487 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
488 |
* Returns an immutable set containing three elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
489 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
490 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
491 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
492 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
493 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
494 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
495 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
496 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
497 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
498 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
499 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
500 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
501 |
static <E> Set<E> of(E e1, E e2, E e3) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
502 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
503 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
504 |
Objects.requireNonNull(e3))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
505 |
if (set.size() != 3) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
506 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
507 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
508 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
509 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
510 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
511 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
512 |
* Returns an immutable set containing four elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
513 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
514 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
515 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
516 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
517 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
518 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
519 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
520 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
521 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
522 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
523 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
524 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
525 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
526 |
static <E> Set<E> of(E e1, E e2, E e3, E e4) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
527 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
528 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
529 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
530 |
Objects.requireNonNull(e4))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
531 |
if (set.size() != 4) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
532 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
533 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
534 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
535 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
536 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
537 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
538 |
* Returns an immutable set containing five elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
539 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
540 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
541 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
542 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
543 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
544 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
545 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
546 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
547 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
548 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
549 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
550 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
551 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
552 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
553 |
static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
554 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
555 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
556 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
557 |
Objects.requireNonNull(e4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
558 |
Objects.requireNonNull(e5))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
559 |
if (set.size() != 5) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
560 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
561 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
562 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
563 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
564 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
565 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
566 |
* Returns an immutable set containing six elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
567 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
568 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
569 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
570 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
571 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
572 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
573 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
574 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
575 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
576 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
577 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
578 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
579 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
580 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
581 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
582 |
static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
583 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
584 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
585 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
586 |
Objects.requireNonNull(e4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
587 |
Objects.requireNonNull(e5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
588 |
Objects.requireNonNull(e6))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
589 |
if (set.size() != 6) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
590 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
591 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
592 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
593 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
594 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
595 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
596 |
* Returns an immutable set containing seven elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
597 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
598 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
599 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
600 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
601 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
602 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
603 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
604 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
605 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
606 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
607 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
608 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
609 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
610 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
611 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
612 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
613 |
static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
614 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
615 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
616 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
617 |
Objects.requireNonNull(e4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
618 |
Objects.requireNonNull(e5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
619 |
Objects.requireNonNull(e6), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
620 |
Objects.requireNonNull(e7))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
621 |
if (set.size() != 7) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
622 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
623 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
624 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
625 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
626 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
627 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
628 |
* Returns an immutable set containing eight elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
629 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
630 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
631 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
632 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
633 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
634 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
635 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
636 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
637 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
638 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
639 |
* @param e8 the eighth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
640 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
641 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
642 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
643 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
644 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
645 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
646 |
static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
647 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
648 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
649 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
650 |
Objects.requireNonNull(e4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
651 |
Objects.requireNonNull(e5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
652 |
Objects.requireNonNull(e6), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
653 |
Objects.requireNonNull(e7), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
654 |
Objects.requireNonNull(e8))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
655 |
if (set.size() != 8) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
656 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
657 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
658 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
659 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
660 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
661 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
662 |
* Returns an immutable set containing nine elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
663 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
664 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
665 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
666 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
667 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
668 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
669 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
670 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
671 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
672 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
673 |
* @param e8 the eighth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
674 |
* @param e9 the ninth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
675 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
676 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
677 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
678 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
679 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
680 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
681 |
static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
682 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
683 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
684 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
685 |
Objects.requireNonNull(e4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
686 |
Objects.requireNonNull(e5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
687 |
Objects.requireNonNull(e6), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
688 |
Objects.requireNonNull(e7), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
689 |
Objects.requireNonNull(e8), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
690 |
Objects.requireNonNull(e9))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
691 |
if (set.size() != 9) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
692 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
693 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
694 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
695 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
696 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
697 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
698 |
* Returns an immutable set containing ten elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
699 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
700 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
701 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
702 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
703 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
704 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
705 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
706 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
707 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
708 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
709 |
* @param e8 the eighth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
710 |
* @param e9 the ninth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
711 |
* @param e10 the tenth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
712 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
713 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
714 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
715 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
716 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
717 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
718 |
static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
719 |
Set<E> set = new HashSet<>(Arrays.asList(Objects.requireNonNull(e1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
720 |
Objects.requireNonNull(e2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
721 |
Objects.requireNonNull(e3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
722 |
Objects.requireNonNull(e4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
723 |
Objects.requireNonNull(e5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
724 |
Objects.requireNonNull(e6), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
725 |
Objects.requireNonNull(e7), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
726 |
Objects.requireNonNull(e8), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
727 |
Objects.requireNonNull(e9), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
728 |
Objects.requireNonNull(e10))); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
729 |
if (set.size() != 10) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
730 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
731 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
732 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
733 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
734 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
735 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
736 |
* Returns an immutable set containing an arbitrary number of elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
737 |
* See <a href="#immutable">Immutable Set Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
738 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
739 |
* @apiNote |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
740 |
* This method also accepts a single array as an argument. The element type of |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
741 |
* the resulting set will be the component type of the array, and the size of |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
742 |
* the set will be equal to the length of the array. To create a set with |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
743 |
* a single element that is an array, do the following: |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
744 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
745 |
* <pre>{@code |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
746 |
* String[] array = ... ; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
747 |
* Set<String[]> list = Set.<String[]>of(array); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
748 |
* }</pre> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
749 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
750 |
* This will cause the {@link Set#of(Object) Set.of(E)} method |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
751 |
* to be invoked instead. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
752 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
753 |
* @param <E> the {@code Set}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
754 |
* @param elements the elements to be contained in the set |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
755 |
* @return a {@code Set} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
756 |
* @throws IllegalArgumentException if there are any duplicate elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
757 |
* @throws NullPointerException if an element is {@code null} or if the array is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
758 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
759 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
760 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
761 |
@SafeVarargs |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
762 |
static <E> Set<E> of(E... elements) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
763 |
for (E e : elements) { // throws NPE if es is null |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
764 |
Objects.requireNonNull(e); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
765 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
766 |
@SuppressWarnings("varargs") |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
767 |
Set<E> set = new HashSet<>(Arrays.asList(elements)); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
768 |
if (set.size() != elements.length) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
769 |
throw new IllegalArgumentException("duplicate elements"); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
770 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
771 |
return Collections.unmodifiableSet(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
772 |
} |
2 | 773 |
} |