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
n
th being at index n
-1.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic 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 TypeMethodDescriptiondefault Item
first()
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 Item
last()
Get the last item.reversed()
Get a reverse iterable that yields each item once.void
Set the item at the given index.default void
Set the first item.default void
Set the last item.default void
swap
(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
(wheren
is 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
(wheren
is 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 (wheren
is 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 ofindexA
orindexB
aren'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
-