E
- The type of element to be stored in this sequence.public class NodeSequence<E> extends java.lang.Object implements Sequence<E>
Constructor and Description |
---|
NodeSequence() |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
E element)
Inserts an element e to be at index i, shifting all elements after this.
|
void |
addAfter(Position<E> pos,
E element)
Inserts an element after the given node in the list.
|
void |
addBefore(Position<E> pos,
E element)
Inserts an element before the given node in the list.
|
void |
addFirst(E element)
Inserts an element to be the first in the deque.
|
void |
addLast(E element)
Inserts an element to be the last in the deque.
|
Position<E> |
atIndex(int index)
Returns the position containing the element at the given index.
|
Position<E> |
first()
Returns the first node in the list.
|
E |
get(int index)
Returns the element at index i, without removing it.
|
E |
getFirst()
Returns the first element; an exception is thrown if deque is empty.
|
E |
getLast()
Returns the last element; an exception is thrown if deque is empty.
|
int |
indexOf(Position<E> pos)
Returns the index of the element stored at the given position.
|
boolean |
isEmpty()
Returns whether the deque is empty.
|
java.util.Iterator<E> |
iterator()
Returns an iterator of all the elements in the list.
|
Position<E> |
last()
Returns the last node in the list.
|
Position<E> |
next(Position<E> pos)
Returns the node after a given node in the list.
|
java.lang.Iterable<Position<E>> |
positions()
Returns an iterable collection of all the nodes in the list.
|
Position<E> |
prev(Position<E> pos)
Returns the node before a given node in the list.
|
E |
remove(int index)
Removes and returns the element at index i, shifting the elements after this.
|
E |
remove(Position<E> pos)
Removes a node from the list, returning the element stored there.
|
E |
removeFirst()
Removes the first element; an exception is thrown if deque is empty.
|
E |
removeLast()
Removes the last element; an exception is thrown if deque is empty.
|
E |
set(int index,
E element)
Replaces the element at index i with e, returning the previous element at i.
|
E |
set(Position<E> pos,
E element)
Replaces the element stored at the given node, returning old element.
|
int |
size()
Returns the number of elements in the deque.
|
public void add(int index, E element) throws java.lang.IndexOutOfBoundsException
IndexList
public void addAfter(Position<E> pos, E element) throws InvalidPositionException
PositionList
addAfter
in interface PositionList<E>
InvalidPositionException
public void addBefore(Position<E> pos, E element) throws InvalidPositionException
PositionList
addBefore
in interface PositionList<E>
InvalidPositionException
public void addFirst(E element)
Deque
public void addLast(E element)
Deque
public Position<E> atIndex(int index) throws BoundaryViolationException
Sequence
atIndex
in interface Sequence<E>
BoundaryViolationException
public Position<E> first()
PositionList
first
in interface PositionList<E>
public E get(int index) throws java.lang.IndexOutOfBoundsException
IndexList
public E getFirst() throws EmptyDequeException
Deque
getFirst
in interface Deque<E>
EmptyDequeException
public E getLast() throws EmptyDequeException
Deque
getLast
in interface Deque<E>
EmptyDequeException
public int indexOf(Position<E> pos) throws InvalidPositionException
Sequence
indexOf
in interface Sequence<E>
InvalidPositionException
public boolean isEmpty()
Deque
public java.util.Iterator<E> iterator()
PositionList
iterator
in interface java.lang.Iterable<E>
iterator
in interface PositionList<E>
public Position<E> last()
PositionList
last
in interface PositionList<E>
public Position<E> next(Position<E> pos) throws InvalidPositionException, BoundaryViolationException
PositionList
next
in interface PositionList<E>
InvalidPositionException
BoundaryViolationException
public java.lang.Iterable<Position<E>> positions()
PositionList
positions
in interface PositionList<E>
public Position<E> prev(Position<E> pos) throws InvalidPositionException, BoundaryViolationException
PositionList
prev
in interface PositionList<E>
InvalidPositionException
BoundaryViolationException
public E remove(int index) throws java.lang.IndexOutOfBoundsException
IndexList
public E remove(Position<E> pos) throws InvalidPositionException
PositionList
remove
in interface PositionList<E>
InvalidPositionException
public E removeFirst() throws EmptyDequeException
Deque
removeFirst
in interface Deque<E>
EmptyDequeException
public E removeLast() throws EmptyDequeException
Deque
removeLast
in interface Deque<E>
EmptyDequeException
public E set(int index, E element) throws java.lang.IndexOutOfBoundsException
IndexList
public E set(Position<E> pos, E element) throws InvalidPositionException
PositionList
set
in interface PositionList<E>
InvalidPositionException