Interface StaticSequence<Item>

Type Parameters:
Item - the item type
All Superinterfaces:
Container<Item>, dsa.lib.DSAInterface, 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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    A forward iterator over the items in a sequence.
    static class 
    A reverse iterator over the items in a sequence.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Item
    Get the first item.
    get(int index)
    Get the item at the given index.
    default Iterable<Item>
    Get a forward iterable that yields each item once.
    default Item
    Get the last item.
    default Iterable<Item>
    Get a reverse iterable that yields each item once.
    void
    set(int index, Item item)
    Set the item at the given index.
    default void
    setFirst(Item item)
    Set the first item.
    default void
    setLast(Item item)
    Set the last item.
    default void
    swap(int indexA, int indexB)
    Swaps the two items at the given indices.

    Methods inherited from interface dsa.lab02.base.Container

    contains, isEmpty, iterator, size, toString

    Methods inherited from interface dsa.lib.DSAInterface

    toDebugString

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • 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