1  import java.util.Collection;
  2  
  3  public interface MyList<E> extends Collection<E> {
  4    /** Add a new element at the specified index in this list */
  5    public void add(int index, E e);
  6  
  7    /** Return the element from this list at the specified index */
  8    public E get(int index);
  9  
 10    /** Return the index of the first matching element in this list.
 11     *  Return -1 if no match. */
 12    public int indexOf(Object e);
 13  
 14    /** Return the index of the last matching element in this list
 15     *  Return -1 if no match. */
 16    public int lastIndexOf(E e);
 17  
 18    /** Remove the element at the specified position in this list
 19     *  Shift any subsequent elements to the left.
 20     *  Return the element that was removed from the list. */
 21    public E remove(int index);
 22  
 23    /** Replace the element at the specified position in this list
 24     *  with the specified element and returns the new set. */
 25    public E set(int index, E e);
 26    
 27    @Override /** Add a new element at the end of this list */
 28    public default boolean add(E e) {
 29      add(size(), e);
 30      return true;
 31    }
 32  
 33    @Override /** Return true if this list contains no elements */
 34    public default boolean isEmpty() {
 35      return size() == 0;
 36    }
 37  
 38    @Override /** Remove the first occurrence of the element e 
 39     *  from this list. Shift any subsequent elements to the left.
 40     *  Return true if the element is removed. */
 41    public default boolean remove(Object e) {
 42      if (indexOf(e) >= 0) {
 43        remove(indexOf(e));
 44        return true;
 45      }
 46      else
 47        return false;
 48    }
 49  
 50    @Override
 51    public default boolean containsAll(Collection<?> c) {
 52      // Left as an exercise
 53      return true;
 54    }
 55  
 56    @Override
 57    public default boolean addAll(Collection<? extends E> c) {
 58      // Left as an exercise
 59      return true;
 60    }
 61  
 62    @Override
 63    public default boolean removeAll(Collection<?> c) {
 64      // Left as an exercise
 65      return true;
 66    }
 67  
 68    @Override
 69    public default boolean retainAll(Collection<?> c) {
 70      // Left as an exercise
 71      return true;
 72    }
 73  
 74    @Override
 75    public default Object[] toArray() {
 76      // Left as an exercise
 77      return null;
 78    }
 79  
 80    @Override
 81    public default <T> T[] toArray(T[] array) {
 82      // Left as an exercise
 83      return null;
 84    }
 85  }