1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/emul/compact/src/main/java/java/util/Vector.java Mon Jan 28 13:28:02 2013 +0100
1.3 @@ -0,0 +1,1212 @@
1.4 +/*
1.5 + * Copyright (c) 1994, 2011, 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 + * The {@code Vector} class implements a growable array of
1.33 + * objects. Like an array, it contains components that can be
1.34 + * accessed using an integer index. However, the size of a
1.35 + * {@code Vector} can grow or shrink as needed to accommodate
1.36 + * adding and removing items after the {@code Vector} has been created.
1.37 + *
1.38 + * <p>Each vector tries to optimize storage management by maintaining a
1.39 + * {@code capacity} and a {@code capacityIncrement}. The
1.40 + * {@code capacity} is always at least as large as the vector
1.41 + * size; it is usually larger because as components are added to the
1.42 + * vector, the vector's storage increases in chunks the size of
1.43 + * {@code capacityIncrement}. An application can increase the
1.44 + * capacity of a vector before inserting a large number of
1.45 + * components; this reduces the amount of incremental reallocation.
1.46 + *
1.47 + * <p><a name="fail-fast"/>
1.48 + * The iterators returned by this class's {@link #iterator() iterator} and
1.49 + * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
1.50 + * if the vector is structurally modified at any time after the iterator is
1.51 + * created, in any way except through the iterator's own
1.52 + * {@link ListIterator#remove() remove} or
1.53 + * {@link ListIterator#add(Object) add} methods, the iterator will throw a
1.54 + * {@link ConcurrentModificationException}. Thus, in the face of
1.55 + * concurrent modification, the iterator fails quickly and cleanly, rather
1.56 + * than risking arbitrary, non-deterministic behavior at an undetermined
1.57 + * time in the future. The {@link Enumeration Enumerations} returned by
1.58 + * the {@link #elements() elements} method are <em>not</em> fail-fast.
1.59 + *
1.60 + * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
1.61 + * as it is, generally speaking, impossible to make any hard guarantees in the
1.62 + * presence of unsynchronized concurrent modification. Fail-fast iterators
1.63 + * throw {@code ConcurrentModificationException} on a best-effort basis.
1.64 + * Therefore, it would be wrong to write a program that depended on this
1.65 + * exception for its correctness: <i>the fail-fast behavior of iterators
1.66 + * should be used only to detect bugs.</i>
1.67 + *
1.68 + * <p>As of the Java 2 platform v1.2, this class was retrofitted to
1.69 + * implement the {@link List} interface, making it a member of the
1.70 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
1.71 + * Java Collections Framework</a>. Unlike the new collection
1.72 + * implementations, {@code Vector} is synchronized. If a thread-safe
1.73 + * implementation is not needed, it is recommended to use {@link
1.74 + * ArrayList} in place of {@code Vector}.
1.75 + *
1.76 + * @author Lee Boynton
1.77 + * @author Jonathan Payne
1.78 + * @see Collection
1.79 + * @see LinkedList
1.80 + * @since JDK1.0
1.81 + */
1.82 +public class Vector<E>
1.83 + extends AbstractList<E>
1.84 + implements List<E>, RandomAccess, Cloneable, java.io.Serializable
1.85 +{
1.86 + /**
1.87 + * The array buffer into which the components of the vector are
1.88 + * stored. The capacity of the vector is the length of this array buffer,
1.89 + * and is at least large enough to contain all the vector's elements.
1.90 + *
1.91 + * <p>Any array elements following the last element in the Vector are null.
1.92 + *
1.93 + * @serial
1.94 + */
1.95 + protected Object[] elementData;
1.96 +
1.97 + /**
1.98 + * The number of valid components in this {@code Vector} object.
1.99 + * Components {@code elementData[0]} through
1.100 + * {@code elementData[elementCount-1]} are the actual items.
1.101 + *
1.102 + * @serial
1.103 + */
1.104 + protected int elementCount;
1.105 +
1.106 + /**
1.107 + * The amount by which the capacity of the vector is automatically
1.108 + * incremented when its size becomes greater than its capacity. If
1.109 + * the capacity increment is less than or equal to zero, the capacity
1.110 + * of the vector is doubled each time it needs to grow.
1.111 + *
1.112 + * @serial
1.113 + */
1.114 + protected int capacityIncrement;
1.115 +
1.116 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
1.117 + private static final long serialVersionUID = -2767605614048989439L;
1.118 +
1.119 + /**
1.120 + * Constructs an empty vector with the specified initial capacity and
1.121 + * capacity increment.
1.122 + *
1.123 + * @param initialCapacity the initial capacity of the vector
1.124 + * @param capacityIncrement the amount by which the capacity is
1.125 + * increased when the vector overflows
1.126 + * @throws IllegalArgumentException if the specified initial capacity
1.127 + * is negative
1.128 + */
1.129 + public Vector(int initialCapacity, int capacityIncrement) {
1.130 + super();
1.131 + if (initialCapacity < 0)
1.132 + throw new IllegalArgumentException("Illegal Capacity: "+
1.133 + initialCapacity);
1.134 + this.elementData = new Object[initialCapacity];
1.135 + this.capacityIncrement = capacityIncrement;
1.136 + }
1.137 +
1.138 + /**
1.139 + * Constructs an empty vector with the specified initial capacity and
1.140 + * with its capacity increment equal to zero.
1.141 + *
1.142 + * @param initialCapacity the initial capacity of the vector
1.143 + * @throws IllegalArgumentException if the specified initial capacity
1.144 + * is negative
1.145 + */
1.146 + public Vector(int initialCapacity) {
1.147 + this(initialCapacity, 0);
1.148 + }
1.149 +
1.150 + /**
1.151 + * Constructs an empty vector so that its internal data array
1.152 + * has size {@code 10} and its standard capacity increment is
1.153 + * zero.
1.154 + */
1.155 + public Vector() {
1.156 + this(10);
1.157 + }
1.158 +
1.159 + /**
1.160 + * Constructs a vector containing the elements of the specified
1.161 + * collection, in the order they are returned by the collection's
1.162 + * iterator.
1.163 + *
1.164 + * @param c the collection whose elements are to be placed into this
1.165 + * vector
1.166 + * @throws NullPointerException if the specified collection is null
1.167 + * @since 1.2
1.168 + */
1.169 + public Vector(Collection<? extends E> c) {
1.170 + elementData = c.toArray();
1.171 + elementCount = elementData.length;
1.172 + // c.toArray might (incorrectly) not return Object[] (see 6260652)
1.173 + if (elementData.getClass() != Object[].class)
1.174 + elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
1.175 + }
1.176 +
1.177 + /**
1.178 + * Copies the components of this vector into the specified array.
1.179 + * The item at index {@code k} in this vector is copied into
1.180 + * component {@code k} of {@code anArray}.
1.181 + *
1.182 + * @param anArray the array into which the components get copied
1.183 + * @throws NullPointerException if the given array is null
1.184 + * @throws IndexOutOfBoundsException if the specified array is not
1.185 + * large enough to hold all the components of this vector
1.186 + * @throws ArrayStoreException if a component of this vector is not of
1.187 + * a runtime type that can be stored in the specified array
1.188 + * @see #toArray(Object[])
1.189 + */
1.190 + public synchronized void copyInto(Object[] anArray) {
1.191 + System.arraycopy(elementData, 0, anArray, 0, elementCount);
1.192 + }
1.193 +
1.194 + /**
1.195 + * Trims the capacity of this vector to be the vector's current
1.196 + * size. If the capacity of this vector is larger than its current
1.197 + * size, then the capacity is changed to equal the size by replacing
1.198 + * its internal data array, kept in the field {@code elementData},
1.199 + * with a smaller one. An application can use this operation to
1.200 + * minimize the storage of a vector.
1.201 + */
1.202 + public synchronized void trimToSize() {
1.203 + modCount++;
1.204 + int oldCapacity = elementData.length;
1.205 + if (elementCount < oldCapacity) {
1.206 + elementData = Arrays.copyOf(elementData, elementCount);
1.207 + }
1.208 + }
1.209 +
1.210 + /**
1.211 + * Increases the capacity of this vector, if necessary, to ensure
1.212 + * that it can hold at least the number of components specified by
1.213 + * the minimum capacity argument.
1.214 + *
1.215 + * <p>If the current capacity of this vector is less than
1.216 + * {@code minCapacity}, then its capacity is increased by replacing its
1.217 + * internal data array, kept in the field {@code elementData}, with a
1.218 + * larger one. The size of the new data array will be the old size plus
1.219 + * {@code capacityIncrement}, unless the value of
1.220 + * {@code capacityIncrement} is less than or equal to zero, in which case
1.221 + * the new capacity will be twice the old capacity; but if this new size
1.222 + * is still smaller than {@code minCapacity}, then the new capacity will
1.223 + * be {@code minCapacity}.
1.224 + *
1.225 + * @param minCapacity the desired minimum capacity
1.226 + */
1.227 + public synchronized void ensureCapacity(int minCapacity) {
1.228 + if (minCapacity > 0) {
1.229 + modCount++;
1.230 + ensureCapacityHelper(minCapacity);
1.231 + }
1.232 + }
1.233 +
1.234 + /**
1.235 + * This implements the unsynchronized semantics of ensureCapacity.
1.236 + * Synchronized methods in this class can internally call this
1.237 + * method for ensuring capacity without incurring the cost of an
1.238 + * extra synchronization.
1.239 + *
1.240 + * @see #ensureCapacity(int)
1.241 + */
1.242 + private void ensureCapacityHelper(int minCapacity) {
1.243 + // overflow-conscious code
1.244 + if (minCapacity - elementData.length > 0)
1.245 + grow(minCapacity);
1.246 + }
1.247 +
1.248 + /**
1.249 + * The maximum size of array to allocate.
1.250 + * Some VMs reserve some header words in an array.
1.251 + * Attempts to allocate larger arrays may result in
1.252 + * OutOfMemoryError: Requested array size exceeds VM limit
1.253 + */
1.254 + private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
1.255 +
1.256 + private void grow(int minCapacity) {
1.257 + // overflow-conscious code
1.258 + int oldCapacity = elementData.length;
1.259 + int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
1.260 + capacityIncrement : oldCapacity);
1.261 + if (newCapacity - minCapacity < 0)
1.262 + newCapacity = minCapacity;
1.263 + if (newCapacity - MAX_ARRAY_SIZE > 0)
1.264 + newCapacity = hugeCapacity(minCapacity);
1.265 + elementData = Arrays.copyOf(elementData, newCapacity);
1.266 + }
1.267 +
1.268 + private static int hugeCapacity(int minCapacity) {
1.269 + if (minCapacity < 0) // overflow
1.270 + throw new OutOfMemoryError();
1.271 + return (minCapacity > MAX_ARRAY_SIZE) ?
1.272 + Integer.MAX_VALUE :
1.273 + MAX_ARRAY_SIZE;
1.274 + }
1.275 +
1.276 + /**
1.277 + * Sets the size of this vector. If the new size is greater than the
1.278 + * current size, new {@code null} items are added to the end of
1.279 + * the vector. If the new size is less than the current size, all
1.280 + * components at index {@code newSize} and greater are discarded.
1.281 + *
1.282 + * @param newSize the new size of this vector
1.283 + * @throws ArrayIndexOutOfBoundsException if the new size is negative
1.284 + */
1.285 + public synchronized void setSize(int newSize) {
1.286 + modCount++;
1.287 + if (newSize > elementCount) {
1.288 + ensureCapacityHelper(newSize);
1.289 + } else {
1.290 + for (int i = newSize ; i < elementCount ; i++) {
1.291 + elementData[i] = null;
1.292 + }
1.293 + }
1.294 + elementCount = newSize;
1.295 + }
1.296 +
1.297 + /**
1.298 + * Returns the current capacity of this vector.
1.299 + *
1.300 + * @return the current capacity (the length of its internal
1.301 + * data array, kept in the field {@code elementData}
1.302 + * of this vector)
1.303 + */
1.304 + public synchronized int capacity() {
1.305 + return elementData.length;
1.306 + }
1.307 +
1.308 + /**
1.309 + * Returns the number of components in this vector.
1.310 + *
1.311 + * @return the number of components in this vector
1.312 + */
1.313 + public synchronized int size() {
1.314 + return elementCount;
1.315 + }
1.316 +
1.317 + /**
1.318 + * Tests if this vector has no components.
1.319 + *
1.320 + * @return {@code true} if and only if this vector has
1.321 + * no components, that is, its size is zero;
1.322 + * {@code false} otherwise.
1.323 + */
1.324 + public synchronized boolean isEmpty() {
1.325 + return elementCount == 0;
1.326 + }
1.327 +
1.328 + /**
1.329 + * Returns an enumeration of the components of this vector. The
1.330 + * returned {@code Enumeration} object will generate all items in
1.331 + * this vector. The first item generated is the item at index {@code 0},
1.332 + * then the item at index {@code 1}, and so on.
1.333 + *
1.334 + * @return an enumeration of the components of this vector
1.335 + * @see Iterator
1.336 + */
1.337 + public Enumeration<E> elements() {
1.338 + return new Enumeration<E>() {
1.339 + int count = 0;
1.340 +
1.341 + public boolean hasMoreElements() {
1.342 + return count < elementCount;
1.343 + }
1.344 +
1.345 + public E nextElement() {
1.346 + synchronized (Vector.this) {
1.347 + if (count < elementCount) {
1.348 + return elementData(count++);
1.349 + }
1.350 + }
1.351 + throw new NoSuchElementException("Vector Enumeration");
1.352 + }
1.353 + };
1.354 + }
1.355 +
1.356 + /**
1.357 + * Returns {@code true} if this vector contains the specified element.
1.358 + * More formally, returns {@code true} if and only if this vector
1.359 + * contains at least one element {@code e} such that
1.360 + * <tt>(o==null ? e==null : o.equals(e))</tt>.
1.361 + *
1.362 + * @param o element whose presence in this vector is to be tested
1.363 + * @return {@code true} if this vector contains the specified element
1.364 + */
1.365 + public boolean contains(Object o) {
1.366 + return indexOf(o, 0) >= 0;
1.367 + }
1.368 +
1.369 + /**
1.370 + * Returns the index of the first occurrence of the specified element
1.371 + * in this vector, or -1 if this vector does not contain the element.
1.372 + * More formally, returns the lowest index {@code i} such that
1.373 + * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>,
1.374 + * or -1 if there is no such index.
1.375 + *
1.376 + * @param o element to search for
1.377 + * @return the index of the first occurrence of the specified element in
1.378 + * this vector, or -1 if this vector does not contain the element
1.379 + */
1.380 + public int indexOf(Object o) {
1.381 + return indexOf(o, 0);
1.382 + }
1.383 +
1.384 + /**
1.385 + * Returns the index of the first occurrence of the specified element in
1.386 + * this vector, searching forwards from {@code index}, or returns -1 if
1.387 + * the element is not found.
1.388 + * More formally, returns the lowest index {@code i} such that
1.389 + * <tt>(i >= index && (o==null ? get(i)==null : o.equals(get(i))))</tt>,
1.390 + * or -1 if there is no such index.
1.391 + *
1.392 + * @param o element to search for
1.393 + * @param index index to start searching from
1.394 + * @return the index of the first occurrence of the element in
1.395 + * this vector at position {@code index} or later in the vector;
1.396 + * {@code -1} if the element is not found.
1.397 + * @throws IndexOutOfBoundsException if the specified index is negative
1.398 + * @see Object#equals(Object)
1.399 + */
1.400 + public synchronized int indexOf(Object o, int index) {
1.401 + if (o == null) {
1.402 + for (int i = index ; i < elementCount ; i++)
1.403 + if (elementData[i]==null)
1.404 + return i;
1.405 + } else {
1.406 + for (int i = index ; i < elementCount ; i++)
1.407 + if (o.equals(elementData[i]))
1.408 + return i;
1.409 + }
1.410 + return -1;
1.411 + }
1.412 +
1.413 + /**
1.414 + * Returns the index of the last occurrence of the specified element
1.415 + * in this vector, or -1 if this vector does not contain the element.
1.416 + * More formally, returns the highest index {@code i} such that
1.417 + * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>,
1.418 + * or -1 if there is no such index.
1.419 + *
1.420 + * @param o element to search for
1.421 + * @return the index of the last occurrence of the specified element in
1.422 + * this vector, or -1 if this vector does not contain the element
1.423 + */
1.424 + public synchronized int lastIndexOf(Object o) {
1.425 + return lastIndexOf(o, elementCount-1);
1.426 + }
1.427 +
1.428 + /**
1.429 + * Returns the index of the last occurrence of the specified element in
1.430 + * this vector, searching backwards from {@code index}, or returns -1 if
1.431 + * the element is not found.
1.432 + * More formally, returns the highest index {@code i} such that
1.433 + * <tt>(i <= index && (o==null ? get(i)==null : o.equals(get(i))))</tt>,
1.434 + * or -1 if there is no such index.
1.435 + *
1.436 + * @param o element to search for
1.437 + * @param index index to start searching backwards from
1.438 + * @return the index of the last occurrence of the element at position
1.439 + * less than or equal to {@code index} in this vector;
1.440 + * -1 if the element is not found.
1.441 + * @throws IndexOutOfBoundsException if the specified index is greater
1.442 + * than or equal to the current size of this vector
1.443 + */
1.444 + public synchronized int lastIndexOf(Object o, int index) {
1.445 + if (index >= elementCount)
1.446 + throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
1.447 +
1.448 + if (o == null) {
1.449 + for (int i = index; i >= 0; i--)
1.450 + if (elementData[i]==null)
1.451 + return i;
1.452 + } else {
1.453 + for (int i = index; i >= 0; i--)
1.454 + if (o.equals(elementData[i]))
1.455 + return i;
1.456 + }
1.457 + return -1;
1.458 + }
1.459 +
1.460 + /**
1.461 + * Returns the component at the specified index.
1.462 + *
1.463 + * <p>This method is identical in functionality to the {@link #get(int)}
1.464 + * method (which is part of the {@link List} interface).
1.465 + *
1.466 + * @param index an index into this vector
1.467 + * @return the component at the specified index
1.468 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.469 + * ({@code index < 0 || index >= size()})
1.470 + */
1.471 + public synchronized E elementAt(int index) {
1.472 + if (index >= elementCount) {
1.473 + throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
1.474 + }
1.475 +
1.476 + return elementData(index);
1.477 + }
1.478 +
1.479 + /**
1.480 + * Returns the first component (the item at index {@code 0}) of
1.481 + * this vector.
1.482 + *
1.483 + * @return the first component of this vector
1.484 + * @throws NoSuchElementException if this vector has no components
1.485 + */
1.486 + public synchronized E firstElement() {
1.487 + if (elementCount == 0) {
1.488 + throw new NoSuchElementException();
1.489 + }
1.490 + return elementData(0);
1.491 + }
1.492 +
1.493 + /**
1.494 + * Returns the last component of the vector.
1.495 + *
1.496 + * @return the last component of the vector, i.e., the component at index
1.497 + * <code>size() - 1</code>.
1.498 + * @throws NoSuchElementException if this vector is empty
1.499 + */
1.500 + public synchronized E lastElement() {
1.501 + if (elementCount == 0) {
1.502 + throw new NoSuchElementException();
1.503 + }
1.504 + return elementData(elementCount - 1);
1.505 + }
1.506 +
1.507 + /**
1.508 + * Sets the component at the specified {@code index} of this
1.509 + * vector to be the specified object. The previous component at that
1.510 + * position is discarded.
1.511 + *
1.512 + * <p>The index must be a value greater than or equal to {@code 0}
1.513 + * and less than the current size of the vector.
1.514 + *
1.515 + * <p>This method is identical in functionality to the
1.516 + * {@link #set(int, Object) set(int, E)}
1.517 + * method (which is part of the {@link List} interface). Note that the
1.518 + * {@code set} method reverses the order of the parameters, to more closely
1.519 + * match array usage. Note also that the {@code set} method returns the
1.520 + * old value that was stored at the specified position.
1.521 + *
1.522 + * @param obj what the component is to be set to
1.523 + * @param index the specified index
1.524 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.525 + * ({@code index < 0 || index >= size()})
1.526 + */
1.527 + public synchronized void setElementAt(E obj, int index) {
1.528 + if (index >= elementCount) {
1.529 + throw new ArrayIndexOutOfBoundsException(index + " >= " +
1.530 + elementCount);
1.531 + }
1.532 + elementData[index] = obj;
1.533 + }
1.534 +
1.535 + /**
1.536 + * Deletes the component at the specified index. Each component in
1.537 + * this vector with an index greater or equal to the specified
1.538 + * {@code index} is shifted downward to have an index one
1.539 + * smaller than the value it had previously. The size of this vector
1.540 + * is decreased by {@code 1}.
1.541 + *
1.542 + * <p>The index must be a value greater than or equal to {@code 0}
1.543 + * and less than the current size of the vector.
1.544 + *
1.545 + * <p>This method is identical in functionality to the {@link #remove(int)}
1.546 + * method (which is part of the {@link List} interface). Note that the
1.547 + * {@code remove} method returns the old value that was stored at the
1.548 + * specified position.
1.549 + *
1.550 + * @param index the index of the object to remove
1.551 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.552 + * ({@code index < 0 || index >= size()})
1.553 + */
1.554 + public synchronized void removeElementAt(int index) {
1.555 + modCount++;
1.556 + if (index >= elementCount) {
1.557 + throw new ArrayIndexOutOfBoundsException(index + " >= " +
1.558 + elementCount);
1.559 + }
1.560 + else if (index < 0) {
1.561 + throw new ArrayIndexOutOfBoundsException(index);
1.562 + }
1.563 + int j = elementCount - index - 1;
1.564 + if (j > 0) {
1.565 + System.arraycopy(elementData, index + 1, elementData, index, j);
1.566 + }
1.567 + elementCount--;
1.568 + elementData[elementCount] = null; /* to let gc do its work */
1.569 + }
1.570 +
1.571 + /**
1.572 + * Inserts the specified object as a component in this vector at the
1.573 + * specified {@code index}. Each component in this vector with
1.574 + * an index greater or equal to the specified {@code index} is
1.575 + * shifted upward to have an index one greater than the value it had
1.576 + * previously.
1.577 + *
1.578 + * <p>The index must be a value greater than or equal to {@code 0}
1.579 + * and less than or equal to the current size of the vector. (If the
1.580 + * index is equal to the current size of the vector, the new element
1.581 + * is appended to the Vector.)
1.582 + *
1.583 + * <p>This method is identical in functionality to the
1.584 + * {@link #add(int, Object) add(int, E)}
1.585 + * method (which is part of the {@link List} interface). Note that the
1.586 + * {@code add} method reverses the order of the parameters, to more closely
1.587 + * match array usage.
1.588 + *
1.589 + * @param obj the component to insert
1.590 + * @param index where to insert the new component
1.591 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.592 + * ({@code index < 0 || index > size()})
1.593 + */
1.594 + public synchronized void insertElementAt(E obj, int index) {
1.595 + modCount++;
1.596 + if (index > elementCount) {
1.597 + throw new ArrayIndexOutOfBoundsException(index
1.598 + + " > " + elementCount);
1.599 + }
1.600 + ensureCapacityHelper(elementCount + 1);
1.601 + System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
1.602 + elementData[index] = obj;
1.603 + elementCount++;
1.604 + }
1.605 +
1.606 + /**
1.607 + * Adds the specified component to the end of this vector,
1.608 + * increasing its size by one. The capacity of this vector is
1.609 + * increased if its size becomes greater than its capacity.
1.610 + *
1.611 + * <p>This method is identical in functionality to the
1.612 + * {@link #add(Object) add(E)}
1.613 + * method (which is part of the {@link List} interface).
1.614 + *
1.615 + * @param obj the component to be added
1.616 + */
1.617 + public synchronized void addElement(E obj) {
1.618 + modCount++;
1.619 + ensureCapacityHelper(elementCount + 1);
1.620 + elementData[elementCount++] = obj;
1.621 + }
1.622 +
1.623 + /**
1.624 + * Removes the first (lowest-indexed) occurrence of the argument
1.625 + * from this vector. If the object is found in this vector, each
1.626 + * component in the vector with an index greater or equal to the
1.627 + * object's index is shifted downward to have an index one smaller
1.628 + * than the value it had previously.
1.629 + *
1.630 + * <p>This method is identical in functionality to the
1.631 + * {@link #remove(Object)} method (which is part of the
1.632 + * {@link List} interface).
1.633 + *
1.634 + * @param obj the component to be removed
1.635 + * @return {@code true} if the argument was a component of this
1.636 + * vector; {@code false} otherwise.
1.637 + */
1.638 + public synchronized boolean removeElement(Object obj) {
1.639 + modCount++;
1.640 + int i = indexOf(obj);
1.641 + if (i >= 0) {
1.642 + removeElementAt(i);
1.643 + return true;
1.644 + }
1.645 + return false;
1.646 + }
1.647 +
1.648 + /**
1.649 + * Removes all components from this vector and sets its size to zero.
1.650 + *
1.651 + * <p>This method is identical in functionality to the {@link #clear}
1.652 + * method (which is part of the {@link List} interface).
1.653 + */
1.654 + public synchronized void removeAllElements() {
1.655 + modCount++;
1.656 + // Let gc do its work
1.657 + for (int i = 0; i < elementCount; i++)
1.658 + elementData[i] = null;
1.659 +
1.660 + elementCount = 0;
1.661 + }
1.662 +
1.663 + /**
1.664 + * Returns a clone of this vector. The copy will contain a
1.665 + * reference to a clone of the internal data array, not a reference
1.666 + * to the original internal data array of this {@code Vector} object.
1.667 + *
1.668 + * @return a clone of this vector
1.669 + */
1.670 + public synchronized Object clone() {
1.671 + try {
1.672 + @SuppressWarnings("unchecked")
1.673 + Vector<E> v = (Vector<E>) super.clone();
1.674 + v.elementData = Arrays.copyOf(elementData, elementCount);
1.675 + v.modCount = 0;
1.676 + return v;
1.677 + } catch (CloneNotSupportedException e) {
1.678 + // this shouldn't happen, since we are Cloneable
1.679 + throw new InternalError();
1.680 + }
1.681 + }
1.682 +
1.683 + /**
1.684 + * Returns an array containing all of the elements in this Vector
1.685 + * in the correct order.
1.686 + *
1.687 + * @since 1.2
1.688 + */
1.689 + public synchronized Object[] toArray() {
1.690 + return Arrays.copyOf(elementData, elementCount);
1.691 + }
1.692 +
1.693 + /**
1.694 + * Returns an array containing all of the elements in this Vector in the
1.695 + * correct order; the runtime type of the returned array is that of the
1.696 + * specified array. If the Vector fits in the specified array, it is
1.697 + * returned therein. Otherwise, a new array is allocated with the runtime
1.698 + * type of the specified array and the size of this Vector.
1.699 + *
1.700 + * <p>If the Vector fits in the specified array with room to spare
1.701 + * (i.e., the array has more elements than the Vector),
1.702 + * the element in the array immediately following the end of the
1.703 + * Vector is set to null. (This is useful in determining the length
1.704 + * of the Vector <em>only</em> if the caller knows that the Vector
1.705 + * does not contain any null elements.)
1.706 + *
1.707 + * @param a the array into which the elements of the Vector are to
1.708 + * be stored, if it is big enough; otherwise, a new array of the
1.709 + * same runtime type is allocated for this purpose.
1.710 + * @return an array containing the elements of the Vector
1.711 + * @throws ArrayStoreException if the runtime type of a is not a supertype
1.712 + * of the runtime type of every element in this Vector
1.713 + * @throws NullPointerException if the given array is null
1.714 + * @since 1.2
1.715 + */
1.716 + @SuppressWarnings("unchecked")
1.717 + public synchronized <T> T[] toArray(T[] a) {
1.718 + if (a.length < elementCount)
1.719 + return (T[]) Arrays.copyOf(elementData, elementCount, a.getClass());
1.720 +
1.721 + System.arraycopy(elementData, 0, a, 0, elementCount);
1.722 +
1.723 + if (a.length > elementCount)
1.724 + a[elementCount] = null;
1.725 +
1.726 + return a;
1.727 + }
1.728 +
1.729 + // Positional Access Operations
1.730 +
1.731 + @SuppressWarnings("unchecked")
1.732 + E elementData(int index) {
1.733 + return (E) elementData[index];
1.734 + }
1.735 +
1.736 + /**
1.737 + * Returns the element at the specified position in this Vector.
1.738 + *
1.739 + * @param index index of the element to return
1.740 + * @return object at the specified index
1.741 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.742 + * ({@code index < 0 || index >= size()})
1.743 + * @since 1.2
1.744 + */
1.745 + public synchronized E get(int index) {
1.746 + if (index >= elementCount)
1.747 + throw new ArrayIndexOutOfBoundsException(index);
1.748 +
1.749 + return elementData(index);
1.750 + }
1.751 +
1.752 + /**
1.753 + * Replaces the element at the specified position in this Vector with the
1.754 + * specified element.
1.755 + *
1.756 + * @param index index of the element to replace
1.757 + * @param element element to be stored at the specified position
1.758 + * @return the element previously at the specified position
1.759 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.760 + * ({@code index < 0 || index >= size()})
1.761 + * @since 1.2
1.762 + */
1.763 + public synchronized E set(int index, E element) {
1.764 + if (index >= elementCount)
1.765 + throw new ArrayIndexOutOfBoundsException(index);
1.766 +
1.767 + E oldValue = elementData(index);
1.768 + elementData[index] = element;
1.769 + return oldValue;
1.770 + }
1.771 +
1.772 + /**
1.773 + * Appends the specified element to the end of this Vector.
1.774 + *
1.775 + * @param e element to be appended to this Vector
1.776 + * @return {@code true} (as specified by {@link Collection#add})
1.777 + * @since 1.2
1.778 + */
1.779 + public synchronized boolean add(E e) {
1.780 + modCount++;
1.781 + ensureCapacityHelper(elementCount + 1);
1.782 + elementData[elementCount++] = e;
1.783 + return true;
1.784 + }
1.785 +
1.786 + /**
1.787 + * Removes the first occurrence of the specified element in this Vector
1.788 + * If the Vector does not contain the element, it is unchanged. More
1.789 + * formally, removes the element with the lowest index i such that
1.790 + * {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
1.791 + * an element exists).
1.792 + *
1.793 + * @param o element to be removed from this Vector, if present
1.794 + * @return true if the Vector contained the specified element
1.795 + * @since 1.2
1.796 + */
1.797 + public boolean remove(Object o) {
1.798 + return removeElement(o);
1.799 + }
1.800 +
1.801 + /**
1.802 + * Inserts the specified element at the specified position in this Vector.
1.803 + * Shifts the element currently at that position (if any) and any
1.804 + * subsequent elements to the right (adds one to their indices).
1.805 + *
1.806 + * @param index index at which the specified element is to be inserted
1.807 + * @param element element to be inserted
1.808 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.809 + * ({@code index < 0 || index > size()})
1.810 + * @since 1.2
1.811 + */
1.812 + public void add(int index, E element) {
1.813 + insertElementAt(element, index);
1.814 + }
1.815 +
1.816 + /**
1.817 + * Removes the element at the specified position in this Vector.
1.818 + * Shifts any subsequent elements to the left (subtracts one from their
1.819 + * indices). Returns the element that was removed from the Vector.
1.820 + *
1.821 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.822 + * ({@code index < 0 || index >= size()})
1.823 + * @param index the index of the element to be removed
1.824 + * @return element that was removed
1.825 + * @since 1.2
1.826 + */
1.827 + public synchronized E remove(int index) {
1.828 + modCount++;
1.829 + if (index >= elementCount)
1.830 + throw new ArrayIndexOutOfBoundsException(index);
1.831 + E oldValue = elementData(index);
1.832 +
1.833 + int numMoved = elementCount - index - 1;
1.834 + if (numMoved > 0)
1.835 + System.arraycopy(elementData, index+1, elementData, index,
1.836 + numMoved);
1.837 + elementData[--elementCount] = null; // Let gc do its work
1.838 +
1.839 + return oldValue;
1.840 + }
1.841 +
1.842 + /**
1.843 + * Removes all of the elements from this Vector. The Vector will
1.844 + * be empty after this call returns (unless it throws an exception).
1.845 + *
1.846 + * @since 1.2
1.847 + */
1.848 + public void clear() {
1.849 + removeAllElements();
1.850 + }
1.851 +
1.852 + // Bulk Operations
1.853 +
1.854 + /**
1.855 + * Returns true if this Vector contains all of the elements in the
1.856 + * specified Collection.
1.857 + *
1.858 + * @param c a collection whose elements will be tested for containment
1.859 + * in this Vector
1.860 + * @return true if this Vector contains all of the elements in the
1.861 + * specified collection
1.862 + * @throws NullPointerException if the specified collection is null
1.863 + */
1.864 + public synchronized boolean containsAll(Collection<?> c) {
1.865 + return super.containsAll(c);
1.866 + }
1.867 +
1.868 + /**
1.869 + * Appends all of the elements in the specified Collection to the end of
1.870 + * this Vector, in the order that they are returned by the specified
1.871 + * Collection's Iterator. The behavior of this operation is undefined if
1.872 + * the specified Collection is modified while the operation is in progress.
1.873 + * (This implies that the behavior of this call is undefined if the
1.874 + * specified Collection is this Vector, and this Vector is nonempty.)
1.875 + *
1.876 + * @param c elements to be inserted into this Vector
1.877 + * @return {@code true} if this Vector changed as a result of the call
1.878 + * @throws NullPointerException if the specified collection is null
1.879 + * @since 1.2
1.880 + */
1.881 + public synchronized boolean addAll(Collection<? extends E> c) {
1.882 + modCount++;
1.883 + Object[] a = c.toArray();
1.884 + int numNew = a.length;
1.885 + ensureCapacityHelper(elementCount + numNew);
1.886 + System.arraycopy(a, 0, elementData, elementCount, numNew);
1.887 + elementCount += numNew;
1.888 + return numNew != 0;
1.889 + }
1.890 +
1.891 + /**
1.892 + * Removes from this Vector all of its elements that are contained in the
1.893 + * specified Collection.
1.894 + *
1.895 + * @param c a collection of elements to be removed from the Vector
1.896 + * @return true if this Vector changed as a result of the call
1.897 + * @throws ClassCastException if the types of one or more elements
1.898 + * in this vector are incompatible with the specified
1.899 + * collection
1.900 + * (<a href="Collection.html#optional-restrictions">optional</a>)
1.901 + * @throws NullPointerException if this vector contains one or more null
1.902 + * elements and the specified collection does not support null
1.903 + * elements
1.904 + * (<a href="Collection.html#optional-restrictions">optional</a>),
1.905 + * or if the specified collection is null
1.906 + * @since 1.2
1.907 + */
1.908 + public synchronized boolean removeAll(Collection<?> c) {
1.909 + return super.removeAll(c);
1.910 + }
1.911 +
1.912 + /**
1.913 + * Retains only the elements in this Vector that are contained in the
1.914 + * specified Collection. In other words, removes from this Vector all
1.915 + * of its elements that are not contained in the specified Collection.
1.916 + *
1.917 + * @param c a collection of elements to be retained in this Vector
1.918 + * (all other elements are removed)
1.919 + * @return true if this Vector changed as a result of the call
1.920 + * @throws ClassCastException if the types of one or more elements
1.921 + * in this vector are incompatible with the specified
1.922 + * collection
1.923 + * (<a href="Collection.html#optional-restrictions">optional</a>)
1.924 + * @throws NullPointerException if this vector contains one or more null
1.925 + * elements and the specified collection does not support null
1.926 + * elements
1.927 + * (<a href="Collection.html#optional-restrictions">optional</a>),
1.928 + * or if the specified collection is null
1.929 + * @since 1.2
1.930 + */
1.931 + public synchronized boolean retainAll(Collection<?> c) {
1.932 + return super.retainAll(c);
1.933 + }
1.934 +
1.935 + /**
1.936 + * Inserts all of the elements in the specified Collection into this
1.937 + * Vector at the specified position. Shifts the element currently at
1.938 + * that position (if any) and any subsequent elements to the right
1.939 + * (increases their indices). The new elements will appear in the Vector
1.940 + * in the order that they are returned by the specified Collection's
1.941 + * iterator.
1.942 + *
1.943 + * @param index index at which to insert the first element from the
1.944 + * specified collection
1.945 + * @param c elements to be inserted into this Vector
1.946 + * @return {@code true} if this Vector changed as a result of the call
1.947 + * @throws ArrayIndexOutOfBoundsException if the index is out of range
1.948 + * ({@code index < 0 || index > size()})
1.949 + * @throws NullPointerException if the specified collection is null
1.950 + * @since 1.2
1.951 + */
1.952 + public synchronized boolean addAll(int index, Collection<? extends E> c) {
1.953 + modCount++;
1.954 + if (index < 0 || index > elementCount)
1.955 + throw new ArrayIndexOutOfBoundsException(index);
1.956 +
1.957 + Object[] a = c.toArray();
1.958 + int numNew = a.length;
1.959 + ensureCapacityHelper(elementCount + numNew);
1.960 +
1.961 + int numMoved = elementCount - index;
1.962 + if (numMoved > 0)
1.963 + System.arraycopy(elementData, index, elementData, index + numNew,
1.964 + numMoved);
1.965 +
1.966 + System.arraycopy(a, 0, elementData, index, numNew);
1.967 + elementCount += numNew;
1.968 + return numNew != 0;
1.969 + }
1.970 +
1.971 + /**
1.972 + * Compares the specified Object with this Vector for equality. Returns
1.973 + * true if and only if the specified Object is also a List, both Lists
1.974 + * have the same size, and all corresponding pairs of elements in the two
1.975 + * Lists are <em>equal</em>. (Two elements {@code e1} and
1.976 + * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
1.977 + * e1.equals(e2))}.) In other words, two Lists are defined to be
1.978 + * equal if they contain the same elements in the same order.
1.979 + *
1.980 + * @param o the Object to be compared for equality with this Vector
1.981 + * @return true if the specified Object is equal to this Vector
1.982 + */
1.983 + public synchronized boolean equals(Object o) {
1.984 + return super.equals(o);
1.985 + }
1.986 +
1.987 + /**
1.988 + * Returns the hash code value for this Vector.
1.989 + */
1.990 + public synchronized int hashCode() {
1.991 + return super.hashCode();
1.992 + }
1.993 +
1.994 + /**
1.995 + * Returns a string representation of this Vector, containing
1.996 + * the String representation of each element.
1.997 + */
1.998 + public synchronized String toString() {
1.999 + return super.toString();
1.1000 + }
1.1001 +
1.1002 + /**
1.1003 + * Returns a view of the portion of this List between fromIndex,
1.1004 + * inclusive, and toIndex, exclusive. (If fromIndex and toIndex are
1.1005 + * equal, the returned List is empty.) The returned List is backed by this
1.1006 + * List, so changes in the returned List are reflected in this List, and
1.1007 + * vice-versa. The returned List supports all of the optional List
1.1008 + * operations supported by this List.
1.1009 + *
1.1010 + * <p>This method eliminates the need for explicit range operations (of
1.1011 + * the sort that commonly exist for arrays). Any operation that expects
1.1012 + * a List can be used as a range operation by operating on a subList view
1.1013 + * instead of a whole List. For example, the following idiom
1.1014 + * removes a range of elements from a List:
1.1015 + * <pre>
1.1016 + * list.subList(from, to).clear();
1.1017 + * </pre>
1.1018 + * Similar idioms may be constructed for indexOf and lastIndexOf,
1.1019 + * and all of the algorithms in the Collections class can be applied to
1.1020 + * a subList.
1.1021 + *
1.1022 + * <p>The semantics of the List returned by this method become undefined if
1.1023 + * the backing list (i.e., this List) is <i>structurally modified</i> in
1.1024 + * any way other than via the returned List. (Structural modifications are
1.1025 + * those that change the size of the List, or otherwise perturb it in such
1.1026 + * a fashion that iterations in progress may yield incorrect results.)
1.1027 + *
1.1028 + * @param fromIndex low endpoint (inclusive) of the subList
1.1029 + * @param toIndex high endpoint (exclusive) of the subList
1.1030 + * @return a view of the specified range within this List
1.1031 + * @throws IndexOutOfBoundsException if an endpoint index value is out of range
1.1032 + * {@code (fromIndex < 0 || toIndex > size)}
1.1033 + * @throws IllegalArgumentException if the endpoint indices are out of order
1.1034 + * {@code (fromIndex > toIndex)}
1.1035 + */
1.1036 + public synchronized List<E> subList(int fromIndex, int toIndex) {
1.1037 + return Collections.synchronizedList(super.subList(fromIndex, toIndex),
1.1038 + this);
1.1039 + }
1.1040 +
1.1041 + /**
1.1042 + * Removes from this list all of the elements whose index is between
1.1043 + * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
1.1044 + * Shifts any succeeding elements to the left (reduces their index).
1.1045 + * This call shortens the list by {@code (toIndex - fromIndex)} elements.
1.1046 + * (If {@code toIndex==fromIndex}, this operation has no effect.)
1.1047 + */
1.1048 + protected synchronized void removeRange(int fromIndex, int toIndex) {
1.1049 + modCount++;
1.1050 + int numMoved = elementCount - toIndex;
1.1051 + System.arraycopy(elementData, toIndex, elementData, fromIndex,
1.1052 + numMoved);
1.1053 +
1.1054 + // Let gc do its work
1.1055 + int newElementCount = elementCount - (toIndex-fromIndex);
1.1056 + while (elementCount != newElementCount)
1.1057 + elementData[--elementCount] = null;
1.1058 + }
1.1059 +
1.1060 + /**
1.1061 + * Save the state of the {@code Vector} instance to a stream (that
1.1062 + * is, serialize it).
1.1063 + * This method performs synchronization to ensure the consistency
1.1064 + * of the serialized data.
1.1065 + */
1.1066 + private void writeObject(java.io.ObjectOutputStream s)
1.1067 + throws java.io.IOException {
1.1068 + final java.io.ObjectOutputStream.PutField fields = s.putFields();
1.1069 + final Object[] data;
1.1070 + synchronized (this) {
1.1071 + fields.put("capacityIncrement", capacityIncrement);
1.1072 + fields.put("elementCount", elementCount);
1.1073 + data = elementData.clone();
1.1074 + }
1.1075 + fields.put("elementData", data);
1.1076 + s.writeFields();
1.1077 + }
1.1078 +
1.1079 + /**
1.1080 + * Returns a list iterator over the elements in this list (in proper
1.1081 + * sequence), starting at the specified position in the list.
1.1082 + * The specified index indicates the first element that would be
1.1083 + * returned by an initial call to {@link ListIterator#next next}.
1.1084 + * An initial call to {@link ListIterator#previous previous} would
1.1085 + * return the element with the specified index minus one.
1.1086 + *
1.1087 + * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1.1088 + *
1.1089 + * @throws IndexOutOfBoundsException {@inheritDoc}
1.1090 + */
1.1091 + public synchronized ListIterator<E> listIterator(int index) {
1.1092 + if (index < 0 || index > elementCount)
1.1093 + throw new IndexOutOfBoundsException("Index: "+index);
1.1094 + return new ListItr(index);
1.1095 + }
1.1096 +
1.1097 + /**
1.1098 + * Returns a list iterator over the elements in this list (in proper
1.1099 + * sequence).
1.1100 + *
1.1101 + * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1.1102 + *
1.1103 + * @see #listIterator(int)
1.1104 + */
1.1105 + public synchronized ListIterator<E> listIterator() {
1.1106 + return new ListItr(0);
1.1107 + }
1.1108 +
1.1109 + /**
1.1110 + * Returns an iterator over the elements in this list in proper sequence.
1.1111 + *
1.1112 + * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1.1113 + *
1.1114 + * @return an iterator over the elements in this list in proper sequence
1.1115 + */
1.1116 + public synchronized Iterator<E> iterator() {
1.1117 + return new Itr();
1.1118 + }
1.1119 +
1.1120 + /**
1.1121 + * An optimized version of AbstractList.Itr
1.1122 + */
1.1123 + private class Itr implements Iterator<E> {
1.1124 + int cursor; // index of next element to return
1.1125 + int lastRet = -1; // index of last element returned; -1 if no such
1.1126 + int expectedModCount = modCount;
1.1127 +
1.1128 + public boolean hasNext() {
1.1129 + // Racy but within spec, since modifications are checked
1.1130 + // within or after synchronization in next/previous
1.1131 + return cursor != elementCount;
1.1132 + }
1.1133 +
1.1134 + public E next() {
1.1135 + synchronized (Vector.this) {
1.1136 + checkForComodification();
1.1137 + int i = cursor;
1.1138 + if (i >= elementCount)
1.1139 + throw new NoSuchElementException();
1.1140 + cursor = i + 1;
1.1141 + return elementData(lastRet = i);
1.1142 + }
1.1143 + }
1.1144 +
1.1145 + public void remove() {
1.1146 + if (lastRet == -1)
1.1147 + throw new IllegalStateException();
1.1148 + synchronized (Vector.this) {
1.1149 + checkForComodification();
1.1150 + Vector.this.remove(lastRet);
1.1151 + expectedModCount = modCount;
1.1152 + }
1.1153 + cursor = lastRet;
1.1154 + lastRet = -1;
1.1155 + }
1.1156 +
1.1157 + final void checkForComodification() {
1.1158 + if (modCount != expectedModCount)
1.1159 + throw new ConcurrentModificationException();
1.1160 + }
1.1161 + }
1.1162 +
1.1163 + /**
1.1164 + * An optimized version of AbstractList.ListItr
1.1165 + */
1.1166 + final class ListItr extends Itr implements ListIterator<E> {
1.1167 + ListItr(int index) {
1.1168 + super();
1.1169 + cursor = index;
1.1170 + }
1.1171 +
1.1172 + public boolean hasPrevious() {
1.1173 + return cursor != 0;
1.1174 + }
1.1175 +
1.1176 + public int nextIndex() {
1.1177 + return cursor;
1.1178 + }
1.1179 +
1.1180 + public int previousIndex() {
1.1181 + return cursor - 1;
1.1182 + }
1.1183 +
1.1184 + public E previous() {
1.1185 + synchronized (Vector.this) {
1.1186 + checkForComodification();
1.1187 + int i = cursor - 1;
1.1188 + if (i < 0)
1.1189 + throw new NoSuchElementException();
1.1190 + cursor = i;
1.1191 + return elementData(lastRet = i);
1.1192 + }
1.1193 + }
1.1194 +
1.1195 + public void set(E e) {
1.1196 + if (lastRet == -1)
1.1197 + throw new IllegalStateException();
1.1198 + synchronized (Vector.this) {
1.1199 + checkForComodification();
1.1200 + Vector.this.set(lastRet, e);
1.1201 + }
1.1202 + }
1.1203 +
1.1204 + public void add(E e) {
1.1205 + int i = cursor;
1.1206 + synchronized (Vector.this) {
1.1207 + checkForComodification();
1.1208 + Vector.this.add(i, e);
1.1209 + expectedModCount = modCount;
1.1210 + }
1.1211 + cursor = i + 1;
1.1212 + lastRet = -1;
1.1213 + }
1.1214 + }
1.1215 +}