Package dsa.lab02.base
Interface StaticSequence<Item>
- Type Parameters:
Item- the item type
- All Known Subinterfaces:
DynamicSequence<Item>,LinkedList<Item>
- All Known Implementing Classes:
CircularDynamicArray,CircularDynamicArray,DoublyLinkedList,DoublyLinkedList,DynamicArray,DynamicArray,SinglyLinkedList,SinglyLinkedList,StaticArray,StaticArray
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 ClassesModifier and TypeInterfaceDescriptionstatic classA forward iterator over the items in a sequence.static classA reverse iterator over the items in a sequence. -
Method Summary
Modifier and TypeMethodDescriptiondefault Itemfirst()Get the first item.get(int index) Get the item at the given index.items()Get a forward iterable that yields each item once.default Itemlast()Get the last item.reversed()Get a reverse iterable that yields each item once.voidSet the item at the given index.default voidSet the first item.default voidSet the last item.default voidswap(int indexA, int indexB) Swaps the two items at the given indices.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
get
Get the item at the given index.- Parameters:
index- the index- Returns:
- the item that is at that index
- Throws:
IndexOutOfBoundsException- ifindex< 0 orindex>=n(wherenis the size)
-
set
Set the item at the given index.Replaces whatever item was there before.
- Parameters:
index- the indexitem- the new item that should now be at that index- Throws:
IndexOutOfBoundsException- ifindex< 0 orindex>=n(wherenis the size)
-
first
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
Get the last item.- Returns:
- the item at index
n-1 (wherenis the size) - Throws:
NoSuchElementException- if there's no last item to retrieve (i.e. this is empty)
-
setFirst
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
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
Swaps the two items at the given indices.- Parameters:
indexA- the first indexindexB- the second index- Throws:
IndexOutOfBoundsException- if either ofindexAorindexBaren't valid indices
-
items
Get a forward iterable that yields each item once.The items are iterated over in first-to-last order (by index).
-
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
-