Interface PositionalList<E>

Type Parameters:
E - the element type stored at a position
All Superinterfaces:
Iterable<E>
All Known Implementing Classes:
LinkedPositionalList

public interface PositionalList<E> extends Iterable<E>
An interface for positional lists.
See Also:
  • Method Details

    • size

      int size()
      Returns the number of elements in the list.
      Returns:
      number of elements in the list
    • isEmpty

      boolean isEmpty()
      Tests whether the list is empty.
      Returns:
      true if the list is empty, false otherwise
    • first

      Position<E> first()
      Returns the first Position in the list.
      Returns:
      the first Position in the list (or null, if empty)
    • last

      Position<E> last()
      Returns the last Position in the list.
      Returns:
      the last Position in the list (or null, if empty)
    • before

      Returns the Position immediately before Position p.
      Parameters:
      p - a Position of the list
      Returns:
      the Position of the preceding element (or null, if p is first)
      Throws:
      IllegalArgumentException - if p is not a valid position for this list
    • after

      Returns the Position immediately after Position p.
      Parameters:
      p - a Position of the list
      Returns:
      the Position of the following element (or null, if p is last)
      Throws:
      IllegalArgumentException - if p is not a valid position for this list
    • addFirst

      Position<E> addFirst(E e)
      Inserts an element at the front of the list.
      Parameters:
      e - the new element
      Returns:
      the Position representing the location of the new element
    • addLast

      Position<E> addLast(E e)
      Inserts an element at the back of the list.
      Parameters:
      e - the new element
      Returns:
      the Position representing the location of the new element
    • addBefore

      Position<E> addBefore(Position<E> p, E e) throws IllegalArgumentException
      Inserts an element immediately before the given Position.
      Parameters:
      p - the Position before which the insertion takes place
      e - the new element
      Returns:
      the Position representing the location of the new element
      Throws:
      IllegalArgumentException - if p is not a valid position for this list
    • addAfter

      Position<E> addAfter(Position<E> p, E e) throws IllegalArgumentException
      Inserts an element immediately after the given Position.
      Parameters:
      p - the Position after which the insertion takes place
      e - the new element
      Returns:
      the Position representing the location of the new element
      Throws:
      IllegalArgumentException - if p is not a valid position for this list
    • set

      E set(Position<E> p, E e) throws IllegalArgumentException
      Replaces the element stored at the given Position and returns the replaced element.
      Parameters:
      p - the Position of the element to be replaced
      e - the new element
      Returns:
      the replaced element
      Throws:
      IllegalArgumentException - if p is not a valid position for this list
    • remove

      E remove(Position<E> p) throws IllegalArgumentException
      Removes the element stored at the given Position and returns it. The given position is invalidated as a result.
      Parameters:
      p - the Position of the element to be removed
      Returns:
      the removed element
      Throws:
      IllegalArgumentException - if p is not a valid position for this list
    • iterator

      Iterator<E> iterator()
      Returns an iterator of the elements stored in the list.
      Specified by:
      iterator in interface Iterable<E>
      Returns:
      iterator of the list's elements
    • positions

      Iterable<Position<E>> positions()
      Returns the positions of the list in iterable form from first to last.
      Returns:
      iterable collection of the list's positions