Interface StaticSequence<Item>

Type Parameters:
Item - the item type
All Superinterfaces:
Container<Item>, Iterable<Item>
All Known Subinterfaces:
DynamicSequence<Item>, LinkedList<Item>
All Known Implementing Classes:
CircularDynamicArray, CircularDynamicArray, DoublyLinkedList, DoublyLinkedList, DynamicArray, DynamicArray, SinglyLinkedList, SinglyLinkedList, StaticArray, StaticArray

public interface StaticSequence<Item> extends Container<Item>
A static sequence.

A container whose n items are in an order given by their indices, where the first item is at index 0, the second at index 1, and so on, the nth being at index n-1.

  • Method Details

    • get

      Item get(int index) throws IndexOutOfBoundsException
      Get the item at the given index.
      Parameters:
      index - the index
      Returns:
      the item that is at that index
      Throws:
      IndexOutOfBoundsException - if index < 0 or index >= n (where n is the size)
    • set

      void set(int index, Item item) throws IndexOutOfBoundsException
      Set the item at the given index.

      Replaces whatever item was there before.

      Parameters:
      index - the index
      item - the new item that should now be at that index
      Throws:
      IndexOutOfBoundsException - if index < 0 or index >= n (where n is the size)
    • first

      default Item first() throws NoSuchElementException
      Get the first item.
      Returns:
      the item at index 0
      Throws:
      NoSuchElementException - if there's no first item to retrieve (i.e. this is empty)
    • last

      default Item last() throws NoSuchElementException
      Get the last item.
      Returns:
      the item at index n-1 (where n is the size)
      Throws:
      NoSuchElementException - if there's no last item to retrieve (i.e. this is empty)
    • setFirst

      default void setFirst(Item item) throws NoSuchElementException
      Set the first item.

      Replaces whatever item was there before.

      Parameters:
      item - the new first item
      Throws:
      NoSuchElementException - if there's no first item to replace (i.e. this is empty)
    • setLast

      default void setLast(Item item) throws NoSuchElementException
      Set the last item.

      Replaces whatever item was there before.

      Parameters:
      item - the new last item
      Throws:
      NoSuchElementException - if there's no last item to replace (i.e. this is empty)
    • swap

      default void swap(int indexA, int indexB) throws IndexOutOfBoundsException
      Swaps the two items at the given indices.
      Parameters:
      indexA - the first index
      indexB - the second index
      Throws:
      IndexOutOfBoundsException - if either of indexA or indexB aren't valid indices
    • items

      default Iterable<Item> items()
      Get a forward iterable that yields each item once.

      The items are iterated over in first-to-last order (by index).

      Specified by:
      items in interface Container<Item>
      Returns:
      an iterable over the items
    • reversed

      default Iterable<Item> reversed()
      Get a reverse iterable that yields each item once.

      The items are iterated over in last-to-first order (by index).

      Returns:
      an iterable over the items