Package utilities

Interface ListADT<E>

Type Parameters:
E - The type of elements this list holds.
All Superinterfaces:
Serializable
All Known Implementing Classes:
MyArrayList

public interface ListADT<E> extends Serializable

The ListADT interface is designed to be used as a basis for all the Linear data structures that will be developed in the CPRG 304 class at SAIT. The implementors of this interface will be required to add all the functionality.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(int index, E toAdd)
    Inserts the specified element at the specified position in this list.
    boolean
    add(E toAdd)
    Appends the specified element to the end of this list.
    boolean
    addAll(ListADT<? extends E> toAdd)
    Appends all the elements in the specified java.utilCollection to the end of this list, in the order that they are returned by the specified collection's Iterator.
    void
    Removes all of the elements from this list.
    boolean
    contains(E toFind)
    Returns true if this list contains the specified element.
    get(int index)
    Returns the element at the specified position in this list.
    boolean
    Returns true if this list contains no elements.
    Returns an iterator over the elements in this list, in a proper sequence.
    remove(int index)
    Removes the element at the specified position in this list.
    remove(E toRemove)
    Removes the first occurrence in this list of the specified element.
    set(int index, E toChange)
    Replaces the element at the specified position in this list with the specified element.
    int
    The size method will return the current element count contained in the list.
    Returns an array containing all the elements in this list in a proper sequence.
    E[]
    toArray(E[] toHold)
    Returns an array containing all of the elements in this list in a proper sequence; the runtime type of the returned array is that of the specified array.
  • Method Details

    • size

      int size()
      The size method will return the current element count contained in the list.
      Returns:
      The current element count.
    • clear

      void clear()
      Removes all of the elements from this list. This list will be empty after this call returns.
    • add

      boolean add(int index, E toAdd) throws NullPointerException, IndexOutOfBoundsException
      Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      Parameters:
      index - The index at which the specified element is to be inserted. The element is inserted before the existing element at [index], or at the end if index is equal to the size (size()).
      toAdd - The element to be inserted.
      Returns:
      true if the element is added successfully.
      Throws:
      NullPointerException - If the specified element is null and the list implementation does not support having null elements.
      IndexOutOfBoundsException - If the index is out of range:
      i.e. (index < 0 || index >= size()).
    • add

      boolean add(E toAdd) throws NullPointerException, IndexOutOfBoundsException
      Appends the specified element to the end of this list. Implementations that support this operation may place limitations on what elements may be added to this list. In particular, some implementations will refuse to add null elements. List classes should clearly specify in their documentation any restrictions on what elements may be added.
      Parameters:
      toAdd - Element to be appended to this list.
      Returns:
      true if the element appended successfully.
      Throws:
      NullPointerException - If the specified element is null and the list implementation does not support having null elements.
      IndexOutOfBoundsException - If the index is out of range:
      i.e. (index < 0 || index >= size()).
    • addAll

      boolean addAll(ListADT<? extends E> toAdd) throws NullPointerException
      Appends all the elements in the specified java.utilCollection to the end of this list, in the order that they are returned by the specified collection's Iterator. The behaviour of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
      Parameters:
      toAdd - The new sub list to be added.
      Returns:
      true If the operation is successful.
      Throws:
      NullPointerException - If the specified element is null and the list implementation does not support having null elements.
    • get

      E get(int index) throws IndexOutOfBoundsException
      Returns the element at the specified position in this list.
      Parameters:
      index - Index of the element to return.
      Returns:
      The element at the specified position in this list.
      Throws:
      IndexOutOfBoundsException - If the index is out of range:
      i.e. (index < 0 || index >= size()).
    • remove

      E remove(int index) throws IndexOutOfBoundsException
      Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
      Parameters:
      index - The index of the element to remove.
      Returns:
      The removed element.
      Throws:
      IndexOutOfBoundsException - If the index is out of range:
      i.e. (index < 0 || index >= size()).
    • remove

      E remove(E toRemove) throws NullPointerException
      Removes the first occurrence in this list of the specified element. If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that o.equals(get(i)) (if such an element exists).
      Parameters:
      toRemove - The element to be removed from this list.
      Returns:
      The element which is being removed, or null if the list does not contain the element.
      Throws:
      NullPointerException - If the specified element is null and the list implementation does not support having null elements.
    • set

      E set(int index, E toChange) throws NullPointerException, IndexOutOfBoundsException
      Replaces the element at the specified position in this list with the specified element.
      Parameters:
      index - The index of the element to replace.
      toChange - Element to be stored at the specified position.
      Returns:
      The element previously at the specified position.
      Throws:
      NullPointerException - If the specified element is null and the list implementation does not support having null elements.
      IndexOutOfBoundsException - If the index is out of range:
      i.e. (index < 0 || index >= size()).
    • isEmpty

      boolean isEmpty()
      Returns true if this list contains no elements.
      Returns:
      true if this list contains no elements.
    • contains

      boolean contains(E toFind) throws NullPointerException
      Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that toFind.equals(e).
      Parameters:
      toFind - The element whose presence in this list is to be tested.
      Returns:
      true if this list contains the specified element.
      Throws:
      NullPointerException - If the specified element is null and the list implementation does not support having null elements.
    • toArray

      E[] toArray(E[] toHold) throws NullPointerException
      Returns an array containing all of the elements in this list in a proper sequence; the runtime type of the returned array is that of the specified array. Obeys the general contract of the java.util.Collection.toArray(Object []) method.
      Parameters:
      toHold - The array into which the elements of this list are to be stored if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
      An array containing the elements of this list.
      Throws:
      NullPointerException - If the specified array is null.
    • toArray

      Object[] toArray()
      Returns an array containing all the elements in this list in a proper sequence. Obeys the general contract of the java.util.Collection.toArray() method.
      Returns:
      An array containing all the elements in this list in a proper sequence.
    • iterator

      Iterator<E> iterator()
      Returns an iterator over the elements in this list, in a proper sequence.
      Returns:
      An iterator over the elements in this list, in a proper sequence. NB: The return is of type linearUtilities.Iterator<E>, not java.util.Iterator.