package java.util;
public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> {
/**
* 唯一构造器. (For invocation by subclass constructors, typically
* implicit.)
*/
protected AbstractList() {
}
/**
* 将指定元素追加到此列表的末尾 (可选操作)。
*/
public boolean add(E e) {
add(size(), e);
return true;
}
/**
* 返回此列表中指定位置的元素。
*/
abstract public E get(int index);
/**
* 用指定的元素替换此列表中指定位置的元素 (可选操作)。
*/
public E set(int index, E element) {
throw new UnsupportedOperationException();
}
/**
* 将指定元素插入此列表中的指定位置 (可选操作)。
*/
public void add(int index, E element) {
throw new UnsupportedOperationException();
}
/**
* 移除此列表中指定位置的元素 (可选操作)。
*/
public E remove(int index) {
throw new UnsupportedOperationException();
}
// Search Operations
/**
* 返回此列表中指定元素的第一个匹配项的索引, 如果此列表不包含元素, 则为-1。
*/
public int indexOf(Object o) {
ListIterator<E> it = listIterator();
if (o==null) {
while (it.hasNext())
if (it.next()==null)
return it.previousIndex();
} else {
while (it.hasNext())
if (o.equals(it.next()))
return it.previousIndex();
}
return -1;
}
/**
* 返回此列表中指定元素的最后一个匹配项的索引, 如果此列表不包含元素, 则为-1。
*/
public int lastIndexOf(Object o) {
ListIterator<E> it = listIterator(size());
if (o==null) {
while (it.hasPrevious())
if (it.previous()==null)
return it.nextIndex();
} else {
while (it.hasPrevious())
if (o.equals(it.previous()))
return it.nextIndex();
}
return -1;
}
// Bulk Operations
public void clear() {
removeRange(0, size());
}
public boolean addAll(int index, Collection<? extends E> c) {
rangeCheckForAdd(index);
boolean modified = false;
for (E e : c) {
add(index++, e);
modified = true;
}
return modified;
}
// Iterators
/**package java.util;
public abstract class