rt/emul/compact/src/main/java/java/util/List.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 557 emul/compact/src/main/java/java/util/List.java@5be31d9fa455
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
jaroslav@557
     1
/*
jaroslav@557
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
jaroslav@557
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@557
     4
 *
jaroslav@557
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@557
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@557
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@557
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@557
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@557
    10
 *
jaroslav@557
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@557
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@557
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@557
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@557
    15
 * accompanied this code).
jaroslav@557
    16
 *
jaroslav@557
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@557
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@557
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@557
    20
 *
jaroslav@557
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@557
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@557
    23
 * questions.
jaroslav@557
    24
 */
jaroslav@557
    25
jaroslav@557
    26
package java.util;
jaroslav@557
    27
jaroslav@557
    28
/**
jaroslav@557
    29
 * An ordered collection (also known as a <i>sequence</i>).  The user of this
jaroslav@557
    30
 * interface has precise control over where in the list each element is
jaroslav@557
    31
 * inserted.  The user can access elements by their integer index (position in
jaroslav@557
    32
 * the list), and search for elements in the list.<p>
jaroslav@557
    33
 *
jaroslav@557
    34
 * Unlike sets, lists typically allow duplicate elements.  More formally,
jaroslav@557
    35
 * lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt>
jaroslav@557
    36
 * such that <tt>e1.equals(e2)</tt>, and they typically allow multiple
jaroslav@557
    37
 * null elements if they allow null elements at all.  It is not inconceivable
jaroslav@557
    38
 * that someone might wish to implement a list that prohibits duplicates, by
jaroslav@557
    39
 * throwing runtime exceptions when the user attempts to insert them, but we
jaroslav@557
    40
 * expect this usage to be rare.<p>
jaroslav@557
    41
 *
jaroslav@557
    42
 * The <tt>List</tt> interface places additional stipulations, beyond those
jaroslav@557
    43
 * specified in the <tt>Collection</tt> interface, on the contracts of the
jaroslav@557
    44
 * <tt>iterator</tt>, <tt>add</tt>, <tt>remove</tt>, <tt>equals</tt>, and
jaroslav@557
    45
 * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
jaroslav@557
    46
 * also included here for convenience.<p>
jaroslav@557
    47
 *
jaroslav@557
    48
 * The <tt>List</tt> interface provides four methods for positional (indexed)
jaroslav@557
    49
 * access to list elements.  Lists (like Java arrays) are zero based.  Note
jaroslav@557
    50
 * that these operations may execute in time proportional to the index value
jaroslav@557
    51
 * for some implementations (the <tt>LinkedList</tt> class, for
jaroslav@557
    52
 * example). Thus, iterating over the elements in a list is typically
jaroslav@557
    53
 * preferable to indexing through it if the caller does not know the
jaroslav@557
    54
 * implementation.<p>
jaroslav@557
    55
 *
jaroslav@557
    56
 * The <tt>List</tt> interface provides a special iterator, called a
jaroslav@557
    57
 * <tt>ListIterator</tt>, that allows element insertion and replacement, and
jaroslav@557
    58
 * bidirectional access in addition to the normal operations that the
jaroslav@557
    59
 * <tt>Iterator</tt> interface provides.  A method is provided to obtain a
jaroslav@557
    60
 * list iterator that starts at a specified position in the list.<p>
jaroslav@557
    61
 *
jaroslav@557
    62
 * The <tt>List</tt> interface provides two methods to search for a specified
jaroslav@557
    63
 * object.  From a performance standpoint, these methods should be used with
jaroslav@557
    64
 * caution.  In many implementations they will perform costly linear
jaroslav@557
    65
 * searches.<p>
jaroslav@557
    66
 *
jaroslav@557
    67
 * The <tt>List</tt> interface provides two methods to efficiently insert and
jaroslav@557
    68
 * remove multiple elements at an arbitrary point in the list.<p>
jaroslav@557
    69
 *
jaroslav@557
    70
 * Note: While it is permissible for lists to contain themselves as elements,
jaroslav@557
    71
 * extreme caution is advised: the <tt>equals</tt> and <tt>hashCode</tt>
jaroslav@557
    72
 * methods are no longer well defined on such a list.
jaroslav@557
    73
 *
jaroslav@557
    74
 * <p>Some list implementations have restrictions on the elements that
jaroslav@557
    75
 * they may contain.  For example, some implementations prohibit null elements,
jaroslav@557
    76
 * and some have restrictions on the types of their elements.  Attempting to
jaroslav@557
    77
 * add an ineligible element throws an unchecked exception, typically
jaroslav@557
    78
 * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
jaroslav@557
    79
 * to query the presence of an ineligible element may throw an exception,
jaroslav@557
    80
 * or it may simply return false; some implementations will exhibit the former
jaroslav@557
    81
 * behavior and some will exhibit the latter.  More generally, attempting an
jaroslav@557
    82
 * operation on an ineligible element whose completion would not result in
jaroslav@557
    83
 * the insertion of an ineligible element into the list may throw an
jaroslav@557
    84
 * exception or it may succeed, at the option of the implementation.
jaroslav@557
    85
 * Such exceptions are marked as "optional" in the specification for this
jaroslav@557
    86
 * interface.
jaroslav@557
    87
 *
jaroslav@557
    88
 * <p>This interface is a member of the
jaroslav@557
    89
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
jaroslav@557
    90
 * Java Collections Framework</a>.
jaroslav@557
    91
 *
jaroslav@557
    92
 * @param <E> the type of elements in this list
jaroslav@557
    93
 *
jaroslav@557
    94
 * @author  Josh Bloch
jaroslav@557
    95
 * @author  Neal Gafter
jaroslav@557
    96
 * @see Collection
jaroslav@557
    97
 * @see Set
jaroslav@557
    98
 * @see ArrayList
jaroslav@557
    99
 * @see LinkedList
jaroslav@557
   100
 * @see Vector
jaroslav@557
   101
 * @see Arrays#asList(Object[])
jaroslav@557
   102
 * @see Collections#nCopies(int, Object)
jaroslav@557
   103
 * @see Collections#EMPTY_LIST
jaroslav@557
   104
 * @see AbstractList
jaroslav@557
   105
 * @see AbstractSequentialList
jaroslav@557
   106
 * @since 1.2
jaroslav@557
   107
 */
jaroslav@557
   108
jaroslav@557
   109
public interface List<E> extends Collection<E> {
jaroslav@557
   110
    // Query Operations
jaroslav@557
   111
jaroslav@557
   112
    /**
jaroslav@557
   113
     * Returns the number of elements in this list.  If this list contains
jaroslav@557
   114
     * more than <tt>Integer.MAX_VALUE</tt> elements, returns
jaroslav@557
   115
     * <tt>Integer.MAX_VALUE</tt>.
jaroslav@557
   116
     *
jaroslav@557
   117
     * @return the number of elements in this list
jaroslav@557
   118
     */
jaroslav@557
   119
    int size();
jaroslav@557
   120
jaroslav@557
   121
    /**
jaroslav@557
   122
     * Returns <tt>true</tt> if this list contains no elements.
jaroslav@557
   123
     *
jaroslav@557
   124
     * @return <tt>true</tt> if this list contains no elements
jaroslav@557
   125
     */
jaroslav@557
   126
    boolean isEmpty();
jaroslav@557
   127
jaroslav@557
   128
    /**
jaroslav@557
   129
     * Returns <tt>true</tt> if this list contains the specified element.
jaroslav@557
   130
     * More formally, returns <tt>true</tt> if and only if this list contains
jaroslav@557
   131
     * at least one element <tt>e</tt> such that
jaroslav@557
   132
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
jaroslav@557
   133
     *
jaroslav@557
   134
     * @param o element whose presence in this list is to be tested
jaroslav@557
   135
     * @return <tt>true</tt> if this list contains the specified element
jaroslav@557
   136
     * @throws ClassCastException if the type of the specified element
jaroslav@557
   137
     *         is incompatible with this list
jaroslav@557
   138
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   139
     * @throws NullPointerException if the specified element is null and this
jaroslav@557
   140
     *         list does not permit null elements
jaroslav@557
   141
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   142
     */
jaroslav@557
   143
    boolean contains(Object o);
jaroslav@557
   144
jaroslav@557
   145
    /**
jaroslav@557
   146
     * Returns an iterator over the elements in this list in proper sequence.
jaroslav@557
   147
     *
jaroslav@557
   148
     * @return an iterator over the elements in this list in proper sequence
jaroslav@557
   149
     */
jaroslav@557
   150
    Iterator<E> iterator();
jaroslav@557
   151
jaroslav@557
   152
    /**
jaroslav@557
   153
     * Returns an array containing all of the elements in this list in proper
jaroslav@557
   154
     * sequence (from first to last element).
jaroslav@557
   155
     *
jaroslav@557
   156
     * <p>The returned array will be "safe" in that no references to it are
jaroslav@557
   157
     * maintained by this list.  (In other words, this method must
jaroslav@557
   158
     * allocate a new array even if this list is backed by an array).
jaroslav@557
   159
     * The caller is thus free to modify the returned array.
jaroslav@557
   160
     *
jaroslav@557
   161
     * <p>This method acts as bridge between array-based and collection-based
jaroslav@557
   162
     * APIs.
jaroslav@557
   163
     *
jaroslav@557
   164
     * @return an array containing all of the elements in this list in proper
jaroslav@557
   165
     *         sequence
jaroslav@557
   166
     * @see Arrays#asList(Object[])
jaroslav@557
   167
     */
jaroslav@557
   168
    Object[] toArray();
jaroslav@557
   169
jaroslav@557
   170
    /**
jaroslav@557
   171
     * Returns an array containing all of the elements in this list in
jaroslav@557
   172
     * proper sequence (from first to last element); the runtime type of
jaroslav@557
   173
     * the returned array is that of the specified array.  If the list fits
jaroslav@557
   174
     * in the specified array, it is returned therein.  Otherwise, a new
jaroslav@557
   175
     * array is allocated with the runtime type of the specified array and
jaroslav@557
   176
     * the size of this list.
jaroslav@557
   177
     *
jaroslav@557
   178
     * <p>If the list fits in the specified array with room to spare (i.e.,
jaroslav@557
   179
     * the array has more elements than the list), the element in the array
jaroslav@557
   180
     * immediately following the end of the list is set to <tt>null</tt>.
jaroslav@557
   181
     * (This is useful in determining the length of the list <i>only</i> if
jaroslav@557
   182
     * the caller knows that the list does not contain any null elements.)
jaroslav@557
   183
     *
jaroslav@557
   184
     * <p>Like the {@link #toArray()} method, this method acts as bridge between
jaroslav@557
   185
     * array-based and collection-based APIs.  Further, this method allows
jaroslav@557
   186
     * precise control over the runtime type of the output array, and may,
jaroslav@557
   187
     * under certain circumstances, be used to save allocation costs.
jaroslav@557
   188
     *
jaroslav@557
   189
     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
jaroslav@557
   190
     * The following code can be used to dump the list into a newly
jaroslav@557
   191
     * allocated array of <tt>String</tt>:
jaroslav@557
   192
     *
jaroslav@557
   193
     * <pre>
jaroslav@557
   194
     *     String[] y = x.toArray(new String[0]);</pre>
jaroslav@557
   195
     *
jaroslav@557
   196
     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
jaroslav@557
   197
     * <tt>toArray()</tt>.
jaroslav@557
   198
     *
jaroslav@557
   199
     * @param a the array into which the elements of this list are to
jaroslav@557
   200
     *          be stored, if it is big enough; otherwise, a new array of the
jaroslav@557
   201
     *          same runtime type is allocated for this purpose.
jaroslav@557
   202
     * @return an array containing the elements of this list
jaroslav@557
   203
     * @throws ArrayStoreException if the runtime type of the specified array
jaroslav@557
   204
     *         is not a supertype of the runtime type of every element in
jaroslav@557
   205
     *         this list
jaroslav@557
   206
     * @throws NullPointerException if the specified array is null
jaroslav@557
   207
     */
jaroslav@557
   208
    <T> T[] toArray(T[] a);
jaroslav@557
   209
jaroslav@557
   210
jaroslav@557
   211
    // Modification Operations
jaroslav@557
   212
jaroslav@557
   213
    /**
jaroslav@557
   214
     * Appends the specified element to the end of this list (optional
jaroslav@557
   215
     * operation).
jaroslav@557
   216
     *
jaroslav@557
   217
     * <p>Lists that support this operation may place limitations on what
jaroslav@557
   218
     * elements may be added to this list.  In particular, some
jaroslav@557
   219
     * lists will refuse to add null elements, and others will impose
jaroslav@557
   220
     * restrictions on the type of elements that may be added.  List
jaroslav@557
   221
     * classes should clearly specify in their documentation any restrictions
jaroslav@557
   222
     * on what elements may be added.
jaroslav@557
   223
     *
jaroslav@557
   224
     * @param e element to be appended to this list
jaroslav@557
   225
     * @return <tt>true</tt> (as specified by {@link Collection#add})
jaroslav@557
   226
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
jaroslav@557
   227
     *         is not supported by this list
jaroslav@557
   228
     * @throws ClassCastException if the class of the specified element
jaroslav@557
   229
     *         prevents it from being added to this list
jaroslav@557
   230
     * @throws NullPointerException if the specified element is null and this
jaroslav@557
   231
     *         list does not permit null elements
jaroslav@557
   232
     * @throws IllegalArgumentException if some property of this element
jaroslav@557
   233
     *         prevents it from being added to this list
jaroslav@557
   234
     */
jaroslav@557
   235
    boolean add(E e);
jaroslav@557
   236
jaroslav@557
   237
    /**
jaroslav@557
   238
     * Removes the first occurrence of the specified element from this list,
jaroslav@557
   239
     * if it is present (optional operation).  If this list does not contain
jaroslav@557
   240
     * the element, it is unchanged.  More formally, removes the element with
jaroslav@557
   241
     * the lowest index <tt>i</tt> such that
jaroslav@557
   242
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
jaroslav@557
   243
     * (if such an element exists).  Returns <tt>true</tt> if this list
jaroslav@557
   244
     * contained the specified element (or equivalently, if this list changed
jaroslav@557
   245
     * as a result of the call).
jaroslav@557
   246
     *
jaroslav@557
   247
     * @param o element to be removed from this list, if present
jaroslav@557
   248
     * @return <tt>true</tt> if this list contained the specified element
jaroslav@557
   249
     * @throws ClassCastException if the type of the specified element
jaroslav@557
   250
     *         is incompatible with this list
jaroslav@557
   251
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   252
     * @throws NullPointerException if the specified element is null and this
jaroslav@557
   253
     *         list does not permit null elements
jaroslav@557
   254
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   255
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
jaroslav@557
   256
     *         is not supported by this list
jaroslav@557
   257
     */
jaroslav@557
   258
    boolean remove(Object o);
jaroslav@557
   259
jaroslav@557
   260
jaroslav@557
   261
    // Bulk Modification Operations
jaroslav@557
   262
jaroslav@557
   263
    /**
jaroslav@557
   264
     * Returns <tt>true</tt> if this list contains all of the elements of the
jaroslav@557
   265
     * specified collection.
jaroslav@557
   266
     *
jaroslav@557
   267
     * @param  c collection to be checked for containment in this list
jaroslav@557
   268
     * @return <tt>true</tt> if this list contains all of the elements of the
jaroslav@557
   269
     *         specified collection
jaroslav@557
   270
     * @throws ClassCastException if the types of one or more elements
jaroslav@557
   271
     *         in the specified collection are incompatible with this
jaroslav@557
   272
     *         list
jaroslav@557
   273
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   274
     * @throws NullPointerException if the specified collection contains one
jaroslav@557
   275
     *         or more null elements and this list does not permit null
jaroslav@557
   276
     *         elements
jaroslav@557
   277
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
jaroslav@557
   278
     *         or if the specified collection is null
jaroslav@557
   279
     * @see #contains(Object)
jaroslav@557
   280
     */
jaroslav@557
   281
    boolean containsAll(Collection<?> c);
jaroslav@557
   282
jaroslav@557
   283
    /**
jaroslav@557
   284
     * Appends all of the elements in the specified collection to the end of
jaroslav@557
   285
     * this list, in the order that they are returned by the specified
jaroslav@557
   286
     * collection's iterator (optional operation).  The behavior of this
jaroslav@557
   287
     * operation is undefined if the specified collection is modified while
jaroslav@557
   288
     * the operation is in progress.  (Note that this will occur if the
jaroslav@557
   289
     * specified collection is this list, and it's nonempty.)
jaroslav@557
   290
     *
jaroslav@557
   291
     * @param c collection containing elements to be added to this list
jaroslav@557
   292
     * @return <tt>true</tt> if this list changed as a result of the call
jaroslav@557
   293
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
jaroslav@557
   294
     *         is not supported by this list
jaroslav@557
   295
     * @throws ClassCastException if the class of an element of the specified
jaroslav@557
   296
     *         collection prevents it from being added to this list
jaroslav@557
   297
     * @throws NullPointerException if the specified collection contains one
jaroslav@557
   298
     *         or more null elements and this list does not permit null
jaroslav@557
   299
     *         elements, or if the specified collection is null
jaroslav@557
   300
     * @throws IllegalArgumentException if some property of an element of the
jaroslav@557
   301
     *         specified collection prevents it from being added to this list
jaroslav@557
   302
     * @see #add(Object)
jaroslav@557
   303
     */
jaroslav@557
   304
    boolean addAll(Collection<? extends E> c);
jaroslav@557
   305
jaroslav@557
   306
    /**
jaroslav@557
   307
     * Inserts all of the elements in the specified collection into this
jaroslav@557
   308
     * list at the specified position (optional operation).  Shifts the
jaroslav@557
   309
     * element currently at that position (if any) and any subsequent
jaroslav@557
   310
     * elements to the right (increases their indices).  The new elements
jaroslav@557
   311
     * will appear in this list in the order that they are returned by the
jaroslav@557
   312
     * specified collection's iterator.  The behavior of this operation is
jaroslav@557
   313
     * undefined if the specified collection is modified while the
jaroslav@557
   314
     * operation is in progress.  (Note that this will occur if the specified
jaroslav@557
   315
     * collection is this list, and it's nonempty.)
jaroslav@557
   316
     *
jaroslav@557
   317
     * @param index index at which to insert the first element from the
jaroslav@557
   318
     *              specified collection
jaroslav@557
   319
     * @param c collection containing elements to be added to this list
jaroslav@557
   320
     * @return <tt>true</tt> if this list changed as a result of the call
jaroslav@557
   321
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
jaroslav@557
   322
     *         is not supported by this list
jaroslav@557
   323
     * @throws ClassCastException if the class of an element of the specified
jaroslav@557
   324
     *         collection prevents it from being added to this list
jaroslav@557
   325
     * @throws NullPointerException if the specified collection contains one
jaroslav@557
   326
     *         or more null elements and this list does not permit null
jaroslav@557
   327
     *         elements, or if the specified collection is null
jaroslav@557
   328
     * @throws IllegalArgumentException if some property of an element of the
jaroslav@557
   329
     *         specified collection prevents it from being added to this list
jaroslav@557
   330
     * @throws IndexOutOfBoundsException if the index is out of range
jaroslav@557
   331
     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
jaroslav@557
   332
     */
jaroslav@557
   333
    boolean addAll(int index, Collection<? extends E> c);
jaroslav@557
   334
jaroslav@557
   335
    /**
jaroslav@557
   336
     * Removes from this list all of its elements that are contained in the
jaroslav@557
   337
     * specified collection (optional operation).
jaroslav@557
   338
     *
jaroslav@557
   339
     * @param c collection containing elements to be removed from this list
jaroslav@557
   340
     * @return <tt>true</tt> if this list changed as a result of the call
jaroslav@557
   341
     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
jaroslav@557
   342
     *         is not supported by this list
jaroslav@557
   343
     * @throws ClassCastException if the class of an element of this list
jaroslav@557
   344
     *         is incompatible with the specified collection
jaroslav@557
   345
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   346
     * @throws NullPointerException if this list contains a null element and the
jaroslav@557
   347
     *         specified collection does not permit null elements
jaroslav@557
   348
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
jaroslav@557
   349
     *         or if the specified collection is null
jaroslav@557
   350
     * @see #remove(Object)
jaroslav@557
   351
     * @see #contains(Object)
jaroslav@557
   352
     */
jaroslav@557
   353
    boolean removeAll(Collection<?> c);
jaroslav@557
   354
jaroslav@557
   355
    /**
jaroslav@557
   356
     * Retains only the elements in this list that are contained in the
jaroslav@557
   357
     * specified collection (optional operation).  In other words, removes
jaroslav@557
   358
     * from this list all of its elements that are not contained in the
jaroslav@557
   359
     * specified collection.
jaroslav@557
   360
     *
jaroslav@557
   361
     * @param c collection containing elements to be retained in this list
jaroslav@557
   362
     * @return <tt>true</tt> if this list changed as a result of the call
jaroslav@557
   363
     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
jaroslav@557
   364
     *         is not supported by this list
jaroslav@557
   365
     * @throws ClassCastException if the class of an element of this list
jaroslav@557
   366
     *         is incompatible with the specified collection
jaroslav@557
   367
     * (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   368
     * @throws NullPointerException if this list contains a null element and the
jaroslav@557
   369
     *         specified collection does not permit null elements
jaroslav@557
   370
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
jaroslav@557
   371
     *         or if the specified collection is null
jaroslav@557
   372
     * @see #remove(Object)
jaroslav@557
   373
     * @see #contains(Object)
jaroslav@557
   374
     */
jaroslav@557
   375
    boolean retainAll(Collection<?> c);
jaroslav@557
   376
jaroslav@557
   377
    /**
jaroslav@557
   378
     * Removes all of the elements from this list (optional operation).
jaroslav@557
   379
     * The list will be empty after this call returns.
jaroslav@557
   380
     *
jaroslav@557
   381
     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
jaroslav@557
   382
     *         is not supported by this list
jaroslav@557
   383
     */
jaroslav@557
   384
    void clear();
jaroslav@557
   385
jaroslav@557
   386
jaroslav@557
   387
    // Comparison and hashing
jaroslav@557
   388
jaroslav@557
   389
    /**
jaroslav@557
   390
     * Compares the specified object with this list for equality.  Returns
jaroslav@557
   391
     * <tt>true</tt> if and only if the specified object is also a list, both
jaroslav@557
   392
     * lists have the same size, and all corresponding pairs of elements in
jaroslav@557
   393
     * the two lists are <i>equal</i>.  (Two elements <tt>e1</tt> and
jaroslav@557
   394
     * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null :
jaroslav@557
   395
     * e1.equals(e2))</tt>.)  In other words, two lists are defined to be
jaroslav@557
   396
     * equal if they contain the same elements in the same order.  This
jaroslav@557
   397
     * definition ensures that the equals method works properly across
jaroslav@557
   398
     * different implementations of the <tt>List</tt> interface.
jaroslav@557
   399
     *
jaroslav@557
   400
     * @param o the object to be compared for equality with this list
jaroslav@557
   401
     * @return <tt>true</tt> if the specified object is equal to this list
jaroslav@557
   402
     */
jaroslav@557
   403
    boolean equals(Object o);
jaroslav@557
   404
jaroslav@557
   405
    /**
jaroslav@557
   406
     * Returns the hash code value for this list.  The hash code of a list
jaroslav@557
   407
     * is defined to be the result of the following calculation:
jaroslav@557
   408
     * <pre>
jaroslav@557
   409
     *  int hashCode = 1;
jaroslav@557
   410
     *  for (E e : list)
jaroslav@557
   411
     *      hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
jaroslav@557
   412
     * </pre>
jaroslav@557
   413
     * This ensures that <tt>list1.equals(list2)</tt> implies that
jaroslav@557
   414
     * <tt>list1.hashCode()==list2.hashCode()</tt> for any two lists,
jaroslav@557
   415
     * <tt>list1</tt> and <tt>list2</tt>, as required by the general
jaroslav@557
   416
     * contract of {@link Object#hashCode}.
jaroslav@557
   417
     *
jaroslav@557
   418
     * @return the hash code value for this list
jaroslav@557
   419
     * @see Object#equals(Object)
jaroslav@557
   420
     * @see #equals(Object)
jaroslav@557
   421
     */
jaroslav@557
   422
    int hashCode();
jaroslav@557
   423
jaroslav@557
   424
jaroslav@557
   425
    // Positional Access Operations
jaroslav@557
   426
jaroslav@557
   427
    /**
jaroslav@557
   428
     * Returns the element at the specified position in this list.
jaroslav@557
   429
     *
jaroslav@557
   430
     * @param index index of the element to return
jaroslav@557
   431
     * @return the element at the specified position in this list
jaroslav@557
   432
     * @throws IndexOutOfBoundsException if the index is out of range
jaroslav@557
   433
     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
jaroslav@557
   434
     */
jaroslav@557
   435
    E get(int index);
jaroslav@557
   436
jaroslav@557
   437
    /**
jaroslav@557
   438
     * Replaces the element at the specified position in this list with the
jaroslav@557
   439
     * specified element (optional operation).
jaroslav@557
   440
     *
jaroslav@557
   441
     * @param index index of the element to replace
jaroslav@557
   442
     * @param element element to be stored at the specified position
jaroslav@557
   443
     * @return the element previously at the specified position
jaroslav@557
   444
     * @throws UnsupportedOperationException if the <tt>set</tt> operation
jaroslav@557
   445
     *         is not supported by this list
jaroslav@557
   446
     * @throws ClassCastException if the class of the specified element
jaroslav@557
   447
     *         prevents it from being added to this list
jaroslav@557
   448
     * @throws NullPointerException if the specified element is null and
jaroslav@557
   449
     *         this list does not permit null elements
jaroslav@557
   450
     * @throws IllegalArgumentException if some property of the specified
jaroslav@557
   451
     *         element prevents it from being added to this list
jaroslav@557
   452
     * @throws IndexOutOfBoundsException if the index is out of range
jaroslav@557
   453
     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
jaroslav@557
   454
     */
jaroslav@557
   455
    E set(int index, E element);
jaroslav@557
   456
jaroslav@557
   457
    /**
jaroslav@557
   458
     * Inserts the specified element at the specified position in this list
jaroslav@557
   459
     * (optional operation).  Shifts the element currently at that position
jaroslav@557
   460
     * (if any) and any subsequent elements to the right (adds one to their
jaroslav@557
   461
     * indices).
jaroslav@557
   462
     *
jaroslav@557
   463
     * @param index index at which the specified element is to be inserted
jaroslav@557
   464
     * @param element element to be inserted
jaroslav@557
   465
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
jaroslav@557
   466
     *         is not supported by this list
jaroslav@557
   467
     * @throws ClassCastException if the class of the specified element
jaroslav@557
   468
     *         prevents it from being added to this list
jaroslav@557
   469
     * @throws NullPointerException if the specified element is null and
jaroslav@557
   470
     *         this list does not permit null elements
jaroslav@557
   471
     * @throws IllegalArgumentException if some property of the specified
jaroslav@557
   472
     *         element prevents it from being added to this list
jaroslav@557
   473
     * @throws IndexOutOfBoundsException if the index is out of range
jaroslav@557
   474
     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
jaroslav@557
   475
     */
jaroslav@557
   476
    void add(int index, E element);
jaroslav@557
   477
jaroslav@557
   478
    /**
jaroslav@557
   479
     * Removes the element at the specified position in this list (optional
jaroslav@557
   480
     * operation).  Shifts any subsequent elements to the left (subtracts one
jaroslav@557
   481
     * from their indices).  Returns the element that was removed from the
jaroslav@557
   482
     * list.
jaroslav@557
   483
     *
jaroslav@557
   484
     * @param index the index of the element to be removed
jaroslav@557
   485
     * @return the element previously at the specified position
jaroslav@557
   486
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
jaroslav@557
   487
     *         is not supported by this list
jaroslav@557
   488
     * @throws IndexOutOfBoundsException if the index is out of range
jaroslav@557
   489
     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
jaroslav@557
   490
     */
jaroslav@557
   491
    E remove(int index);
jaroslav@557
   492
jaroslav@557
   493
jaroslav@557
   494
    // Search Operations
jaroslav@557
   495
jaroslav@557
   496
    /**
jaroslav@557
   497
     * Returns the index of the first occurrence of the specified element
jaroslav@557
   498
     * in this list, or -1 if this list does not contain the element.
jaroslav@557
   499
     * More formally, returns the lowest index <tt>i</tt> such that
jaroslav@557
   500
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
jaroslav@557
   501
     * or -1 if there is no such index.
jaroslav@557
   502
     *
jaroslav@557
   503
     * @param o element to search for
jaroslav@557
   504
     * @return the index of the first occurrence of the specified element in
jaroslav@557
   505
     *         this list, or -1 if this list does not contain the element
jaroslav@557
   506
     * @throws ClassCastException if the type of the specified element
jaroslav@557
   507
     *         is incompatible with this list
jaroslav@557
   508
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   509
     * @throws NullPointerException if the specified element is null and this
jaroslav@557
   510
     *         list does not permit null elements
jaroslav@557
   511
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   512
     */
jaroslav@557
   513
    int indexOf(Object o);
jaroslav@557
   514
jaroslav@557
   515
    /**
jaroslav@557
   516
     * Returns the index of the last occurrence of the specified element
jaroslav@557
   517
     * in this list, or -1 if this list does not contain the element.
jaroslav@557
   518
     * More formally, returns the highest index <tt>i</tt> such that
jaroslav@557
   519
     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
jaroslav@557
   520
     * or -1 if there is no such index.
jaroslav@557
   521
     *
jaroslav@557
   522
     * @param o element to search for
jaroslav@557
   523
     * @return the index of the last occurrence of the specified element in
jaroslav@557
   524
     *         this list, or -1 if this list does not contain the element
jaroslav@557
   525
     * @throws ClassCastException if the type of the specified element
jaroslav@557
   526
     *         is incompatible with this list
jaroslav@557
   527
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   528
     * @throws NullPointerException if the specified element is null and this
jaroslav@557
   529
     *         list does not permit null elements
jaroslav@557
   530
     *         (<a href="Collection.html#optional-restrictions">optional</a>)
jaroslav@557
   531
     */
jaroslav@557
   532
    int lastIndexOf(Object o);
jaroslav@557
   533
jaroslav@557
   534
jaroslav@557
   535
    // List Iterators
jaroslav@557
   536
jaroslav@557
   537
    /**
jaroslav@557
   538
     * Returns a list iterator over the elements in this list (in proper
jaroslav@557
   539
     * sequence).
jaroslav@557
   540
     *
jaroslav@557
   541
     * @return a list iterator over the elements in this list (in proper
jaroslav@557
   542
     *         sequence)
jaroslav@557
   543
     */
jaroslav@557
   544
    ListIterator<E> listIterator();
jaroslav@557
   545
jaroslav@557
   546
    /**
jaroslav@557
   547
     * Returns a list iterator over the elements in this list (in proper
jaroslav@557
   548
     * sequence), starting at the specified position in the list.
jaroslav@557
   549
     * The specified index indicates the first element that would be
jaroslav@557
   550
     * returned by an initial call to {@link ListIterator#next next}.
jaroslav@557
   551
     * An initial call to {@link ListIterator#previous previous} would
jaroslav@557
   552
     * return the element with the specified index minus one.
jaroslav@557
   553
     *
jaroslav@557
   554
     * @param index index of the first element to be returned from the
jaroslav@557
   555
     *        list iterator (by a call to {@link ListIterator#next next})
jaroslav@557
   556
     * @return a list iterator over the elements in this list (in proper
jaroslav@557
   557
     *         sequence), starting at the specified position in the list
jaroslav@557
   558
     * @throws IndexOutOfBoundsException if the index is out of range
jaroslav@557
   559
     *         ({@code index < 0 || index > size()})
jaroslav@557
   560
     */
jaroslav@557
   561
    ListIterator<E> listIterator(int index);
jaroslav@557
   562
jaroslav@557
   563
    // View
jaroslav@557
   564
jaroslav@557
   565
    /**
jaroslav@557
   566
     * Returns a view of the portion of this list between the specified
jaroslav@557
   567
     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.  (If
jaroslav@557
   568
     * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is
jaroslav@557
   569
     * empty.)  The returned list is backed by this list, so non-structural
jaroslav@557
   570
     * changes in the returned list are reflected in this list, and vice-versa.
jaroslav@557
   571
     * The returned list supports all of the optional list operations supported
jaroslav@557
   572
     * by this list.<p>
jaroslav@557
   573
     *
jaroslav@557
   574
     * This method eliminates the need for explicit range operations (of
jaroslav@557
   575
     * the sort that commonly exist for arrays).  Any operation that expects
jaroslav@557
   576
     * a list can be used as a range operation by passing a subList view
jaroslav@557
   577
     * instead of a whole list.  For example, the following idiom
jaroslav@557
   578
     * removes a range of elements from a list:
jaroslav@557
   579
     * <pre>
jaroslav@557
   580
     *      list.subList(from, to).clear();
jaroslav@557
   581
     * </pre>
jaroslav@557
   582
     * Similar idioms may be constructed for <tt>indexOf</tt> and
jaroslav@557
   583
     * <tt>lastIndexOf</tt>, and all of the algorithms in the
jaroslav@557
   584
     * <tt>Collections</tt> class can be applied to a subList.<p>
jaroslav@557
   585
     *
jaroslav@557
   586
     * The semantics of the list returned by this method become undefined if
jaroslav@557
   587
     * the backing list (i.e., this list) is <i>structurally modified</i> in
jaroslav@557
   588
     * any way other than via the returned list.  (Structural modifications are
jaroslav@557
   589
     * those that change the size of this list, or otherwise perturb it in such
jaroslav@557
   590
     * a fashion that iterations in progress may yield incorrect results.)
jaroslav@557
   591
     *
jaroslav@557
   592
     * @param fromIndex low endpoint (inclusive) of the subList
jaroslav@557
   593
     * @param toIndex high endpoint (exclusive) of the subList
jaroslav@557
   594
     * @return a view of the specified range within this list
jaroslav@557
   595
     * @throws IndexOutOfBoundsException for an illegal endpoint index value
jaroslav@557
   596
     *         (<tt>fromIndex &lt; 0 || toIndex &gt; size ||
jaroslav@557
   597
     *         fromIndex &gt; toIndex</tt>)
jaroslav@557
   598
     */
jaroslav@557
   599
    List<E> subList(int fromIndex, int toIndex);
jaroslav@557
   600
}