2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 * An ListIterator is used to sequence over a List of objects. ListIterator can
23 * move backwards or forwards through the list.
25 public interface ListIterator<E> extends Iterator<E> {
28 * Inserts the specified object into the list between {@code next} and
29 * {@code previous}. The object inserted will be the previous object.
32 * the object to insert.
33 * @throws UnsupportedOperationException
34 * if adding is not supported by the list being iterated.
35 * @throws ClassCastException
36 * if the class of the object is inappropriate for the list.
37 * @throws IllegalArgumentException
38 * if the object cannot be added to the list.
43 * Returns whether there are more elements to iterate.
45 * @return {@code true} if there are more elements, {@code false} otherwise.
48 public boolean hasNext();
51 * Returns whether there are previous elements to iterate.
53 * @return {@code true} if there are previous elements, {@code false}
57 public boolean hasPrevious();
60 * Returns the next object in the iteration.
62 * @return the next object.
63 * @throws NoSuchElementException
64 * if there are no more elements.
70 * Returns the index of the next object in the iteration.
72 * @return the index of the next object, or the size of the list if the
73 * iterator is at the end.
74 * @throws NoSuchElementException
75 * if there are no more elements.
78 public int nextIndex();
81 * Returns the previous object in the iteration.
83 * @return the previous object.
84 * @throws NoSuchElementException
85 * if there are no previous elements.
91 * Returns the index of the previous object in the iteration.
93 * @return the index of the previous object, or -1 if the iterator is at the
95 * @throws NoSuchElementException
96 * if there are no previous elements.
99 public int previousIndex();
102 * Removes the last object returned by {@code next} or {@code previous} from
105 * @throws UnsupportedOperationException
106 * if removing is not supported by the list being iterated.
107 * @throws IllegalStateException
108 * if {@code next} or {@code previous} have not been called, or
109 * {@code remove} or {@code add} have already been called after
110 * the last call to {@code next} or {@code previous}.
112 public void remove();
115 * Replaces the last object returned by {@code next} or {@code previous}
116 * with the specified object.
120 * @throws UnsupportedOperationException
121 * if setting is not supported by the list being iterated
122 * @throws ClassCastException
123 * if the class of the object is inappropriate for the list.
124 * @throws IllegalArgumentException
125 * if the object cannot be added to the list.
126 * @throws IllegalStateException
127 * if {@code next} or {@code previous} have not been called, or
128 * {@code remove} or {@code add} have already been called after
129 * the last call to {@code next} or {@code previous}.