author | psandoz |
Mon, 23 May 2016 23:12:05 +0800 | |
changeset 39568 | 1987f3929c39 |
parent 38567 | 6d4c5a278fff |
child 40788 | 01ffe34b7340 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
38567 | 2 |
* Copyright (c) 1997, 2016, 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 |
||
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
28 |
import java.util.function.UnaryOperator; |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
29 |
|
2 | 30 |
/** |
31 |
* An ordered collection (also known as a <i>sequence</i>). The user of this |
|
32 |
* interface has precise control over where in the list each element is |
|
33 |
* inserted. The user can access elements by their integer index (position in |
|
34 |
* the list), and search for elements in the list.<p> |
|
35 |
* |
|
36 |
* Unlike sets, lists typically allow duplicate elements. More formally, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
37 |
* lists typically allow pairs of elements {@code e1} and {@code e2} |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
38 |
* such that {@code e1.equals(e2)}, and they typically allow multiple |
2 | 39 |
* null elements if they allow null elements at all. It is not inconceivable |
40 |
* that someone might wish to implement a list that prohibits duplicates, by |
|
41 |
* throwing runtime exceptions when the user attempts to insert them, but we |
|
42 |
* expect this usage to be rare.<p> |
|
43 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
44 |
* The {@code List} interface places additional stipulations, beyond those |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
45 |
* specified in the {@code Collection} interface, on the contracts of the |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
46 |
* {@code iterator}, {@code add}, {@code remove}, {@code equals}, and |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
47 |
* {@code hashCode} methods. Declarations for other inherited methods are |
2 | 48 |
* also included here for convenience.<p> |
49 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
50 |
* The {@code List} interface provides four methods for positional (indexed) |
2 | 51 |
* access to list elements. Lists (like Java arrays) are zero based. Note |
52 |
* that these operations may execute in time proportional to the index value |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
53 |
* for some implementations (the {@code LinkedList} class, for |
2 | 54 |
* example). Thus, iterating over the elements in a list is typically |
55 |
* preferable to indexing through it if the caller does not know the |
|
56 |
* implementation.<p> |
|
57 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
58 |
* The {@code List} interface provides a special iterator, called a |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
59 |
* {@code ListIterator}, that allows element insertion and replacement, and |
2 | 60 |
* bidirectional access in addition to the normal operations that the |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
61 |
* {@code Iterator} interface provides. A method is provided to obtain a |
2 | 62 |
* list iterator that starts at a specified position in the list.<p> |
63 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
64 |
* The {@code List} interface provides two methods to search for a specified |
2 | 65 |
* object. From a performance standpoint, these methods should be used with |
66 |
* caution. In many implementations they will perform costly linear |
|
67 |
* searches.<p> |
|
68 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
69 |
* The {@code List} interface provides two methods to efficiently insert and |
2 | 70 |
* remove multiple elements at an arbitrary point in the list.<p> |
71 |
* |
|
72 |
* Note: While it is permissible for lists to contain themselves as elements, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
73 |
* extreme caution is advised: the {@code equals} and {@code hashCode} |
2 | 74 |
* methods are no longer well defined on such a list. |
75 |
* |
|
76 |
* <p>Some list implementations have restrictions on the elements that |
|
77 |
* they may contain. For example, some implementations prohibit null elements, |
|
78 |
* and some have restrictions on the types of their elements. Attempting to |
|
79 |
* 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
|
80 |
* {@code NullPointerException} or {@code ClassCastException}. Attempting |
2 | 81 |
* to query the presence of an ineligible element may throw an exception, |
82 |
* or it may simply return false; some implementations will exhibit the former |
|
83 |
* behavior and some will exhibit the latter. More generally, attempting an |
|
84 |
* operation on an ineligible element whose completion would not result in |
|
85 |
* the insertion of an ineligible element into the list may throw an |
|
86 |
* exception or it may succeed, at the option of the implementation. |
|
87 |
* Such exceptions are marked as "optional" in the specification for this |
|
88 |
* interface. |
|
89 |
* |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
90 |
* <h2><a name="immutable">Immutable List Static Factory Methods</a></h2> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
91 |
* <p>The {@link List#of(Object...) List.of()} static factory methods |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
92 |
* provide a convenient way to create immutable lists. The {@code List} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
93 |
* instances created by these methods have the following characteristics: |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
94 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
95 |
* <ul> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
96 |
* <li>They are <em>structurally immutable</em>. Elements cannot be added, removed, |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
97 |
* or replaced. Attempts to do so result in {@code UnsupportedOperationException}. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
98 |
* However, if the contained elements are themselves mutable, |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
99 |
* this may cause the List's contents to appear to change. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
100 |
* <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
|
101 |
* {@code null} elements result in {@code NullPointerException}. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
102 |
* <li>They are serializable if all elements are serializable. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
103 |
* <li>The order of elements in the list is the same as the order of the |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
104 |
* provided arguments, or of the elements in the provided array. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
105 |
* <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
|
106 |
* 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
|
107 |
* 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
|
108 |
* identity-sensitive operations on these instances (reference equality ({@code ==}), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
109 |
* identity hash code, and synchronization) are unreliable and should be avoided. |
38567 | 110 |
* <li>They are serialized as specified on the |
111 |
* <a href="{@docRoot}/serialized-form.html#java.util.CollSer">Serialized Form</a> |
|
112 |
* page. |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
113 |
* </ul> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
114 |
* |
2 | 115 |
* <p>This interface is a member of the |
116 |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
|
117 |
* Java Collections Framework</a>. |
|
118 |
* |
|
4977
81902a400bbf
6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents:
2
diff
changeset
|
119 |
* @param <E> the type of elements in this list |
81902a400bbf
6929382: Various core classes in util and elsewhere are missing @param <T> tags
darcy
parents:
2
diff
changeset
|
120 |
* |
2 | 121 |
* @author Josh Bloch |
122 |
* @author Neal Gafter |
|
123 |
* @see Collection |
|
124 |
* @see Set |
|
125 |
* @see ArrayList |
|
126 |
* @see LinkedList |
|
127 |
* @see Vector |
|
128 |
* @see Arrays#asList(Object[]) |
|
129 |
* @see Collections#nCopies(int, Object) |
|
130 |
* @see Collections#EMPTY_LIST |
|
131 |
* @see AbstractList |
|
132 |
* @see AbstractSequentialList |
|
133 |
* @since 1.2 |
|
134 |
*/ |
|
135 |
||
136 |
public interface List<E> extends Collection<E> { |
|
137 |
// Query Operations |
|
138 |
||
139 |
/** |
|
140 |
* Returns the number of elements in this list. If this list contains |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
141 |
* 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
|
142 |
* {@code Integer.MAX_VALUE}. |
2 | 143 |
* |
144 |
* @return the number of elements in this list |
|
145 |
*/ |
|
146 |
int size(); |
|
147 |
||
148 |
/** |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
149 |
* Returns {@code true} if this list contains no elements. |
2 | 150 |
* |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
151 |
* @return {@code true} if this list contains no elements |
2 | 152 |
*/ |
153 |
boolean isEmpty(); |
|
154 |
||
155 |
/** |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
156 |
* Returns {@code true} if this list contains the specified element. |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
157 |
* More formally, returns {@code true} if and only if this list contains |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
158 |
* at least one element {@code e} such that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
159 |
* {@code Objects.equals(o, e)}. |
2 | 160 |
* |
161 |
* @param o element whose presence in this list is to be tested |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
162 |
* @return {@code true} if this list contains the specified element |
2 | 163 |
* @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:
7668
diff
changeset
|
164 |
* is incompatible with this list |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
165 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 166 |
* @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:
7668
diff
changeset
|
167 |
* list does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
168 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 169 |
*/ |
170 |
boolean contains(Object o); |
|
171 |
||
172 |
/** |
|
173 |
* Returns an iterator over the elements in this list in proper sequence. |
|
174 |
* |
|
175 |
* @return an iterator over the elements in this list in proper sequence |
|
176 |
*/ |
|
177 |
Iterator<E> iterator(); |
|
178 |
||
179 |
/** |
|
180 |
* Returns an array containing all of the elements in this list in proper |
|
181 |
* sequence (from first to last element). |
|
182 |
* |
|
183 |
* <p>The returned array will be "safe" in that no references to it are |
|
184 |
* maintained by this list. (In other words, this method must |
|
185 |
* allocate a new array even if this list is backed by an array). |
|
186 |
* The caller is thus free to modify the returned array. |
|
187 |
* |
|
188 |
* <p>This method acts as bridge between array-based and collection-based |
|
189 |
* APIs. |
|
190 |
* |
|
191 |
* @return an array containing all of the elements in this list in proper |
|
192 |
* sequence |
|
193 |
* @see Arrays#asList(Object[]) |
|
194 |
*/ |
|
195 |
Object[] toArray(); |
|
196 |
||
197 |
/** |
|
198 |
* Returns an array containing all of the elements in this list in |
|
199 |
* proper sequence (from first to last element); the runtime type of |
|
200 |
* the returned array is that of the specified array. If the list fits |
|
201 |
* in the specified array, it is returned therein. Otherwise, a new |
|
202 |
* array is allocated with the runtime type of the specified array and |
|
203 |
* the size of this list. |
|
204 |
* |
|
205 |
* <p>If the list fits in the specified array with room to spare (i.e., |
|
206 |
* the array has more elements than the list), the element in the array |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
207 |
* immediately following the end of the list is set to {@code null}. |
2 | 208 |
* (This is useful in determining the length of the list <i>only</i> if |
209 |
* the caller knows that the list does not contain any null elements.) |
|
210 |
* |
|
211 |
* <p>Like the {@link #toArray()} method, this method acts as bridge between |
|
212 |
* array-based and collection-based APIs. Further, this method allows |
|
213 |
* precise control over the runtime type of the output array, and may, |
|
214 |
* under certain circumstances, be used to save allocation costs. |
|
215 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
216 |
* <p>Suppose {@code x} is a list known to contain only strings. |
2 | 217 |
* The following code can be used to dump the list into a newly |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
218 |
* allocated array of {@code String}: |
2 | 219 |
* |
21339 | 220 |
* <pre>{@code |
221 |
* String[] y = x.toArray(new String[0]); |
|
222 |
* }</pre> |
|
2 | 223 |
* |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
224 |
* 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
|
225 |
* {@code toArray()}. |
2 | 226 |
* |
227 |
* @param a the array into which the elements of this list are to |
|
228 |
* be stored, if it is big enough; otherwise, a new array of the |
|
229 |
* same runtime type is allocated for this purpose. |
|
230 |
* @return an array containing the elements of this list |
|
231 |
* @throws ArrayStoreException if the runtime type of the specified array |
|
232 |
* is not a supertype of the runtime type of every element in |
|
233 |
* this list |
|
234 |
* @throws NullPointerException if the specified array is null |
|
235 |
*/ |
|
236 |
<T> T[] toArray(T[] a); |
|
237 |
||
238 |
||
239 |
// Modification Operations |
|
240 |
||
241 |
/** |
|
242 |
* Appends the specified element to the end of this list (optional |
|
243 |
* operation). |
|
244 |
* |
|
245 |
* <p>Lists that support this operation may place limitations on what |
|
246 |
* elements may be added to this list. In particular, some |
|
247 |
* lists will refuse to add null elements, and others will impose |
|
248 |
* restrictions on the type of elements that may be added. List |
|
249 |
* classes should clearly specify in their documentation any restrictions |
|
250 |
* on what elements may be added. |
|
251 |
* |
|
252 |
* @param e element to be appended to this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
253 |
* @return {@code true} (as specified by {@link Collection#add}) |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
254 |
* @throws UnsupportedOperationException if the {@code add} operation |
2 | 255 |
* is not supported by this list |
256 |
* @throws ClassCastException if the class of the specified element |
|
257 |
* prevents it from being added to this list |
|
258 |
* @throws NullPointerException if the specified element is null and this |
|
259 |
* list does not permit null elements |
|
260 |
* @throws IllegalArgumentException if some property of this element |
|
261 |
* prevents it from being added to this list |
|
262 |
*/ |
|
263 |
boolean add(E e); |
|
264 |
||
265 |
/** |
|
266 |
* Removes the first occurrence of the specified element from this list, |
|
267 |
* if it is present (optional operation). If this list does not contain |
|
268 |
* the element, it is unchanged. More formally, removes the element with |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
269 |
* the lowest index {@code i} such that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
270 |
* {@code Objects.equals(o, get(i))} |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
271 |
* (if such an element exists). Returns {@code true} if this list |
2 | 272 |
* contained the specified element (or equivalently, if this list changed |
273 |
* as a result of the call). |
|
274 |
* |
|
275 |
* @param o element to be removed from this list, if present |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
276 |
* @return {@code true} if this list contained the specified element |
2 | 277 |
* @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:
7668
diff
changeset
|
278 |
* is incompatible with this list |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
279 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 280 |
* @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:
7668
diff
changeset
|
281 |
* list does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
282 |
* (<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
|
283 |
* @throws UnsupportedOperationException if the {@code remove} operation |
2 | 284 |
* is not supported by this list |
285 |
*/ |
|
286 |
boolean remove(Object o); |
|
287 |
||
288 |
||
289 |
// Bulk Modification Operations |
|
290 |
||
291 |
/** |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
292 |
* Returns {@code true} if this list contains all of the elements of the |
2 | 293 |
* specified collection. |
294 |
* |
|
295 |
* @param c collection to be checked for containment in this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
296 |
* @return {@code true} if this list contains all of the elements of the |
2 | 297 |
* specified collection |
298 |
* @throws ClassCastException if the types of one or more elements |
|
299 |
* 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:
7668
diff
changeset
|
300 |
* list |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
301 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 302 |
* @throws NullPointerException if the specified collection contains one |
303 |
* or more null elements and this list does not permit null |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
304 |
* elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
305 |
* (<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:
7668
diff
changeset
|
306 |
* or if the specified collection is null |
2 | 307 |
* @see #contains(Object) |
308 |
*/ |
|
309 |
boolean containsAll(Collection<?> c); |
|
310 |
||
311 |
/** |
|
312 |
* Appends all of the elements in the specified collection to the end of |
|
313 |
* this list, in the order that they are returned by the specified |
|
314 |
* collection's iterator (optional operation). The behavior of this |
|
315 |
* operation is undefined if the specified collection is modified while |
|
316 |
* the operation is in progress. (Note that this will occur if the |
|
317 |
* specified collection is this list, and it's nonempty.) |
|
318 |
* |
|
319 |
* @param c collection containing elements to be added to this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
320 |
* @return {@code true} if this list changed as a result of the call |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
321 |
* @throws UnsupportedOperationException if the {@code addAll} operation |
2 | 322 |
* is not supported by this list |
323 |
* @throws ClassCastException if the class of an element of the specified |
|
324 |
* collection prevents it from being added to this list |
|
325 |
* @throws NullPointerException if the specified collection contains one |
|
326 |
* or more null elements and this list does not permit null |
|
327 |
* elements, or if the specified collection is null |
|
328 |
* @throws IllegalArgumentException if some property of an element of the |
|
329 |
* specified collection prevents it from being added to this list |
|
330 |
* @see #add(Object) |
|
331 |
*/ |
|
332 |
boolean addAll(Collection<? extends E> c); |
|
333 |
||
334 |
/** |
|
335 |
* Inserts all of the elements in the specified collection into this |
|
336 |
* list at the specified position (optional operation). Shifts the |
|
337 |
* element currently at that position (if any) and any subsequent |
|
338 |
* elements to the right (increases their indices). The new elements |
|
339 |
* will appear in this list in the order that they are returned by the |
|
340 |
* specified collection's iterator. The behavior of this operation is |
|
341 |
* undefined if the specified collection is modified while the |
|
342 |
* operation is in progress. (Note that this will occur if the specified |
|
343 |
* collection is this list, and it's nonempty.) |
|
344 |
* |
|
345 |
* @param index index at which to insert the first element from the |
|
346 |
* specified collection |
|
347 |
* @param c collection containing elements to be added to this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
348 |
* @return {@code true} if this list changed as a result of the call |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
349 |
* @throws UnsupportedOperationException if the {@code addAll} operation |
2 | 350 |
* is not supported by this list |
351 |
* @throws ClassCastException if the class of an element of the specified |
|
352 |
* collection prevents it from being added to this list |
|
353 |
* @throws NullPointerException if the specified collection contains one |
|
354 |
* or more null elements and this list does not permit null |
|
355 |
* elements, or if the specified collection is null |
|
356 |
* @throws IllegalArgumentException if some property of an element of the |
|
357 |
* specified collection prevents it from being added to this list |
|
358 |
* @throws IndexOutOfBoundsException if the index is out of range |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
359 |
* ({@code index < 0 || index > size()}) |
2 | 360 |
*/ |
361 |
boolean addAll(int index, Collection<? extends E> c); |
|
362 |
||
363 |
/** |
|
364 |
* Removes from this list all of its elements that are contained in the |
|
365 |
* specified collection (optional operation). |
|
366 |
* |
|
367 |
* @param c collection containing elements to be removed from this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
368 |
* @return {@code true} if this list changed as a result of the call |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
369 |
* @throws UnsupportedOperationException if the {@code removeAll} operation |
2 | 370 |
* is not supported by this list |
371 |
* @throws ClassCastException if the class of an element of this list |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
372 |
* 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:
7668
diff
changeset
|
373 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 374 |
* @throws NullPointerException if this list 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:
7668
diff
changeset
|
375 |
* 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:
7668
diff
changeset
|
376 |
* (<a href="Collection.html#optional-restrictions">optional</a>), |
2 | 377 |
* or if the specified collection is null |
378 |
* @see #remove(Object) |
|
379 |
* @see #contains(Object) |
|
380 |
*/ |
|
381 |
boolean removeAll(Collection<?> c); |
|
382 |
||
383 |
/** |
|
384 |
* Retains only the elements in this list that are contained in the |
|
385 |
* specified collection (optional operation). In other words, removes |
|
386 |
* from this list all of its elements that are not contained in the |
|
387 |
* specified collection. |
|
388 |
* |
|
389 |
* @param c collection containing elements to be retained in this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
390 |
* @return {@code true} if this list changed as a result of the call |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
391 |
* @throws UnsupportedOperationException if the {@code retainAll} operation |
2 | 392 |
* is not supported by this list |
393 |
* @throws ClassCastException if the class of an element of this list |
|
9503
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
394 |
* 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:
7668
diff
changeset
|
395 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 396 |
* @throws NullPointerException if this list 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:
7668
diff
changeset
|
397 |
* 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:
7668
diff
changeset
|
398 |
* (<a href="Collection.html#optional-restrictions">optional</a>), |
2 | 399 |
* or if the specified collection is null |
400 |
* @see #remove(Object) |
|
401 |
* @see #contains(Object) |
|
402 |
*/ |
|
403 |
boolean retainAll(Collection<?> c); |
|
404 |
||
405 |
/** |
|
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
406 |
* Replaces each element of this list with the result of applying the |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
407 |
* operator to that element. Errors or runtime exceptions thrown by |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
408 |
* the operator are relayed to the caller. |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
409 |
* |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
410 |
* @implSpec |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
411 |
* The default implementation is equivalent to, for this {@code list}: |
21339 | 412 |
* <pre>{@code |
413 |
* final ListIterator<E> li = list.listIterator(); |
|
414 |
* while (li.hasNext()) { |
|
415 |
* li.set(operator.apply(li.next())); |
|
416 |
* } |
|
417 |
* }</pre> |
|
418 |
* |
|
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
419 |
* If the list's list-iterator does not support the {@code set} operation |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
420 |
* then an {@code UnsupportedOperationException} will be thrown when |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
421 |
* replacing the first element. |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
422 |
* |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
423 |
* @param operator the operator to apply to each element |
20477
f7a1f6688508
8023340: Clarify that unmodifiable List.replaceAll() may not throw UOE if there are no items to be replaced.
mduigou
parents:
19435
diff
changeset
|
424 |
* @throws UnsupportedOperationException if this list is unmodifiable. |
f7a1f6688508
8023340: Clarify that unmodifiable List.replaceAll() may not throw UOE if there are no items to be replaced.
mduigou
parents:
19435
diff
changeset
|
425 |
* Implementations may throw this exception if an element |
f7a1f6688508
8023340: Clarify that unmodifiable List.replaceAll() may not throw UOE if there are no items to be replaced.
mduigou
parents:
19435
diff
changeset
|
426 |
* cannot be replaced or if, in general, modification is not |
f7a1f6688508
8023340: Clarify that unmodifiable List.replaceAll() may not throw UOE if there are no items to be replaced.
mduigou
parents:
19435
diff
changeset
|
427 |
* supported |
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
428 |
* @throws NullPointerException if the specified operator is null or |
20477
f7a1f6688508
8023340: Clarify that unmodifiable List.replaceAll() may not throw UOE if there are no items to be replaced.
mduigou
parents:
19435
diff
changeset
|
429 |
* if the operator result is a null value and this list does |
f7a1f6688508
8023340: Clarify that unmodifiable List.replaceAll() may not throw UOE if there are no items to be replaced.
mduigou
parents:
19435
diff
changeset
|
430 |
* not permit null elements |
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
431 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
432 |
* @since 1.8 |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
433 |
*/ |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
434 |
default void replaceAll(UnaryOperator<E> operator) { |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
435 |
Objects.requireNonNull(operator); |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
436 |
final ListIterator<E> li = this.listIterator(); |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
437 |
while (li.hasNext()) { |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
438 |
li.set(operator.apply(li.next())); |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
439 |
} |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
440 |
} |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
441 |
|
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
442 |
/** |
22285
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
443 |
* Sorts this list according to the order induced by the specified |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
444 |
* {@link Comparator}. |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
445 |
* |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
446 |
* <p>All elements in this list must be <i>mutually comparable</i> using the |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
447 |
* specified comparator (that is, {@code c.compare(e1, e2)} must not throw |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
448 |
* a {@code ClassCastException} for any elements {@code e1} and {@code e2} |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
449 |
* in the list). |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
450 |
* |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
451 |
* <p>If the specified comparator is {@code null} then all elements in this |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
452 |
* list must implement the {@link Comparable} interface and the elements' |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
453 |
* {@linkplain Comparable natural ordering} should be used. |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
454 |
* |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
455 |
* <p>This list must be modifiable, but need not be resizable. |
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
456 |
* |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
457 |
* @implSpec |
22285
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
458 |
* The default implementation obtains an array containing all elements in |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
459 |
* this list, sorts the array, and iterates over this list resetting each |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
460 |
* element from the corresponding position in the array. (This avoids the |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
461 |
* n<sup>2</sup> log(n) performance that would result from attempting |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
462 |
* to sort a linked list in place.) |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
463 |
* |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
464 |
* @implNote |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
465 |
* This implementation is a stable, adaptive, iterative mergesort that |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
466 |
* requires far fewer than n lg(n) comparisons when the input array is |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
467 |
* partially sorted, while offering the performance of a traditional |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
468 |
* mergesort when the input array is randomly ordered. If the input array |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
469 |
* is nearly sorted, the implementation requires approximately n |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
470 |
* comparisons. Temporary storage requirements vary from a small constant |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
471 |
* for nearly sorted input arrays to n/2 object references for randomly |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
472 |
* ordered input arrays. |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
473 |
* |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
474 |
* <p>The implementation takes equal advantage of ascending and |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
475 |
* descending order in its input array, and can take advantage of |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
476 |
* ascending and descending order in different parts of the same |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
477 |
* input array. It is well-suited to merging two or more sorted arrays: |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
478 |
* simply concatenate the arrays and sort the resulting array. |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
479 |
* |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
480 |
* <p>The implementation was adapted from Tim Peters's list sort for Python |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
481 |
* (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt"> |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
482 |
* TimSort</a>). It uses techniques from Peter McIlroy's "Optimistic |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
483 |
* Sorting and Information Theoretic Complexity", in Proceedings of the |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
484 |
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
485 |
* January 1993. |
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
486 |
* |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
487 |
* @param c the {@code Comparator} used to compare list elements. |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
488 |
* A {@code null} value indicates that the elements' |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
489 |
* {@linkplain Comparable natural ordering} should be used |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
490 |
* @throws ClassCastException if the list contains elements that are not |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
491 |
* <i>mutually comparable</i> using the specified comparator |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
492 |
* @throws UnsupportedOperationException if the list's list-iterator does |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
493 |
* not support the {@code set} operation |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
494 |
* @throws IllegalArgumentException |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
495 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
496 |
* if the comparator is found to violate the {@link Comparator} |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
497 |
* contract |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
498 |
* @since 1.8 |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
499 |
*/ |
22285
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
500 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
501 |
default void sort(Comparator<? super E> c) { |
22285
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
502 |
Object[] a = this.toArray(); |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
503 |
Arrays.sort(a, (Comparator) c); |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
504 |
ListIterator<E> i = this.listIterator(); |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
505 |
for (Object e : a) { |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
506 |
i.next(); |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
507 |
i.set((E) e); |
6c67737a5ac0
8030848: Collections.sort(List l, Comparator) should defer to List.sort(Comparator )
psandoz
parents:
21339
diff
changeset
|
508 |
} |
17166
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
509 |
} |
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
510 |
|
c83a0fa44906
8001647: default methods for Collections - forEach, removeIf, replaceAll, sort
akhil
parents:
16929
diff
changeset
|
511 |
/** |
2 | 512 |
* Removes all of the elements from this list (optional operation). |
513 |
* The list will be empty after this call returns. |
|
514 |
* |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
515 |
* @throws UnsupportedOperationException if the {@code clear} operation |
2 | 516 |
* is not supported by this list |
517 |
*/ |
|
518 |
void clear(); |
|
519 |
||
520 |
||
521 |
// Comparison and hashing |
|
522 |
||
523 |
/** |
|
524 |
* Compares the specified object with this list for equality. Returns |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
525 |
* {@code true} if and only if the specified object is also a list, both |
2 | 526 |
* lists have the same size, and all corresponding pairs of elements in |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
527 |
* the two lists are <i>equal</i>. (Two elements {@code e1} and |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
528 |
* {@code e2} are <i>equal</i> if {@code Objects.equals(e1, e2)}.) |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
529 |
* In other words, two lists are defined to be |
2 | 530 |
* equal if they contain the same elements in the same order. This |
531 |
* definition ensures that the equals method works properly across |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
532 |
* different implementations of the {@code List} interface. |
2 | 533 |
* |
534 |
* @param o the object to be compared for equality with this list |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
535 |
* @return {@code true} if the specified object is equal to this list |
2 | 536 |
*/ |
537 |
boolean equals(Object o); |
|
538 |
||
539 |
/** |
|
540 |
* Returns the hash code value for this list. The hash code of a list |
|
541 |
* is defined to be the result of the following calculation: |
|
21339 | 542 |
* <pre>{@code |
543 |
* int hashCode = 1; |
|
544 |
* for (E e : list) |
|
545 |
* hashCode = 31*hashCode + (e==null ? 0 : e.hashCode()); |
|
546 |
* }</pre> |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
547 |
* This ensures that {@code list1.equals(list2)} implies that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
548 |
* {@code list1.hashCode()==list2.hashCode()} for any two lists, |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
549 |
* {@code list1} and {@code list2}, as required by the general |
2 | 550 |
* contract of {@link Object#hashCode}. |
551 |
* |
|
552 |
* @return the hash code value for this list |
|
553 |
* @see Object#equals(Object) |
|
554 |
* @see #equals(Object) |
|
555 |
*/ |
|
556 |
int hashCode(); |
|
557 |
||
558 |
||
559 |
// Positional Access Operations |
|
560 |
||
561 |
/** |
|
562 |
* Returns the element at the specified position in this list. |
|
563 |
* |
|
564 |
* @param index index of the element to return |
|
565 |
* @return the element at the specified position in this list |
|
566 |
* @throws IndexOutOfBoundsException if the index is out of range |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
567 |
* ({@code index < 0 || index >= size()}) |
2 | 568 |
*/ |
569 |
E get(int index); |
|
570 |
||
571 |
/** |
|
572 |
* Replaces the element at the specified position in this list with the |
|
573 |
* specified element (optional operation). |
|
574 |
* |
|
575 |
* @param index index of the element to replace |
|
576 |
* @param element element to be stored at the specified position |
|
577 |
* @return the element previously at the specified position |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
578 |
* @throws UnsupportedOperationException if the {@code set} operation |
2 | 579 |
* is not supported by this list |
580 |
* @throws ClassCastException if the class of the specified element |
|
581 |
* prevents it from being added to this list |
|
582 |
* @throws NullPointerException if the specified element is null and |
|
583 |
* this list does not permit null elements |
|
584 |
* @throws IllegalArgumentException if some property of the specified |
|
585 |
* element prevents it from being added to this list |
|
586 |
* @throws IndexOutOfBoundsException if the index is out of range |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
587 |
* ({@code index < 0 || index >= size()}) |
2 | 588 |
*/ |
589 |
E set(int index, E element); |
|
590 |
||
591 |
/** |
|
592 |
* Inserts the specified element at the specified position in this list |
|
593 |
* (optional operation). Shifts the element currently at that position |
|
594 |
* (if any) and any subsequent elements to the right (adds one to their |
|
595 |
* indices). |
|
596 |
* |
|
597 |
* @param index index at which the specified element is to be inserted |
|
598 |
* @param element element to be inserted |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
599 |
* @throws UnsupportedOperationException if the {@code add} operation |
2 | 600 |
* is not supported by this list |
601 |
* @throws ClassCastException if the class of the specified element |
|
602 |
* prevents it from being added to this list |
|
603 |
* @throws NullPointerException if the specified element is null and |
|
604 |
* this list does not permit null elements |
|
605 |
* @throws IllegalArgumentException if some property of the specified |
|
606 |
* element prevents it from being added to this list |
|
607 |
* @throws IndexOutOfBoundsException if the index is out of range |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
608 |
* ({@code index < 0 || index > size()}) |
2 | 609 |
*/ |
610 |
void add(int index, E element); |
|
611 |
||
612 |
/** |
|
613 |
* Removes the element at the specified position in this list (optional |
|
614 |
* operation). Shifts any subsequent elements to the left (subtracts one |
|
615 |
* from their indices). Returns the element that was removed from the |
|
616 |
* list. |
|
617 |
* |
|
618 |
* @param index the index of the element to be removed |
|
619 |
* @return the element previously at the specified position |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
620 |
* @throws UnsupportedOperationException if the {@code remove} operation |
2 | 621 |
* is not supported by this list |
622 |
* @throws IndexOutOfBoundsException if the index is out of range |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
623 |
* ({@code index < 0 || index >= size()}) |
2 | 624 |
*/ |
625 |
E remove(int index); |
|
626 |
||
627 |
||
628 |
// Search Operations |
|
629 |
||
630 |
/** |
|
631 |
* Returns the index of the first occurrence of the specified element |
|
632 |
* in this list, or -1 if this list does not contain the element. |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
633 |
* More formally, returns the lowest index {@code i} such that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
634 |
* {@code Objects.equals(o, get(i))}, |
2 | 635 |
* or -1 if there is no such index. |
636 |
* |
|
637 |
* @param o element to search for |
|
638 |
* @return the index of the first occurrence of the specified element in |
|
639 |
* this list, or -1 if this list does not contain the element |
|
640 |
* @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:
7668
diff
changeset
|
641 |
* is incompatible with this list |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
642 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 643 |
* @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:
7668
diff
changeset
|
644 |
* list does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
645 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 646 |
*/ |
647 |
int indexOf(Object o); |
|
648 |
||
649 |
/** |
|
650 |
* Returns the index of the last occurrence of the specified element |
|
651 |
* in this list, or -1 if this list does not contain the element. |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
652 |
* More formally, returns the highest index {@code i} such that |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
653 |
* {@code Objects.equals(o, get(i))}, |
2 | 654 |
* or -1 if there is no such index. |
655 |
* |
|
656 |
* @param o element to search for |
|
657 |
* @return the index of the last occurrence of the specified element in |
|
658 |
* this list, or -1 if this list does not contain the element |
|
659 |
* @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:
7668
diff
changeset
|
660 |
* is incompatible with this list |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
661 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 662 |
* @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:
7668
diff
changeset
|
663 |
* list does not permit null elements |
588cf31d584a
6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents:
7668
diff
changeset
|
664 |
* (<a href="Collection.html#optional-restrictions">optional</a>) |
2 | 665 |
*/ |
666 |
int lastIndexOf(Object o); |
|
667 |
||
668 |
||
669 |
// List Iterators |
|
670 |
||
671 |
/** |
|
672 |
* Returns a list iterator over the elements in this list (in proper |
|
673 |
* sequence). |
|
674 |
* |
|
675 |
* @return a list iterator over the elements in this list (in proper |
|
676 |
* sequence) |
|
677 |
*/ |
|
678 |
ListIterator<E> listIterator(); |
|
679 |
||
680 |
/** |
|
681 |
* Returns a list iterator over the elements in this list (in proper |
|
682 |
* sequence), starting at the specified position in the list. |
|
683 |
* The specified index indicates the first element that would be |
|
684 |
* returned by an initial call to {@link ListIterator#next next}. |
|
685 |
* An initial call to {@link ListIterator#previous previous} would |
|
686 |
* return the element with the specified index minus one. |
|
687 |
* |
|
688 |
* @param index index of the first element to be returned from the |
|
689 |
* list iterator (by a call to {@link ListIterator#next next}) |
|
690 |
* @return a list iterator over the elements in this list (in proper |
|
691 |
* sequence), starting at the specified position in the list |
|
692 |
* @throws IndexOutOfBoundsException if the index is out of range |
|
693 |
* ({@code index < 0 || index > size()}) |
|
694 |
*/ |
|
695 |
ListIterator<E> listIterator(int index); |
|
696 |
||
697 |
// View |
|
698 |
||
699 |
/** |
|
700 |
* Returns a view of the portion of this list between the specified |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
701 |
* {@code fromIndex}, inclusive, and {@code toIndex}, exclusive. (If |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
702 |
* {@code fromIndex} and {@code toIndex} are equal, the returned list is |
2 | 703 |
* empty.) The returned list is backed by this list, so non-structural |
704 |
* changes in the returned list are reflected in this list, and vice-versa. |
|
705 |
* The returned list supports all of the optional list operations supported |
|
706 |
* by this list.<p> |
|
707 |
* |
|
708 |
* This method eliminates the need for explicit range operations (of |
|
709 |
* the sort that commonly exist for arrays). Any operation that expects |
|
710 |
* a list can be used as a range operation by passing a subList view |
|
711 |
* instead of a whole list. For example, the following idiom |
|
712 |
* removes a range of elements from a list: |
|
21339 | 713 |
* <pre>{@code |
2 | 714 |
* list.subList(from, to).clear(); |
21339 | 715 |
* }</pre> |
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
716 |
* Similar idioms may be constructed for {@code indexOf} and |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
717 |
* {@code lastIndexOf}, and all of the algorithms in the |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
718 |
* {@code Collections} class can be applied to a subList.<p> |
2 | 719 |
* |
720 |
* The semantics of the list returned by this method become undefined if |
|
721 |
* the backing list (i.e., this list) is <i>structurally modified</i> in |
|
722 |
* any way other than via the returned list. (Structural modifications are |
|
723 |
* those that change the size of this list, or otherwise perturb it in such |
|
724 |
* a fashion that iterations in progress may yield incorrect results.) |
|
725 |
* |
|
726 |
* @param fromIndex low endpoint (inclusive) of the subList |
|
727 |
* @param toIndex high endpoint (exclusive) of the subList |
|
728 |
* @return a view of the specified range within this list |
|
729 |
* @throws IndexOutOfBoundsException for an illegal endpoint index value |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
730 |
* ({@code fromIndex < 0 || toIndex > size || |
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
731 |
* fromIndex > toIndex}) |
2 | 732 |
*/ |
733 |
List<E> subList(int fromIndex, int toIndex); |
|
16929
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
734 |
|
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
735 |
/** |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
736 |
* Creates a {@link Spliterator} over the elements in this list. |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
737 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
738 |
* <p>The {@code Spliterator} reports {@link Spliterator#SIZED} and |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
739 |
* {@link Spliterator#ORDERED}. Implementations should document the |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
740 |
* reporting of additional characteristic values. |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
741 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
742 |
* @implSpec |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
743 |
* The default implementation creates a |
39568
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
744 |
* <em><a href="Spliterator.html#binding">late-binding</a></em> |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
745 |
* spliterator as follows: |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
746 |
* <ul> |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
747 |
* <li>If the list is an instance of {@link RandomAccess} then the default |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
748 |
* implementation creates a spliterator that traverses elements by |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
749 |
* invoking the method {@link List#get}. If such invocation results or |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
750 |
* would result in an {@code IndexOutOfBoundsException} then the |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
751 |
* spliterator will <em>fail-fast</em> and throw a |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
752 |
* {@code ConcurrentModificationException}. |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
753 |
* If the list is also an instance of {@link AbstractList} then the |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
754 |
* spliterator will use the list's {@link AbstractList#modCount modCount} |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
755 |
* field to provide additional <em>fail-fast</em> behavior. |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
756 |
* <li>Otherwise, the default implementation creates a spliterator from the |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
757 |
* list's {@code Iterator}. The spliterator inherits the |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
758 |
* <em>fail-fast</em> of the list's iterator. |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
759 |
* </ul> |
16929
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
760 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
761 |
* @implNote |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
762 |
* The created {@code Spliterator} additionally reports |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
763 |
* {@link Spliterator#SUBSIZED}. |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
764 |
* |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
765 |
* @return a {@code Spliterator} over the elements in this list |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
766 |
* @since 1.8 |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
767 |
*/ |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
768 |
@Override |
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
769 |
default Spliterator<E> spliterator() { |
39568
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
770 |
if (this instanceof RandomAccess) { |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
771 |
return new AbstractList.RandomAccessSpliterator<>(this); |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
772 |
} else { |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
773 |
return Spliterators.spliterator(this, Spliterator.ORDERED); |
1987f3929c39
8158365: List.spliterator should optimize for RandomAccess lists
psandoz
parents:
38567
diff
changeset
|
774 |
} |
16929
c984ae5655cb
8010096: Initial java.util.Spliterator putback
briangoetz
parents:
14342
diff
changeset
|
775 |
} |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
776 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
777 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
778 |
* Returns an immutable list containing zero elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
779 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
780 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
781 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
782 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
783 |
* @return an empty {@code List} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
784 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
785 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
786 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
787 |
static <E> List<E> of() { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
788 |
return new ImmutableCollections.List0<>(); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
789 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
790 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
791 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
792 |
* Returns an immutable list containing one element. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
793 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
794 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
795 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
796 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
797 |
* @param e1 the single element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
798 |
* @return a {@code List} containing the specified element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
799 |
* @throws NullPointerException if the element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
800 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
801 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
802 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
803 |
static <E> List<E> of(E e1) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
804 |
return new ImmutableCollections.List1<>(e1); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
805 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
806 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
807 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
808 |
* Returns an immutable list containing two elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
809 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
810 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
811 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
812 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
813 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
814 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
815 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
816 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
817 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
818 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
819 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
820 |
static <E> List<E> of(E e1, E e2) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
821 |
return new ImmutableCollections.List2<>(e1, e2); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
822 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
823 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
824 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
825 |
* Returns an immutable list containing three elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
826 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
827 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
828 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
829 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
830 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
831 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
832 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
833 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
834 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
835 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
836 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
837 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
838 |
static <E> List<E> of(E e1, E e2, E e3) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
839 |
return new ImmutableCollections.ListN<>(e1, e2, e3); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
840 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
841 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
842 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
843 |
* Returns an immutable list containing four elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
844 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
845 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
846 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
847 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
848 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
849 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
850 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
851 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
852 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
853 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
854 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
855 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
856 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
857 |
static <E> List<E> of(E e1, E e2, E e3, E e4) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
858 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
859 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
860 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
861 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
862 |
* Returns an immutable list containing five elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
863 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
864 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
865 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
866 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
867 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
868 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
869 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
870 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
871 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
872 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
873 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
874 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
875 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
876 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
877 |
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
878 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
879 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
880 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
881 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
882 |
* Returns an immutable list containing six elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
883 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
884 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
885 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
886 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
887 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
888 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
889 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
890 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
891 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
892 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
893 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
894 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
895 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
896 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
897 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
898 |
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
899 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5, |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
900 |
e6); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
901 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
902 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
903 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
904 |
* Returns an immutable list containing seven elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
905 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
906 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
907 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
908 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
909 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
910 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
911 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
912 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
913 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
914 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
915 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
916 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
917 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
918 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
919 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
920 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
921 |
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
922 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5, |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
923 |
e6, e7); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
924 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
925 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
926 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
927 |
* Returns an immutable list containing eight elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
928 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
929 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
930 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
931 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
932 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
933 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
934 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
935 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
936 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
937 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
938 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
939 |
* @param e8 the eighth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
940 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
941 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
942 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
943 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
944 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
945 |
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
946 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5, |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
947 |
e6, e7, e8); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
948 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
949 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
950 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
951 |
* Returns an immutable list containing nine elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
952 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
953 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
954 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
955 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
956 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
957 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
958 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
959 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
960 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
961 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
962 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
963 |
* @param e8 the eighth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
964 |
* @param e9 the ninth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
965 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
966 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
967 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
968 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
969 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
970 |
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
971 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5, |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
972 |
e6, e7, e8, e9); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
973 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
974 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
975 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
976 |
* Returns an immutable list containing ten elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
977 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
978 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
979 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
980 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
981 |
* @param e1 the first element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
982 |
* @param e2 the second element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
983 |
* @param e3 the third element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
984 |
* @param e4 the fourth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
985 |
* @param e5 the fifth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
986 |
* @param e6 the sixth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
987 |
* @param e7 the seventh element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
988 |
* @param e8 the eighth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
989 |
* @param e9 the ninth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
990 |
* @param e10 the tenth element |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
991 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
992 |
* @throws NullPointerException if an element is {@code null} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
993 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
994 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
995 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
996 |
static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
997 |
return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5, |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
998 |
e6, e7, e8, e9, e10); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
999 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1000 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1001 |
/** |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1002 |
* Returns an immutable list containing an arbitrary number of elements. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1003 |
* See <a href="#immutable">Immutable List Static Factory Methods</a> for details. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1004 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1005 |
* @apiNote |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1006 |
* 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
|
1007 |
* the resulting list 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
|
1008 |
* the list will be equal to the length of the array. To create a list with |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1009 |
* a single element that is an array, do the following: |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1010 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1011 |
* <pre>{@code |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1012 |
* String[] array = ... ; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1013 |
* List<String[]> list = List.<String[]>of(array); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1014 |
* }</pre> |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1015 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1016 |
* This will cause the {@link List#of(Object) List.of(E)} method |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1017 |
* to be invoked instead. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1018 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1019 |
* @param <E> the {@code List}'s element type |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1020 |
* @param elements the elements to be contained in the list |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1021 |
* @return a {@code List} containing the specified elements |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1022 |
* @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
|
1023 |
* |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1024 |
* @since 9 |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1025 |
*/ |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1026 |
@SafeVarargs |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1027 |
@SuppressWarnings("varargs") |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1028 |
static <E> List<E> of(E... elements) { |
37802
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1029 |
Objects.requireNonNull(elements); |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1030 |
switch (elements.length) { |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1031 |
case 0: |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1032 |
return new ImmutableCollections.List0<>(); |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1033 |
case 1: |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1034 |
return new ImmutableCollections.List1<>(elements[0]); |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1035 |
case 2: |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1036 |
return new ImmutableCollections.List2<>(elements[0], elements[1]); |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1037 |
default: |
91fc9ac7b8b3
8139233: add initial compact immutable collection implementations
smarks
parents:
34527
diff
changeset
|
1038 |
return new ImmutableCollections.ListN<>(elements); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1039 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32108
diff
changeset
|
1040 |
} |
2 | 1041 |
} |