Methods Summary |
---|
public void | add(int location, E object)Inserts the specified object into this List at the specified location.
The object is inserted before any previous element at the specified
location. If the location is equal to the size of this List, the object
is added at the end.
Concrete implementations that would like to support the add functionality
must override this method.
throw new UnsupportedOperationException();
|
public boolean | add(E object)Adds the specified object at the end of this List.
add(size(), object);
return true;
|
public boolean | addAll(int location, java.util.Collection collection)Inserts the objects in the specified Collection at the specified location
in this List. The objects are added in the order they are returned from
the collection's iterator.
Iterator<? extends E> it = collection.iterator();
while (it.hasNext()) {
add(location++, it.next());
}
return !collection.isEmpty();
|
public void | clear()Removes all elements from this list, leaving it empty.
removeRange(0, size());
|
public boolean | equals(java.lang.Object object)Compares the specified object to this list and return true if they are
equal. Two lists are equal when they both contain the same objects in the
same order.
if (this == object) {
return true;
}
if (object instanceof List) {
List<?> list = (List<?>) object;
if (list.size() != size()) {
return false;
}
Iterator<?> it1 = iterator(), it2 = list.iterator();
while (it1.hasNext()) {
Object e1 = it1.next(), e2 = it2.next();
if (!(e1 == null ? e2 == null : e1.equals(e2))) {
return false;
}
}
return true;
}
return false;
|
public abstract E | get(int location)Returns the element at the specified location in this list.
|
public int | hashCode()Returns the hash code of this list. The hash code is calculated by taking
each element's hashcode into account.
int result = 1;
Iterator<?> it = iterator();
while (it.hasNext()) {
Object object = it.next();
result = (31 * result) + (object == null ? 0 : object.hashCode());
}
return result;
|
public int | indexOf(java.lang.Object object)Searches this list for the specified object and returns the index of the
first occurrence.
ListIterator<?> it = listIterator();
if (object != null) {
while (it.hasNext()) {
if (object.equals(it.next())) {
return it.previousIndex();
}
}
} else {
while (it.hasNext()) {
if (it.next() == null) {
return it.previousIndex();
}
}
}
return -1;
|
public java.util.Iterator | iterator()Returns an iterator on the elements of this list. The elements are
iterated in the same order as they occur in the list.
return new SimpleListIterator();
|
public int | lastIndexOf(java.lang.Object object)Searches this list for the specified object and returns the index of the
last occurrence.
ListIterator<?> it = listIterator(size());
if (object != null) {
while (it.hasPrevious()) {
if (object.equals(it.previous())) {
return it.nextIndex();
}
}
} else {
while (it.hasPrevious()) {
if (it.previous() == null) {
return it.nextIndex();
}
}
}
return -1;
|
public java.util.ListIterator | listIterator()Returns a ListIterator on the elements of this list. The elements are
iterated in the same order that they occur in the list.
return listIterator(0);
|
public java.util.ListIterator | listIterator(int location)Returns a list iterator on the elements of this list. The elements are
iterated in the same order as they occur in the list. The iteration
starts at the specified location.
return new FullListIterator(location);
|
public E | remove(int location)Removes the object at the specified location from this list.
throw new UnsupportedOperationException();
|
protected void | removeRange(int start, int end)Removes the objects in the specified range from the start to the end
index minus one.
Iterator<?> it = listIterator(start);
for (int i = start; i < end; i++) {
it.next();
it.remove();
}
|
public E | set(int location, E object)Replaces the element at the specified location in this list with the
specified object.
throw new UnsupportedOperationException();
|
public java.util.List | subList(int start, int end)Returns a part of consecutive elements of this list as a view. The
returned view will be of zero length if start equals end. Any change that
occurs in the returned subList will be reflected to the original list,
and vice-versa. All the supported optional operations by the original
list will also be supported by this subList.
This method can be used as a handy method to do some operations on a sub
range of the original list, for example
{@code list.subList(from, to).clear();}
If the original list is modified in other ways than through the returned
subList, the behavior of the returned subList becomes undefined.
The returned subList is a subclass of AbstractList. The subclass stores
offset, size of itself, and modCount of the original list. If the
original list implements RandomAccess interface, the returned subList
also implements RandomAccess interface.
The subList's set(int, Object), get(int), add(int, Object), remove(int),
addAll(int, Collection) and removeRange(int, int) methods first check the
bounds, adjust offsets and then call the corresponding methods of the
original AbstractList. addAll(Collection c) method of the returned
subList calls the original addAll(offset + size, c).
The listIterator(int) method of the subList wraps the original list
iterator. The iterator() method of the subList invokes the original
listIterator() method, and the size() method merely returns the size of
the subList.
All methods will throw a ConcurrentModificationException if the modCount
of the original list is not equal to the expected value.
if (0 <= start && end <= size()) {
if (start <= end) {
if (this instanceof RandomAccess) {
return new SubAbstractListRandomAccess<E>(this, start, end);
}
return new SubAbstractList<E>(this, start, end);
}
throw new IllegalArgumentException();
}
throw new IndexOutOfBoundsException();
|