package java.util;
import java.util.function.UnaryOperator;
//顺序存储的数据结构的接口,链表,动态数组,队列,栈
//继承 Collection,大部分方法与Collection接口中的方法一致
public interface List<E> extends Collection<E> {
// 查询方法,同Collection接口
int size();
boolean isEmpty();
boolean contains(Object o);
Iterator<E> iterator();
Object[] toArray();
<T> T[] toArray(T[] a);
// 修改方法
boolean add(E e);
boolean remove(Object o);
// 扩展方法,同Collection接口
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c);
boolean addAll(int index, Collection<? extends E> c);
boolean removeAll(Collection<?> c);
boolean retainAll(Collection<?> c);
default void replaceAll(UnaryOperator<E> operator) {
Objects.requireNonNull(operator);
final ListIterator<E> li = this.listIterator();
while (li.hasNext()) {
li.set(operator.apply(li.next()));
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
default void sort(Comparator<? super E> c) {
Object[] a = this.toArray();
Arrays.sort(a, (Comparator) c);
ListIterator<E> i = this.listIterator();
for (Object e : a) {
i.next();
i.set((E) e);
}
}
void clear();
boolean equals(Object o);
int hashCode();
// 含有index的方法
E get(int index);//查询index处的元素
E set(int index, E element);//设置index处的元素
void add(int index, E element);//index处插入元素
E remove(int index);//移除index处的元素
// 查找元素
int indexOf(Object o); //顺序查找第一个对象o,返回其index
int lastIndexOf(Object o);//逆序(从后往前),返回其index
// List Iterators
ListIterator<E> listIterator();
ListIterator<E> listIterator(int index);//从list的index开始迭代,返回迭代器
// View 返回 子list,index从fromIndex 到 toIndex
List<E> subList(int fromIndex, int toIndex);
//可分割迭代器
@Override
default Spliterator<E> spliterator() {
return Spliterators.spliterator(this, Spliterator.ORDERED);
}
}