jdk/src/java.base/share/classes/java/util/AbstractSequentialList.java
author mchung
Fri, 22 May 2015 16:43:39 -0700
changeset 30789 9eca83469588
parent 25859 3317bb8137f4
child 32108 aa5490a167ee
permissions -rw-r--r--
8074431: Remove native2ascii tool Reviewed-by: erikj, alanb, okutsu, mfang, naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This class provides a skeletal implementation of the <tt>List</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * interface to minimize the effort required to implement this interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * backed by a "sequential access" data store (such as a linked list).  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * random access data (such as an array), <tt>AbstractList</tt> should be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * in preference to this class.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class is the opposite of the <tt>AbstractList</tt> class in the sense
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * that it implements the "random access" methods (<tt>get(int index)</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <tt>set(int index, E element)</tt>, <tt>add(int index, E element)</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <tt>remove(int index)</tt>) on top of the list's list iterator, instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the other way around.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * To implement a list the programmer needs only to extend this class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * provide implementations for the <tt>listIterator</tt> and <tt>size</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * methods.  For an unmodifiable list, the programmer need only implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * list iterator's <tt>hasNext</tt>, <tt>next</tt>, <tt>hasPrevious</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <tt>previous</tt> and <tt>index</tt> methods.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * For a modifiable list the programmer should additionally implement the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * iterator's <tt>set</tt> method.  For a variable-size list the programmer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * should additionally implement the list iterator's <tt>remove</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <tt>add</tt> methods.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The programmer should generally provide a void (no argument) and collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * constructor, as per the recommendation in the <tt>Collection</tt> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * specification.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This class is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @author  Neal Gafter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see List
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see AbstractList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see AbstractCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public abstract class AbstractSequentialList<E> extends AbstractList<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected AbstractSequentialList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Returns the element at the specified position in this list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * <p>This implementation first gets a list iterator pointing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * the element using <tt>ListIterator.next</tt> and returns it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public E get(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return listIterator(index).next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } catch (NoSuchElementException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new IndexOutOfBoundsException("Index: "+index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Replaces the element at the specified position in this list with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * specified element (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * <p>This implementation first gets a list iterator pointing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * the current element using <tt>ListIterator.next</tt> and replaces it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * with <tt>ListIterator.set</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <p>Note that this implementation will throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <tt>UnsupportedOperationException</tt> if the list iterator does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * implement the <tt>set</tt> operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws UnsupportedOperationException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @throws ClassCastException            {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws NullPointerException          {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws IllegalArgumentException      {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @throws IndexOutOfBoundsException     {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public E set(int index, E element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            ListIterator<E> e = listIterator(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            E oldVal = e.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            e.set(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return oldVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } catch (NoSuchElementException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new IndexOutOfBoundsException("Index: "+index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Inserts the specified element at the specified position in this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * (optional operation).  Shifts the element currently at that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * (if any) and any subsequent elements to the right (adds one to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * indices).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p>This implementation first gets a list iterator pointing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * indexed element (with <tt>listIterator(index)</tt>).  Then, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * inserts the specified element with <tt>ListIterator.add</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <p>Note that this implementation will throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <tt>UnsupportedOperationException</tt> if the list iterator does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * implement the <tt>add</tt> operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws UnsupportedOperationException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @throws ClassCastException            {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @throws NullPointerException          {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @throws IllegalArgumentException      {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @throws IndexOutOfBoundsException     {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void add(int index, E element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            listIterator(index).add(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        } catch (NoSuchElementException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new IndexOutOfBoundsException("Index: "+index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Removes the element at the specified position in this list (optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * operation).  Shifts any subsequent elements to the left (subtracts one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * from their indices).  Returns the element that was removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <p>This implementation first gets a list iterator pointing to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * indexed element (with <tt>listIterator(index)</tt>).  Then, it removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * the element with <tt>ListIterator.remove</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <p>Note that this implementation will throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <tt>UnsupportedOperationException</tt> if the list iterator does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * implement the <tt>remove</tt> operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws UnsupportedOperationException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @throws IndexOutOfBoundsException     {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public E remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            ListIterator<E> e = listIterator(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            E outCast = e.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            e.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            return outCast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        } catch (NoSuchElementException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            throw new IndexOutOfBoundsException("Index: "+index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    // Bulk Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Inserts all of the elements in the specified collection into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * list at the specified position (optional operation).  Shifts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * element currently at that position (if any) and any subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * elements to the right (increases their indices).  The new elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * will appear in this list in the order that they are returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * specified collection's iterator.  The behavior of this operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * undefined if the specified collection is modified while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * operation is in progress.  (Note that this will occur if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * collection is this list, and it's nonempty.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <p>This implementation gets an iterator over the specified collection and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * a list iterator over this list pointing to the indexed element (with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <tt>listIterator(index)</tt>).  Then, it iterates over the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * collection, inserting the elements obtained from the iterator into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * list, one at a time, using <tt>ListIterator.add</tt> followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <tt>ListIterator.next</tt> (to skip over the added element).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <p>Note that this implementation will throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <tt>UnsupportedOperationException</tt> if the list iterator returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * the <tt>listIterator</tt> method does not implement the <tt>add</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @throws UnsupportedOperationException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @throws ClassCastException            {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @throws NullPointerException          {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @throws IllegalArgumentException      {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @throws IndexOutOfBoundsException     {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public boolean addAll(int index, Collection<? extends E> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            boolean modified = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            ListIterator<E> e1 = listIterator(index);
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 5506
diff changeset
   216
            for (E e : c) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 5506
diff changeset
   217
                e1.add(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                modified = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return modified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } catch (NoSuchElementException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            throw new IndexOutOfBoundsException("Index: "+index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // Iterators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns an iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * sequence).<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * This implementation merely returns a list iterator over the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return an iterator over the elements in this list (in proper sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public Iterator<E> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return listIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * sequence).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param  index index of first element to be returned from the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *         iterator (by a call to the <code>next</code> method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return a list iterator over the elements in this list (in proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *         sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public abstract ListIterator<E> listIterator(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}