< prev index next >

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

Print this page

        

@@ -21,13 +21,15 @@
  * 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;
+package javany.util;
 
-import java.util.function.UnaryOperator;
+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,11 +108,11 @@
  * @see AbstractList
  * @see AbstractSequentialList
  * @since 1.2
  */
 
-public interface List<E> extends Collection<E> {
+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,11 +208,11 @@
      * @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);
+    <any T> T[] toArray(T[] a);
 
 
     // Modification Operations
 
     /**

@@ -472,16 +474,16 @@
      *         contract
      * @since 1.8
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
     default void sort(Comparator<? super E> c) {
-        Object[] a = this.toArray();
-        Arrays.sort(a, (Comparator) c);
+        E[] a = this.toArray(new E[size()]);
+        Arrays.sort(a, c);
         ListIterator<E> i = this.listIterator();
-        for (Object e : a) {
+        for (E e : a) {
             i.next();
-            i.set((E) e);
+            i.set(e);
         }
     }
 
     /**
      * Removes all of the elements from this list (optional operation).

@@ -619,10 +621,18 @@
      *         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,10 +648,17 @@
      *         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,10 +742,10 @@
      * {@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);
-    }
+//    @Override
+//    default Spliterator<E> spliterator() {
+//        return Spliterators.spliterator(this, Spliterator.ORDERED);
+//    }
 }
< prev index next >