3261N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class provides a skeletal implementation of the {@link List} 0N/A * interface to minimize the effort required to implement this interface 0N/A * backed by a "random access" data store (such as an array). For sequential 0N/A * access data (such as a linked list), {@link AbstractSequentialList} should 0N/A * be used in preference to this class. 0N/A * <p>To implement an unmodifiable list, the programmer needs only to extend 0N/A * this class and provide implementations for the {@link #get(int)} and 0N/A * {@link List#size() size()} methods. 0N/A * <p>To implement a modifiable list, the programmer must additionally 0N/A * override the {@link #set(int, Object) set(int, E)} method (which otherwise 0N/A * throws an {@code UnsupportedOperationException}). If the list is 0N/A * variable-size the programmer must additionally override the 0N/A * {@link #add(int, Object) add(int, E)} and {@link #remove(int)} methods. 0N/A * <p>The programmer should generally provide a void (no argument) and collection 0N/A * constructor, as per the recommendation in the {@link Collection} interface 0N/A * <p>Unlike the other abstract collection implementations, the programmer does 0N/A * <i>not</i> have to provide an iterator implementation; the iterator and 0N/A * list iterator are implemented by this class, on top of the "random access" 0N/A * {@link #get(int)}, 0N/A * {@link #set(int, Object) set(int, E)}, 0N/A * {@link #add(int, Object) add(int, E)} and 0N/A * {@link #remove(int)}. 0N/A * <p>The documentation for each non-abstract method in this class describes its 0N/A * implementation in detail. Each of these methods may be overridden if the 0N/A * collection being implemented admits a more efficient implementation. 0N/A * <p>This class is a member of the 0N/A * Java Collections Framework</a>. 0N/A * @author Josh Bloch 0N/A * @author Neal Gafter 0N/A * Sole constructor. (For invocation by subclass constructors, typically 0N/A * Appends the specified element to the end of this list (optional 0N/A * <p>Lists that support this operation may place limitations on what 0N/A * elements may be added to this list. In particular, some 0N/A * lists will refuse to add null elements, and others will impose 0N/A * restrictions on the type of elements that may be added. List 0N/A * classes should clearly specify in their documentation any restrictions 0N/A * on what elements may be added. 0N/A * <p>This implementation calls {@code add(size(), e)}. 0N/A * <p>Note that this implementation throws an 0N/A * {@code UnsupportedOperationException} unless 0N/A * {@link #add(int, Object) add(int, E)} is overridden. 0N/A * @param e element to be appended to this list 0N/A * @return {@code true} (as specified by {@link Collection#add}) 0N/A * @throws UnsupportedOperationException if the {@code add} operation 0N/A * is not supported by this list 0N/A * @throws ClassCastException if the class of the specified element 0N/A * prevents it from being added to this list 0N/A * @throws NullPointerException if the specified element is null and this 0N/A * list does not permit null elements 0N/A * @throws IllegalArgumentException if some property of this element 0N/A * prevents it from being added to this list 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * <p>This implementation always throws an 0N/A * {@code UnsupportedOperationException}. 0N/A * @throws UnsupportedOperationException {@inheritDoc} 0N/A * @throws ClassCastException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws IllegalArgumentException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * <p>This implementation always throws an 0N/A * {@code UnsupportedOperationException}. 0N/A * @throws UnsupportedOperationException {@inheritDoc} 0N/A * @throws ClassCastException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws IllegalArgumentException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * <p>This implementation always throws an 0N/A * {@code UnsupportedOperationException}. 0N/A * @throws UnsupportedOperationException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A // Search Operations 0N/A * <p>This implementation first gets a list iterator (with 0N/A * {@code listIterator()}). Then, it iterates over the list until the 0N/A * specified element is found or the end of the list is reached. 0N/A * @throws ClassCastException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * <p>This implementation first gets a list iterator that points to the end 0N/A * of the list (with {@code listIterator(size())}). Then, it iterates 0N/A * backwards over the list until the specified element is found, or the 0N/A * beginning of the list is reached. 0N/A * @throws ClassCastException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * Removes all of the elements from this list (optional operation). 0N/A * The list will be empty after this call returns. 0N/A * <p>This implementation calls {@code removeRange(0, size())}. 0N/A * <p>Note that this implementation throws an 0N/A * {@code UnsupportedOperationException} unless {@code remove(int 0N/A * index)} or {@code removeRange(int fromIndex, int toIndex)} is 0N/A * @throws UnsupportedOperationException if the {@code clear} operation 0N/A * is not supported by this list 0N/A * <p>This implementation gets an iterator over the specified collection 0N/A * and iterates over it, inserting the elements obtained from the 0N/A * iterator into this list at the appropriate position, one at a time, 0N/A * using {@code add(int, E)}. 0N/A * Many implementations will override this method for efficiency. 0N/A * <p>Note that this implementation throws an 0N/A * {@code UnsupportedOperationException} unless 0N/A * {@link #add(int, Object) add(int, E)} is overridden. 0N/A * @throws UnsupportedOperationException {@inheritDoc} 0N/A * @throws ClassCastException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws IllegalArgumentException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * Returns an iterator over the elements in this list in proper sequence. 0N/A * <p>This implementation returns a straightforward implementation of the 0N/A * iterator interface, relying on the backing list's {@code size()}, 0N/A * {@code get(int)}, and {@code remove(int)} methods. 0N/A * <p>Note that the iterator returned by this method will throw an 0N/A * {@link UnsupportedOperationException} in response to its 0N/A * {@code remove} method unless the list's {@code remove(int)} method is 0N/A * <p>This implementation can be made to throw runtime exceptions in the 0N/A * face of concurrent modification, as described in the specification 0N/A * for the (protected) {@link #modCount} field. 0N/A * @return an iterator over the elements in this list in proper sequence 0N/A * <p>This implementation returns {@code listIterator(0)}. 0N/A * @see #listIterator(int) 0N/A * <p>This implementation returns a straightforward implementation of the 0N/A * {@code ListIterator} interface that extends the implementation of the 0N/A * {@code Iterator} interface returned by the {@code iterator()} method. 0N/A * The {@code ListIterator} implementation relies on the backing list's 0N/A * {@code get(int)}, {@code set(int, E)}, {@code add(int, E)} 0N/A * and {@code remove(int)} methods. 0N/A * <p>Note that the list iterator returned by this implementation will 0N/A * throw an {@link UnsupportedOperationException} in response to its 0N/A * {@code remove}, {@code set} and {@code add} methods unless the 0N/A * list's {@code remove(int)}, {@code set(int, E)}, and 0N/A * {@code add(int, E)} methods are overridden. 0N/A * <p>This implementation can be made to throw runtime exceptions in the 0N/A * face of concurrent modification, as described in the specification for 0N/A * the (protected) {@link #modCount} field. 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * Index of element to be returned by subsequent call to next. 0N/A * Index of element returned by most recent call to next or 0N/A * previous. Reset to -1 if this element is deleted by a call 0N/A * The modCount value that the iterator believes that the backing 0N/A * List should have. If this expectation is violated, the iterator 0N/A * has detected concurrent modification. 0N/A * <p>This implementation returns a list that subclasses 0N/A * {@code AbstractList}. The subclass stores, in private fields, the 0N/A * offset of the subList within the backing list, the size of the subList 0N/A * (which can change over its lifetime), and the expected 0N/A * {@code modCount} value of the backing list. There are two variants 0N/A * of the subclass, one of which implements {@code RandomAccess}. 0N/A * If this list implements {@code RandomAccess} the returned list will 0N/A * be an instance of the subclass that implements {@code RandomAccess}. 0N/A * <p>The subclass's {@code set(int, E)}, {@code get(int)}, 0N/A * {@code add(int, E)}, {@code remove(int)}, {@code addAll(int, 0N/A * Collection)} and {@code removeRange(int, int)} methods all 0N/A * delegate to the corresponding methods on the backing abstract list, 0N/A * after bounds-checking the index and adjusting for the offset. The 0N/A * {@code addAll(Collection c)} method merely returns {@code addAll(size, 0N/A * <p>The {@code listIterator(int)} method returns a "wrapper object" 0N/A * over a list iterator on the backing list, which is created with the 0N/A * corresponding method on the backing list. The {@code iterator} method 0N/A * merely returns {@code listIterator()}, and the {@code size} method 0N/A * merely returns the subclass's {@code size} field. 0N/A * <p>All methods first check to see if the actual {@code modCount} of 0N/A * the backing list is equal to its expected value, and throw a 0N/A * {@code ConcurrentModificationException} if it is not. 0N/A * @throws IndexOutOfBoundsException if an endpoint index value is out of range 0N/A * {@code (fromIndex < 0 || toIndex > size)} 0N/A * @throws IllegalArgumentException if the endpoint indices are out of order 0N/A * {@code (fromIndex > toIndex)} 0N/A // Comparison and hashing 0N/A * Compares the specified object with this list for equality. Returns 0N/A * {@code true} if and only if the specified object is also a list, both 0N/A * lists have the same size, and all corresponding pairs of elements in 0N/A * the two lists are <i>equal</i>. (Two elements {@code e1} and 0N/A * {@code e2} are <i>equal</i> if {@code (e1==null ? e2==null : 0N/A * e1.equals(e2))}.) In other words, two lists are defined to be 0N/A * equal if they contain the same elements in the same order.<p> 0N/A * This implementation first checks if the specified object is this 0N/A * list. If so, it returns {@code true}; if not, it checks if the 0N/A * specified object is a list. If not, it returns {@code false}; if so, 0N/A * it iterates over both lists, comparing corresponding pairs of elements. 0N/A * If any comparison returns {@code false}, this method returns 0N/A * {@code false}. If either iterator runs out of elements before the 0N/A * other it returns {@code false} (as the lists are of unequal length); 0N/A * otherwise it returns {@code true} when the iterations complete. 0N/A * @param o the object to be compared for equality with this list 0N/A * @return {@code true} if the specified object is equal to this list 0N/A * Returns the hash code value for this list. 0N/A * <p>This implementation uses exactly the code that is used to define the 0N/A * list hash function in the documentation for the {@link List#hashCode} 0N/A * @return the hash code value for this list 0N/A * Removes from this list all of the elements whose index is between 0N/A * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive. 0N/A * Shifts any succeeding elements to the left (reduces their index). 0N/A * This call shortens the list by {@code (toIndex - fromIndex)} elements. 0N/A * (If {@code toIndex==fromIndex}, this operation has no effect.) 0N/A * <p>This method is called by the {@code clear} operation on this list 0N/A * and its subLists. Overriding this method to take advantage of 0N/A * the internals of the list implementation can <i>substantially</i> 0N/A * improve the performance of the {@code clear} operation on this list 0N/A * <p>This implementation gets a list iterator positioned before 0N/A * {@code fromIndex}, and repeatedly calls {@code ListIterator.next} 0N/A * followed by {@code ListIterator.remove} until the entire range has 0N/A * been removed. <b>Note: if {@code ListIterator.remove} requires linear 0N/A * time, this implementation requires quadratic time.</b> 0N/A * @param fromIndex index of first element to be removed 0N/A * @param toIndex index after last element to be removed 0N/A * The number of times this list has been <i>structurally modified</i>. 0N/A * Structural modifications are those that change the size of the 0N/A * list, or otherwise perturb it in such a fashion that iterations in 0N/A * progress may yield incorrect results. 0N/A * <p>This field is used by the iterator and list iterator implementation 0N/A * returned by the {@code iterator} and {@code listIterator} methods. 0N/A * If the value of this field changes unexpectedly, the iterator (or list 0N/A * iterator) will throw a {@code ConcurrentModificationException} in 0N/A * response to the {@code next}, {@code remove}, {@code previous}, 0N/A * {@code set} or {@code add} operations. This provides 0N/A * <i>fail-fast</i> behavior, rather than non-deterministic behavior in 0N/A * the face of concurrent modification during iteration. 0N/A * <p><b>Use of this field by subclasses is optional.</b> If a subclass 0N/A * wishes to provide fail-fast iterators (and list iterators), then it 0N/A * merely has to increment this field in its {@code add(int, E)} and 0N/A * {@code remove(int)} methods (and any other methods that it overrides 0N/A * that result in structural modifications to the list). A single call to 0N/A * {@code add(int, E)} or {@code remove(int)} must add no more than 0N/A * one to this field, or the iterators (and list iterators) will throw 0N/A * bogus {@code ConcurrentModificationExceptions}. If an implementation 0N/A * does not wish to provide fail-fast iterators, this field may be