jdk/src/java.base/share/classes/java/util/List.java
author smarks
Wed, 25 May 2016 13:38:35 -0700
changeset 38567 6d4c5a278fff
parent 37802 91fc9ac7b8b3
child 39568 1987f3929c39
permissions -rw-r--r--
8133977: add specification for serialized forms Reviewed-by: chegar, plevart, scolebourne
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38567
6d4c5a278fff 8133977: add specification for serialized forms
smarks
parents: 37802
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4977
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An ordered collection (also known as a <i>sequence</i>).  The user of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * interface has precise control over where in the list each element is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * inserted.  The user can access elements by their integer index (position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the list), and search for elements in the list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * null elements if they allow null elements at all.  It is not inconceivable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * that someone might wish to implement a list that prohibits duplicates, by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * throwing runtime exceptions when the user attempts to insert them, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * expect this usage to be rare.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * also included here for convenience.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * access to list elements.  Lists (like Java arrays) are zero based.  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * example). Thus, iterating over the elements in a list is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * preferable to indexing through it if the caller does not know the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * implementation.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * list iterator that starts at a specified position in the list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * object.  From a performance standpoint, these methods should be used with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * caution.  In many implementations they will perform costly linear
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * searches.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * remove multiple elements at an arbitrary point in the list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * methods are no longer well defined on such a list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>Some list implementations have restrictions on the elements that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * they may contain.  For example, some implementations prohibit null elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * and some have restrictions on the types of their elements.  Attempting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * to query the presence of an ineligible element may throw an exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * or it may simply return false; some implementations will exhibit the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * behavior and some will exhibit the latter.  More generally, attempting an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * operation on an ineligible element whose completion would not result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the insertion of an ineligible element into the list may throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * exception or it may succeed, at the option of the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Such exceptions are marked as "optional" in the specification for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
6d4c5a278fff 8133977: add specification for serialized forms
smarks
parents: 37802
diff changeset
   110
 * <li>They are serialized as specified on the
6d4c5a278fff 8133977: add specification for serialized forms
smarks
parents: 37802
diff changeset
   111
 * <a href="{@docRoot}/serialized-form.html#java.util.CollSer">Serialized Form</a>
6d4c5a278fff 8133977: add specification for serialized forms
smarks
parents: 37802
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @author  Neal Gafter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @see Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @see ArrayList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @see LinkedList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * @see Vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * @see Arrays#asList(Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @see Collections#nCopies(int, Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @see Collections#EMPTY_LIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @see AbstractList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @see AbstractSequentialList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
public interface List<E> extends Collection<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    // Query Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return the number of elements in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    int size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    boolean isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Returns an iterator over the elements in this list in proper sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return an iterator over the elements in this list in proper sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Returns an array containing all of the elements in this list in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * sequence (from first to last element).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <p>The returned array will be "safe" in that no references to it are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * maintained by this list.  (In other words, this method must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * allocate a new array even if this list is backed by an array).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * The caller is thus free to modify the returned array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <p>This method acts as bridge between array-based and collection-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return an array containing all of the elements in this list in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see Arrays#asList(Object[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    Object[] toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Returns an array containing all of the elements in this list in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * proper sequence (from first to last element); the runtime type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * the returned array is that of the specified array.  If the list fits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * in the specified array, it is returned therein.  Otherwise, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * array is allocated with the runtime type of the specified array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * the size of this list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <p>If the list fits in the specified array with room to spare (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * (This is useful in determining the length of the list <i>only</i> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * the caller knows that the list does not contain any null elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <p>Like the {@link #toArray()} method, this method acts as bridge between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * array-based and collection-based APIs.  Further, this method allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * precise control over the runtime type of the output array, and may,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * under certain circumstances, be used to save allocation costs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   220
     * <pre>{@code
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   221
     *     String[] y = x.toArray(new String[0]);
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   222
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param a the array into which the elements of this list are to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *          be stored, if it is big enough; otherwise, a new array of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *          same runtime type is allocated for this purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return an array containing the elements of this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @throws ArrayStoreException if the runtime type of the specified array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *         is not a supertype of the runtime type of every element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *         this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @throws NullPointerException if the specified array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    <T> T[] toArray(T[] a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Appends the specified element to the end of this list (optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <p>Lists that support this operation may place limitations on what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * elements may be added to this list.  In particular, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * lists will refuse to add null elements, and others will impose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * restrictions on the type of elements that may be added.  List
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * classes should clearly specify in their documentation any restrictions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * on what elements may be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *         list does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @throws IllegalArgumentException if some property of this element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Removes the first occurrence of the specified element from this list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * if it is present (optional operation).  If this list does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * contained the specified element (or equivalently, if this list changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * as a result of the call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    // Bulk Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *         specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    boolean containsAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Appends all of the elements in the specified collection to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * this list, in the order that they are returned by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * collection's iterator (optional operation).  The behavior of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * operation is undefined if the specified collection is modified while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * the operation is in progress.  (Note that this will occur if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * specified collection is this list, and it's nonempty.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @throws ClassCastException if the class of an element of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *         collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *         or more null elements and this list does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *         elements, or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *         specified collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see #add(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    boolean addAll(Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Inserts all of the elements in the specified collection into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * list at the specified position (optional operation).  Shifts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * element currently at that position (if any) and any subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * elements to the right (increases their indices).  The new elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * will appear in this list in the order that they are returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * specified collection's iterator.  The behavior of this operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * undefined if the specified collection is modified while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * operation is in progress.  (Note that this will occur if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * collection is this list, and it's nonempty.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @param index index at which to insert the first element from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *              specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @throws ClassCastException if the class of an element of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *         collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *         or more null elements and this list does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *         elements, or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *         specified collection prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    boolean addAll(int index, Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Removes from this list all of its elements that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * specified collection (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    boolean removeAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Retains only the elements in this list that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * specified collection (optional operation).  In other words, removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * from this list all of its elements that are not contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    boolean retainAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   412
     * <pre>{@code
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   413
     *     final ListIterator<E> li = list.listIterator();
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   414
     *     while (li.hasNext()) {
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   415
     *         li.set(operator.apply(li.next()));
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   416
     *     }
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   417
     * }</pre>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Removes all of the elements from this list (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * The list will be empty after this call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    void clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    // Comparison and hashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * equal if they contain the same elements in the same order.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Returns the hash code value for this list.  The hash code of a list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * is defined to be the result of the following calculation:
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   542
     * <pre>{@code
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   543
     *     int hashCode = 1;
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   544
     *     for (E e : list)
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   545
     *         hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * contract of {@link Object#hashCode}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @return the hash code value for this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @see #equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    // Positional Access Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Returns the element at the specified position in this list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @param index index of the element to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @return the element at the specified position in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    E get(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Replaces the element at the specified position in this list with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * specified element (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @param index index of the element to replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @param element element to be stored at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @throws NullPointerException if the specified element is null and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *         this list does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *         element prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    E set(int index, E element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Inserts the specified element at the specified position in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * (optional operation).  Shifts the element currently at that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * (if any) and any subsequent elements to the right (adds one to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * indices).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param index index at which the specified element is to be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @throws NullPointerException if the specified element is null and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *         this list does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @throws IllegalArgumentException if some property of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *         element prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    void add(int index, E element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Removes the element at the specified position in this list (optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * operation).  Shifts any subsequent elements to the left (subtracts one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * from their indices).  Returns the element that was removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @param index the index of the element to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *         is not supported by this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    E remove(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    // Search Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * Returns the index of the first occurrence of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * or -1 if there is no such index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @param o element to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @return the index of the first occurrence of the specified element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *         this list, or -1 if this list does not contain the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    int indexOf(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * Returns the index of the last occurrence of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * or -1 if there is no such index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @param o element to search for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return the index of the last occurrence of the specified element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *         this list, or -1 if this list does not contain the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    int lastIndexOf(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    // List Iterators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Returns a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * sequence).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @return a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *         sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    ListIterator<E> listIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * Returns a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * sequence), starting at the specified position in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * The specified index indicates the first element that would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * returned by an initial call to {@link ListIterator#next next}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * An initial call to {@link ListIterator#previous previous} would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * return the element with the specified index minus one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @param index index of the first element to be returned from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *        list iterator (by a call to {@link ListIterator#next next})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * @return a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *         sequence), starting at the specified position in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @throws IndexOutOfBoundsException if the index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *         ({@code index < 0 || index > size()})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    ListIterator<E> listIterator(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // View
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * empty.)  The returned list is backed by this list, so non-structural
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * changes in the returned list are reflected in this list, and vice-versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * The returned list supports all of the optional list operations supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * by this list.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * This method eliminates the need for explicit range operations (of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * the sort that commonly exist for arrays).  Any operation that expects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * a list can be used as a range operation by passing a subList view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * instead of a whole list.  For example, the following idiom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * removes a range of elements from a list:
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   713
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *      list.subList(from, to).clear();
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20477
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * The semantics of the list returned by this method become undefined if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * the backing list (i.e., this list) is <i>structurally modified</i> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * any way other than via the returned list.  (Structural modifications are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * those that change the size of this list, or otherwise perturb it in such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * a fashion that iterations in progress may yield incorrect results.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @param fromIndex low endpoint (inclusive) of the subList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @param toIndex high endpoint (exclusive) of the subList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @return a view of the specified range within this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   744
     * <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   745
     * from the list's {@code Iterator}.  The spliterator inherits the
19435
9d7530ff42cb 8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents: 19074
diff changeset
   746
     * <em>fail-fast</em> properties of the list's iterator.
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   747
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   748
     * @implNote
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   749
     * The created {@code Spliterator} additionally reports
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   750
     * {@link Spliterator#SUBSIZED}.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   751
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   752
     * @return a {@code Spliterator} over the elements in this list
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   753
     * @since 1.8
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   754
     */
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   755
    @Override
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   756
    default Spliterator<E> spliterator() {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   757
        return Spliterators.spliterator(this, Spliterator.ORDERED);
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 14342
diff changeset
   758
    }
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   759
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   760
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   761
     * Returns an immutable list containing zero elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   762
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   763
     * 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
   764
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   765
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   766
     * @return an empty {@code List}
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   767
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   768
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   769
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   770
    static <E> List<E> of() {
37802
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   771
        return new ImmutableCollections.List0<>();
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   772
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   773
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   774
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   775
     * Returns an immutable list containing one element.
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
     * 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
   778
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   779
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   780
     * @param e1 the single element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   781
     * @return a {@code List} containing the specified element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   782
     * @throws NullPointerException if the element is {@code null}
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   783
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   784
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   785
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   786
    static <E> List<E> of(E e1) {
37802
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   787
        return new ImmutableCollections.List1<>(e1);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   788
    }
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
     * Returns an immutable list containing two elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   792
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   793
     * 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
   794
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   795
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   796
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   797
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   798
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   799
     * @throws NullPointerException if an 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, E e2) {
37802
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   804
        return new ImmutableCollections.List2<>(e1, e2);
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 three 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
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   816
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   817
     * @throws NullPointerException if an element is {@code null}
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   818
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   819
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   820
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   821
    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
   822
        return new ImmutableCollections.ListN<>(e1, e2, e3);
34527
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
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   826
     * Returns an immutable list containing four elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   827
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   828
     * 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
   829
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   830
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   831
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   832
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   833
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   834
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   835
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   836
     * @throws NullPointerException if an element is {@code null}
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
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   839
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   840
    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
   841
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4);
34527
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
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
     * Returns an immutable list containing five elements.
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
     * 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
   848
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   849
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   850
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   851
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   852
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   853
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   854
     * @param e5 the fifth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   855
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   856
     * @throws NullPointerException if an element is {@code null}
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   857
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   858
     * @since 9
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
    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
   861
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   862
    }
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
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   865
     * Returns an immutable list containing six elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   866
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   867
     * 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
   868
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   869
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   870
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   871
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   872
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   873
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   874
     * @param e5 the fifth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   875
     * @param e6 the sixth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   876
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   877
     * @throws NullPointerException if an element is {@code null}
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   878
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   879
     * @since 9
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
    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
   882
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5,
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   883
                                                e6);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   884
    }
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
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   887
     * Returns an immutable list containing seven elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   888
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   889
     * 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
   890
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   891
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   892
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   893
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   894
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   895
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   896
     * @param e5 the fifth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   897
     * @param e6 the sixth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   898
     * @param e7 the seventh element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   899
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   900
     * @throws NullPointerException if an element is {@code null}
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
     * @since 9
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
    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
   905
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5,
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   906
                                                e6, e7);
34527
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
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   909
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   910
     * Returns an immutable list containing eight elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   911
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   912
     * 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
   913
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   914
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   915
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   916
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   917
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   918
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   919
     * @param e5 the fifth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   920
     * @param e6 the sixth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   921
     * @param e7 the seventh element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   922
     * @param e8 the eighth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   923
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   924
     * @throws NullPointerException if an element is {@code null}
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
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   927
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   928
    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
   929
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5,
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   930
                                                e6, e7, e8);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   931
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   932
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   933
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   934
     * Returns an immutable list containing nine elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   935
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   936
     * 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
   937
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   938
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   939
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   940
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   941
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   942
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   943
     * @param e5 the fifth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   944
     * @param e6 the sixth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   945
     * @param e7 the seventh element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   946
     * @param e8 the eighth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   947
     * @param e9 the ninth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   948
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   949
     * @throws NullPointerException if an element is {@code null}
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
     * @since 9
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
    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
   954
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5,
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   955
                                                e6, e7, e8, e9);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   956
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   957
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   958
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   959
     * Returns an immutable list containing ten elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   960
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   961
     * 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
   962
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   963
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   964
     * @param e1 the first element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   965
     * @param e2 the second element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   966
     * @param e3 the third element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   967
     * @param e4 the fourth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   968
     * @param e5 the fifth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   969
     * @param e6 the sixth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   970
     * @param e7 the seventh element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   971
     * @param e8 the eighth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   972
     * @param e9 the ninth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   973
     * @param e10 the tenth element
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   974
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   975
     * @throws NullPointerException if an element is {@code null}
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   976
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   977
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   978
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   979
    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
   980
        return new ImmutableCollections.ListN<>(e1, e2, e3, e4, e5,
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
   981
                                                e6, e7, e8, e9, e10);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   982
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   983
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   984
    /**
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   985
     * Returns an immutable list containing an arbitrary number of elements.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   986
     * 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
   987
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   988
     * @apiNote
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   989
     * 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
   990
     * 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
   991
     * 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
   992
     * a single element that is an array, do the following:
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
     * <pre>{@code
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   995
     *     String[] array = ... ;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   996
     *     List<String[]> list = List.<String[]>of(array);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   997
     * }</pre>
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   998
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
   999
     * 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
  1000
     * to be invoked instead.
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
     * @param <E> the {@code List}'s element type
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1003
     * @param elements the elements to be contained in the list
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1004
     * @return a {@code List} containing the specified elements
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1005
     * @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
  1006
     *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1007
     * @since 9
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1008
     */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1009
    @SafeVarargs
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1010
    @SuppressWarnings("varargs")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1011
    static <E> List<E> of(E... elements) {
37802
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1012
        Objects.requireNonNull(elements);
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1013
        switch (elements.length) {
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1014
            case 0:
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1015
                return new ImmutableCollections.List0<>();
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1016
            case 1:
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1017
                return new ImmutableCollections.List1<>(elements[0]);
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1018
            case 2:
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1019
                return new ImmutableCollections.List2<>(elements[0], elements[1]);
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1020
            default:
91fc9ac7b8b3 8139233: add initial compact immutable collection implementations
smarks
parents: 34527
diff changeset
  1021
                return new ImmutableCollections.ListN<>(elements);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1022
        }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents: 32108
diff changeset
  1023
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
}