jdk/src/share/classes/java/util/ListIterator.java
author sherman
Wed, 04 Mar 2009 09:26:41 -0800
changeset 2178 5a730fff4d0d
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6812879: Excess code line in ArrayList method Summary: Removed the line of "oldData" which is no longer used. Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
 * An iterator for lists that allows the programmer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * to traverse the list in either direction, modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * the list during iteration, and obtain the iterator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * current position in the list. A {@code ListIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * has no current element; its <I>cursor position</I> always
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * lies between the element that would be returned by a call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * to {@code previous()} and the element that would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * returned by a call to {@code next()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * An iterator for a list of length {@code n} has {@code n+1} possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * cursor positions, as illustrated by the carets ({@code ^}) below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *                      Element(0)   Element(1)   Element(2)   ... Element(n-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * cursor positions:  ^            ^            ^            ^                  ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Note that the {@link #remove} and {@link #set(Object)} methods are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <i>not</i> defined in terms of the cursor position;  they are defined to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * operate on the last element returned by a call to {@link #next} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@link #previous()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see List
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see Iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see Enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see List#listIterator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public interface ListIterator<E> extends Iterator<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Query Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Returns {@code true} if this list iterator has more elements when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * traversing the list in the forward direction. (In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * returns {@code true} if {@link #next} would return an element rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * than throwing an exception.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @return {@code true} if the list iterator has more elements when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *         traversing the list in the forward direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    boolean hasNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Returns the next element in the list and advances the cursor position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * This method may be called repeatedly to iterate through the list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * or intermixed with calls to {@link #previous} to go back and forth.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * (Note that alternating calls to {@code next} and {@code previous}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * will return the same element repeatedly.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @return the next element in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @throws NoSuchElementException if the iteration has no next element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    E next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Returns {@code true} if this list iterator has more elements when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * traversing the list in the reverse direction.  (In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * returns {@code true} if {@link #previous} would return an element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * rather than throwing an exception.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @return {@code true} if the list iterator has more elements when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *         traversing the list in the reverse direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    boolean hasPrevious();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns the previous element in the list and moves the cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * position backwards.  This method may be called repeatedly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * iterate through the list backwards, or intermixed with calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * {@link #next} to go back and forth.  (Note that alternating calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * to {@code next} and {@code previous} will return the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * element repeatedly.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return the previous element in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throws NoSuchElementException if the iteration has no previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *         element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    E previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Returns the index of the element that would be returned by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * subsequent call to {@link #next}. (Returns list size if the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * iterator is at the end of the list.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return the index of the element that would be returned by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *         subsequent call to {@code next}, or list size if the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *         iterator is at the end of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    int nextIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Returns the index of the element that would be returned by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * subsequent call to {@link #previous}. (Returns -1 if the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * iterator is at the beginning of the list.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return the index of the element that would be returned by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         subsequent call to {@code previous}, or -1 if the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *         iterator is at the beginning of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    int previousIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Removes from the list the last element that was returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * #next} or {@link #previous} (optional operation).  This call can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * only be made once per call to {@code next} or {@code previous}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * It can be made only if {@link #add} has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * called after the last call to {@code next} or {@code previous}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @throws UnsupportedOperationException if the {@code remove}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *         operation is not supported by this list iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @throws IllegalStateException if neither {@code next} nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *         {@code previous} have been called, or {@code remove} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *         {@code add} have been called after the last call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *         {@code next} or {@code previous}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    void remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Replaces the last element returned by {@link #next} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * {@link #previous} with the specified element (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * This call can be made only if neither {@link #remove} nor {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * #add} have been called after the last call to {@code next} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * {@code previous}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param e the element with which to replace the last element returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *          {@code next} or {@code previous}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @throws UnsupportedOperationException if the {@code set} operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *         is not supported by this list iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @throws IllegalArgumentException if some aspect of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *         element prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @throws IllegalStateException if neither {@code next} nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *         {@code previous} have been called, or {@code remove} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *         {@code add} have been called after the last call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *         {@code next} or {@code previous}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    void set(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Inserts the specified element into the list (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The element is inserted immediately before the next element that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * would be returned by {@link #next}, if any, and after the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * element that would be returned by {@link #previous}, if any.  (If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * list contains no elements, the new element becomes the sole element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * on the list.)  The new element is inserted before the implicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * cursor: a subsequent call to {@code next} would be unaffected, and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * subsequent call to {@code previous} would return the new element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * (This call increases by one the value that would be returned by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * call to {@code nextIndex} or {@code previousIndex}.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param e the element to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @throws UnsupportedOperationException if the {@code add} method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *         not supported by this list iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @throws IllegalArgumentException if some aspect of this element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         prevents it from being added to this list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    void add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}