< prev index next >

src/java.base/share/classes/java/util/List.java

Print this page

        

*** 21,33 **** * 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; ! import java.util.function.UnaryOperator; /** * An ordered collection (also known as a <i>sequence</i>). The user of this * interface has precise control over where in the list each element is * inserted. The user can access elements by their integer index (position in --- 21,35 ---- * 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 javany.util.function.UnaryOperator; ! ! import java.util.Objects; /** * An ordered collection (also known as a <i>sequence</i>). The user of this * interface has precise control over where in the list each element is * inserted. The user can access elements by their integer index (position in
*** 106,116 **** * @see AbstractList * @see AbstractSequentialList * @since 1.2 */ ! public interface List<E> extends Collection<E> { // Query Operations /** * Returns the number of elements in this list. If this list contains * more than <tt>Integer.MAX_VALUE</tt> elements, returns --- 108,118 ---- * @see AbstractList * @see AbstractSequentialList * @since 1.2 */ ! public interface List<any E> extends Collection<E> { // Query Operations /** * Returns the number of elements in this list. If this list contains * more than <tt>Integer.MAX_VALUE</tt> elements, returns
*** 206,216 **** * @throws ArrayStoreException if the runtime type of the specified array * is not a supertype of the runtime type of every element in * this list * @throws NullPointerException if the specified array is null */ ! <T> T[] toArray(T[] a); // Modification Operations /** --- 208,218 ---- * @throws ArrayStoreException if the runtime type of the specified array * is not a supertype of the runtime type of every element in * this list * @throws NullPointerException if the specified array is null */ ! <any T> T[] toArray(T[] a); // Modification Operations /**
*** 472,487 **** * contract * @since 1.8 */ @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); } } /** * Removes all of the elements from this list (optional operation). --- 474,489 ---- * contract * @since 1.8 */ @SuppressWarnings({"unchecked", "rawtypes"}) default void sort(Comparator<? super E> c) { ! E[] a = this.toArray(new E[size()]); ! Arrays.sort(a, c); ListIterator<E> i = this.listIterator(); ! for (E e : a) { i.next(); ! i.set(e); } } /** * Removes all of the elements from this list (optional operation).
*** 619,628 **** --- 621,638 ---- * list does not permit null elements * (<a href="Collection.html#optional-restrictions">optional</a>) */ int indexOf(Object o); + default int indexOfElement(E e) { + ListIterator<E> it = listIterator(); + while (it.hasNext()) + if (Any.equals(e, it.next())) + return it.previousIndex(); + return -1; + } + /** * Returns the index of the last occurrence of the specified element * in this list, or -1 if this list does not contain the element. * More formally, returns the highest index <tt>i</tt> such that * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
*** 638,647 **** --- 648,664 ---- * list does not permit null elements * (<a href="Collection.html#optional-restrictions">optional</a>) */ int lastIndexOf(Object o); + default int lastIndexOfElement(E e) { + ListIterator<E> it = listIterator(size()); + while (it.hasPrevious()) + if (Any.equals(e, it.previous())) + return it.nextIndex(); + return -1; + } // List Iterators /** * Returns a list iterator over the elements in this list (in proper
*** 725,734 **** * {@link Spliterator#SUBSIZED}. * * @return a {@code Spliterator} over the elements in this list * @since 1.8 */ ! @Override ! default Spliterator<E> spliterator() { ! return Spliterators.spliterator(this, Spliterator.ORDERED); ! } } --- 742,751 ---- * {@link Spliterator#SUBSIZED}. * * @return a {@code Spliterator} over the elements in this list * @since 1.8 */ ! // @Override ! // default Spliterator<E> spliterator() { ! // return Spliterators.spliterator(this, Spliterator.ORDERED); ! // } }
< prev index next >