rt/emul/compact/src/main/java/java/util/ListIterator.java
changeset 772 d382dacfd73f
parent 557 5be31d9fa455
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compact/src/main/java/java/util/ListIterator.java	Tue Feb 26 16:54:16 2013 +0100
     1.3 @@ -0,0 +1,195 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.util;
    1.30 +
    1.31 +/**
    1.32 + * An iterator for lists that allows the programmer
    1.33 + * to traverse the list in either direction, modify
    1.34 + * the list during iteration, and obtain the iterator's
    1.35 + * current position in the list. A {@code ListIterator}
    1.36 + * has no current element; its <I>cursor position</I> always
    1.37 + * lies between the element that would be returned by a call
    1.38 + * to {@code previous()} and the element that would be
    1.39 + * returned by a call to {@code next()}.
    1.40 + * An iterator for a list of length {@code n} has {@code n+1} possible
    1.41 + * cursor positions, as illustrated by the carets ({@code ^}) below:
    1.42 + * <PRE>
    1.43 + *                      Element(0)   Element(1)   Element(2)   ... Element(n-1)
    1.44 + * cursor positions:  ^            ^            ^            ^                  ^
    1.45 + * </PRE>
    1.46 + * Note that the {@link #remove} and {@link #set(Object)} methods are
    1.47 + * <i>not</i> defined in terms of the cursor position;  they are defined to
    1.48 + * operate on the last element returned by a call to {@link #next} or
    1.49 + * {@link #previous()}.
    1.50 + *
    1.51 + * <p>This interface is a member of the
    1.52 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
    1.53 + * Java Collections Framework</a>.
    1.54 + *
    1.55 + * @author  Josh Bloch
    1.56 + * @see Collection
    1.57 + * @see List
    1.58 + * @see Iterator
    1.59 + * @see Enumeration
    1.60 + * @see List#listIterator()
    1.61 + * @since   1.2
    1.62 + */
    1.63 +public interface ListIterator<E> extends Iterator<E> {
    1.64 +    // Query Operations
    1.65 +
    1.66 +    /**
    1.67 +     * Returns {@code true} if this list iterator has more elements when
    1.68 +     * traversing the list in the forward direction. (In other words,
    1.69 +     * returns {@code true} if {@link #next} would return an element rather
    1.70 +     * than throwing an exception.)
    1.71 +     *
    1.72 +     * @return {@code true} if the list iterator has more elements when
    1.73 +     *         traversing the list in the forward direction
    1.74 +     */
    1.75 +    boolean hasNext();
    1.76 +
    1.77 +    /**
    1.78 +     * Returns the next element in the list and advances the cursor position.
    1.79 +     * This method may be called repeatedly to iterate through the list,
    1.80 +     * or intermixed with calls to {@link #previous} to go back and forth.
    1.81 +     * (Note that alternating calls to {@code next} and {@code previous}
    1.82 +     * will return the same element repeatedly.)
    1.83 +     *
    1.84 +     * @return the next element in the list
    1.85 +     * @throws NoSuchElementException if the iteration has no next element
    1.86 +     */
    1.87 +    E next();
    1.88 +
    1.89 +    /**
    1.90 +     * Returns {@code true} if this list iterator has more elements when
    1.91 +     * traversing the list in the reverse direction.  (In other words,
    1.92 +     * returns {@code true} if {@link #previous} would return an element
    1.93 +     * rather than throwing an exception.)
    1.94 +     *
    1.95 +     * @return {@code true} if the list iterator has more elements when
    1.96 +     *         traversing the list in the reverse direction
    1.97 +     */
    1.98 +    boolean hasPrevious();
    1.99 +
   1.100 +    /**
   1.101 +     * Returns the previous element in the list and moves the cursor
   1.102 +     * position backwards.  This method may be called repeatedly to
   1.103 +     * iterate through the list backwards, or intermixed with calls to
   1.104 +     * {@link #next} to go back and forth.  (Note that alternating calls
   1.105 +     * to {@code next} and {@code previous} will return the same
   1.106 +     * element repeatedly.)
   1.107 +     *
   1.108 +     * @return the previous element in the list
   1.109 +     * @throws NoSuchElementException if the iteration has no previous
   1.110 +     *         element
   1.111 +     */
   1.112 +    E previous();
   1.113 +
   1.114 +    /**
   1.115 +     * Returns the index of the element that would be returned by a
   1.116 +     * subsequent call to {@link #next}. (Returns list size if the list
   1.117 +     * iterator is at the end of the list.)
   1.118 +     *
   1.119 +     * @return the index of the element that would be returned by a
   1.120 +     *         subsequent call to {@code next}, or list size if the list
   1.121 +     *         iterator is at the end of the list
   1.122 +     */
   1.123 +    int nextIndex();
   1.124 +
   1.125 +    /**
   1.126 +     * Returns the index of the element that would be returned by a
   1.127 +     * subsequent call to {@link #previous}. (Returns -1 if the list
   1.128 +     * iterator is at the beginning of the list.)
   1.129 +     *
   1.130 +     * @return the index of the element that would be returned by a
   1.131 +     *         subsequent call to {@code previous}, or -1 if the list
   1.132 +     *         iterator is at the beginning of the list
   1.133 +     */
   1.134 +    int previousIndex();
   1.135 +
   1.136 +
   1.137 +    // Modification Operations
   1.138 +
   1.139 +    /**
   1.140 +     * Removes from the list the last element that was returned by {@link
   1.141 +     * #next} or {@link #previous} (optional operation).  This call can
   1.142 +     * only be made once per call to {@code next} or {@code previous}.
   1.143 +     * It can be made only if {@link #add} has not been
   1.144 +     * called after the last call to {@code next} or {@code previous}.
   1.145 +     *
   1.146 +     * @throws UnsupportedOperationException if the {@code remove}
   1.147 +     *         operation is not supported by this list iterator
   1.148 +     * @throws IllegalStateException if neither {@code next} nor
   1.149 +     *         {@code previous} have been called, or {@code remove} or
   1.150 +     *         {@code add} have been called after the last call to
   1.151 +     *         {@code next} or {@code previous}
   1.152 +     */
   1.153 +    void remove();
   1.154 +
   1.155 +    /**
   1.156 +     * Replaces the last element returned by {@link #next} or
   1.157 +     * {@link #previous} with the specified element (optional operation).
   1.158 +     * This call can be made only if neither {@link #remove} nor {@link
   1.159 +     * #add} have been called after the last call to {@code next} or
   1.160 +     * {@code previous}.
   1.161 +     *
   1.162 +     * @param e the element with which to replace the last element returned by
   1.163 +     *          {@code next} or {@code previous}
   1.164 +     * @throws UnsupportedOperationException if the {@code set} operation
   1.165 +     *         is not supported by this list iterator
   1.166 +     * @throws ClassCastException if the class of the specified element
   1.167 +     *         prevents it from being added to this list
   1.168 +     * @throws IllegalArgumentException if some aspect of the specified
   1.169 +     *         element prevents it from being added to this list
   1.170 +     * @throws IllegalStateException if neither {@code next} nor
   1.171 +     *         {@code previous} have been called, or {@code remove} or
   1.172 +     *         {@code add} have been called after the last call to
   1.173 +     *         {@code next} or {@code previous}
   1.174 +     */
   1.175 +    void set(E e);
   1.176 +
   1.177 +    /**
   1.178 +     * Inserts the specified element into the list (optional operation).
   1.179 +     * The element is inserted immediately before the element that
   1.180 +     * would be returned by {@link #next}, if any, and after the element
   1.181 +     * that would be returned by {@link #previous}, if any.  (If the
   1.182 +     * list contains no elements, the new element becomes the sole element
   1.183 +     * on the list.)  The new element is inserted before the implicit
   1.184 +     * cursor: a subsequent call to {@code next} would be unaffected, and a
   1.185 +     * subsequent call to {@code previous} would return the new element.
   1.186 +     * (This call increases by one the value that would be returned by a
   1.187 +     * call to {@code nextIndex} or {@code previousIndex}.)
   1.188 +     *
   1.189 +     * @param e the element to insert
   1.190 +     * @throws UnsupportedOperationException if the {@code add} method is
   1.191 +     *         not supported by this list iterator
   1.192 +     * @throws ClassCastException if the class of the specified element
   1.193 +     *         prevents it from being added to this list
   1.194 +     * @throws IllegalArgumentException if some aspect of this element
   1.195 +     *         prevents it from being added to this list
   1.196 +     */
   1.197 +    void add(E e);
   1.198 +}