--- old/src/java.base/share/classes/java/util/AbstractList.java 2015-02-04 10:44:09.336980974 +0100 +++ new/src/java.base/share/classes/java/util/AbstractList.java 2015-02-04 10:44:09.224983051 +0100 @@ -23,7 +23,13 @@ * questions. */ -package java.util; +package javany.util; + +import java.util.ConcurrentModificationException; +import java.util.NoSuchElementException; +import java.util.RandomAccess; + +import javany.util.function.*; /** * This class provides a skeletal implementation of the {@link List} @@ -68,7 +74,7 @@ * @since 1.2 */ -public abstract class AbstractList extends AbstractCollection implements List { +public abstract class AbstractList extends AbstractCollection implements List { /** * Sole constructor. (For invocation by subclass constructors, typically * implicit.) @@ -180,17 +186,30 @@ * @throws NullPointerException {@inheritDoc} */ public int indexOf(Object o) { - ListIterator it = listIterator(); - if (o==null) { - while (it.hasNext()) - if (it.next()==null) - return it.previousIndex(); - } else { + __WhereVal(E) { + if (o == null) { + return -1; + } + ListIterator it = listIterator(); + Function box = Any.converter(); while (it.hasNext()) - if (o.equals(it.next())) + if (o.equals(box.apply(it.next()))) // boxing return it.previousIndex(); + return -1; + } + __WhereRef(E) { + ListIterator 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; } - return -1; } /** @@ -206,17 +225,30 @@ * @throws NullPointerException {@inheritDoc} */ public int lastIndexOf(Object o) { - ListIterator it = listIterator(size()); - if (o==null) { - while (it.hasPrevious()) - if (it.previous()==null) - return it.nextIndex(); - } else { + __WhereVal(E) { + if (o == null) { + return -1; + } + ListIterator it = listIterator(size()); + Function box = Any.converter(); while (it.hasPrevious()) - if (o.equals(it.previous())) + if (o.equals(box.apply(it.previous()))) // boxing return it.nextIndex(); + return -1; + } + __WhereRef(E) { + ListIterator 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; } - return -1; } @@ -264,7 +296,9 @@ public boolean addAll(int index, Collection c) { rangeCheckForAdd(index); boolean modified = false; - for (E e : c) { + Iterator it = c.iterator(); + while (it.hasNext()) { + E e = it.next(); add(index++, e); modified = true; } @@ -522,18 +556,17 @@ * @param o the object to be compared for equality with this list * @return {@code true} if the specified object is equal to this list */ + @SuppressWarnings("unchecked") public boolean equals(Object o) { if (o == this) return true; - if (!(o instanceof List)) + if (!(o instanceof List)) return false; ListIterator e1 = listIterator(); - ListIterator e2 = ((List) o).listIterator(); + ListIterator e2 = ((List) o).listIterator(); while (e1.hasNext() && e2.hasNext()) { - E o1 = e1.next(); - Object o2 = e2.next(); - if (!(o1==null ? o2==null : o1.equals(o2))) + if (!Any.equals(e1.next(), e2.next())) return false; } return !(e1.hasNext() || e2.hasNext()); @@ -551,8 +584,11 @@ */ public int hashCode() { int hashCode = 1; - for (E e : this) - hashCode = 31*hashCode + (e==null ? 0 : e.hashCode()); + Iterator it = iterator(); + while (it.hasNext()) { + E e = it.next(); + hashCode = 31 * hashCode + Any.hashCode(e); + } return hashCode; } @@ -625,7 +661,7 @@ } } -class SubList extends AbstractList { +class SubList extends AbstractList { private final AbstractList l; private final int offset; private int size; @@ -785,7 +821,7 @@ } } -class RandomAccessSubList extends SubList implements RandomAccess { +class RandomAccessSubList extends SubList implements RandomAccess { RandomAccessSubList(AbstractList list, int fromIndex, int toIndex) { super(list, fromIndex, toIndex); }