< prev index next >
src/java.base/share/classes/java/util/AbstractList.java
Print this page
*** 21,31 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package java.util;
/**
* This class provides a skeletal implementation of the {@link List}
* interface to minimize the effort required to implement this interface
* backed by a "random access" data store (such as an array). For sequential
--- 21,37 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! 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}
* interface to minimize the effort required to implement this interface
* backed by a "random access" data store (such as an array). For sequential
*** 66,76 ****
* @author Josh Bloch
* @author Neal Gafter
* @since 1.2
*/
! public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E> {
/**
* Sole constructor. (For invocation by subclass constructors, typically
* implicit.)
*/
protected AbstractList() {
--- 72,82 ----
* @author Josh Bloch
* @author Neal Gafter
* @since 1.2
*/
! public abstract class AbstractList<any E> extends AbstractCollection<E> implements List<E> {
/**
* Sole constructor. (For invocation by subclass constructors, typically
* implicit.)
*/
protected AbstractList() {
*** 178,199 ****
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
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;
}
/**
* {@inheritDoc}
*
* @implSpec
--- 184,218 ----
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
public int indexOf(Object o) {
+ __WhereVal(E) {
+ if (o == null) {
+ return -1;
+ }
+ ListIterator<E> it = listIterator();
+ Function<E, Object> box = Any.converter();
+ while (it.hasNext())
+ if (o.equals(box.apply(it.next()))) // boxing
+ return it.previousIndex();
+ return -1;
+ }
+ __WhereRef(E) {
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;
}
+ }
/**
* {@inheritDoc}
*
* @implSpec
*** 204,225 ****
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
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
/**
--- 223,257 ----
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
public int lastIndexOf(Object o) {
+ __WhereVal(E) {
+ if (o == null) {
+ return -1;
+ }
ListIterator<E> it = listIterator(size());
! Function<E, Object> box = Any.converter();
while (it.hasPrevious())
! if (o.equals(box.apply(it.previous()))) // boxing
! return it.nextIndex();
! return -1;
! }
! __WhereRef(E) {
! 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
/**
*** 262,272 ****
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
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;
}
--- 294,306 ----
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public boolean addAll(int index, Collection<? extends E> c) {
rangeCheckForAdd(index);
boolean modified = false;
! Iterator<? extends E> it = c.iterator();
! while (it.hasNext()) {
! E e = it.next();
add(index++, e);
modified = true;
}
return modified;
}
*** 520,541 ****
* otherwise it returns {@code true} when the iterations complete.
*
* @param o the object to be compared for equality with this list
* @return {@code true} if the specified object is equal to this list
*/
public boolean equals(Object o) {
if (o == this)
return true;
! if (!(o instanceof List))
return false;
ListIterator<E> e1 = 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)))
return false;
}
return !(e1.hasNext() || e2.hasNext());
}
--- 554,574 ----
* otherwise it returns {@code true} when the iterations complete.
*
* @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<E>))
return false;
ListIterator<E> e1 = listIterator();
! ListIterator<? extends E> e2 = ((List<? extends E>) o).listIterator();
while (e1.hasNext() && e2.hasNext()) {
! if (!Any.equals(e1.next(), e2.next()))
return false;
}
return !(e1.hasNext() || e2.hasNext());
}
*** 549,560 ****
*
* @return the hash code value for this list
*/
public int hashCode() {
int hashCode = 1;
! for (E e : this)
! hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
return hashCode;
}
/**
* Removes from this list all of the elements whose index is between
--- 582,596 ----
*
* @return the hash code value for this list
*/
public int hashCode() {
int hashCode = 1;
! Iterator<E> it = iterator();
! while (it.hasNext()) {
! E e = it.next();
! hashCode = 31 * hashCode + Any.hashCode(e);
! }
return hashCode;
}
/**
* Removes from this list all of the elements whose index is between
*** 623,633 ****
private String outOfBoundsMsg(int index) {
return "Index: "+index+", Size: "+size();
}
}
! class SubList<E> extends AbstractList<E> {
private final AbstractList<E> l;
private final int offset;
private int size;
SubList(AbstractList<E> list, int fromIndex, int toIndex) {
--- 659,669 ----
private String outOfBoundsMsg(int index) {
return "Index: "+index+", Size: "+size();
}
}
! class SubList<any E> extends AbstractList<E> {
private final AbstractList<E> l;
private final int offset;
private int size;
SubList(AbstractList<E> list, int fromIndex, int toIndex) {
*** 783,793 ****
if (this.modCount != l.modCount)
throw new ConcurrentModificationException();
}
}
! class RandomAccessSubList<E> extends SubList<E> implements RandomAccess {
RandomAccessSubList(AbstractList<E> list, int fromIndex, int toIndex) {
super(list, fromIndex, toIndex);
}
public List<E> subList(int fromIndex, int toIndex) {
--- 819,829 ----
if (this.modCount != l.modCount)
throw new ConcurrentModificationException();
}
}
! class RandomAccessSubList<any E> extends SubList<E> implements RandomAccess {
RandomAccessSubList(AbstractList<E> list, int fromIndex, int toIndex) {
super(list, fromIndex, toIndex);
}
public List<E> subList(int fromIndex, int toIndex) {
< prev index next >