Package cs2110

Class JavaIndexedSeq<T>

java.lang.Object
cs2110.JavaIndexedSeq<T>
All Implemented Interfaces:
IndexedSeq<T>, Iterable<T>

public class JavaIndexedSeq<T> extends Object implements IndexedSeq<T>
An indexed sequence of elements of type `T` backed by a Java List. Changes made to the sequence are reflected in the original list, and vice versa. Null values must never be added to the backing list. It is recommended that an `ArrayList` is used for the backing list.
  • Constructor Details Link icon

    • JavaIndexedSeq Link icon

      public JavaIndexedSeq(List<T> list)
      Create an `IndexedSeq` backed by `list`. Requires `list` is mutable and does not contain any null values.
  • Method Details Link icon

    • getList Link icon

      public List<T> getList()
      Return the Java List backing this sequence.
    • get Link icon

      public T get(int index)
      Description copied from interface: IndexedSeq
      Return the element at index `index`. Throws `IndexOutOfBoundsException` if `index` is negative or is not less than this sequence's size.
      Specified by:
      get in interface IndexedSeq<T>
    • set Link icon

      public void set(int index, T value)
      Description copied from interface: IndexedSeq
      Assign `value` to the element at index `index`. Throws `IndexOutOfBoundsException` if `index` is negative or is not less than this sequence's size. Requires `value` is not null.
      Specified by:
      set in interface IndexedSeq<T>
    • size Link icon

      public int size()
      Description copied from interface: IndexedSeq
      Return the number of elements in this sequence.
      Specified by:
      size in interface IndexedSeq<T>
    • add Link icon

      public void add(T value)
      Description copied from interface: IndexedSeq
      Append `value` to the end of this sequence. Requires `value` is not null.
      Specified by:
      add in interface IndexedSeq<T>
    • truncate Link icon

      public void truncate(int end)
      Description copied from interface: IndexedSeq
      Truncate this sequence, retaining only the elements with indices `[0..end)`.
      Specified by:
      truncate in interface IndexedSeq<T>
    • sortDistinct Link icon

      public <U extends Comparable<? super U>> void sortDistinct()
      Description copied from interface: IndexedSeq
      Sort the distinct elements in this sequence in ascending order, discarding duplicate copies. Requires `T` is `Comparable` to itself (that is, `T` satisfies the bounds on `U`).
      Specified by:
      sortDistinct in interface IndexedSeq<T>
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object