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