public class LinkedPositionalList<E> extends Object implements PositionalList<E>
Constructor and Description |
---|
LinkedPositionalList()
Constructs a new empty list.
|
Modifier and Type | Method and Description |
---|---|
Position<E> |
addAfter(Position<E> p,
E e)
Inserts an element immediately after the given Position.
|
Position<E> |
addBefore(Position<E> p,
E e)
Inserts an element immediately before the given Position.
|
Position<E> |
addFirst(E e)
Inserts an element at the front of the list.
|
Position<E> |
addLast(E e)
Inserts an element at the back of the list.
|
Position<E> |
after(Position<E> p)
Returns the Position immediately after Position p.
|
Position<E> |
before(Position<E> p)
Returns the Position immediately before Position p.
|
Position<E> |
first()
Returns the first Position in the list.
|
boolean |
isEmpty()
Tests whether the list is empty.
|
Iterator<E> |
iterator()
Returns an iterator of the elements stored in the list.
|
Position<E> |
last()
Returns the last Position in the list.
|
static void |
main(String[] args) |
Iterable<Position<E>> |
positions()
Returns an iterable representation of the list's positions.
|
E |
remove(Position<E> p)
Removes the element stored at the given Position and returns it.
|
E |
set(Position<E> p,
E e)
Replaces the element stored at the given Position and returns the replaced element.
|
int |
size()
Returns the number of elements in the list.
|
String |
toString()
Produces a string representation of the contents of the list.
|
public int size()
size
in interface PositionalList<E>
public boolean isEmpty()
isEmpty
in interface PositionalList<E>
public Position<E> first()
first
in interface PositionalList<E>
public Position<E> last()
last
in interface PositionalList<E>
public Position<E> before(Position<E> p) throws IllegalArgumentException
before
in interface PositionalList<E>
p
- a Position of the listIllegalArgumentException
- if p is not a valid position for this listpublic Position<E> after(Position<E> p) throws IllegalArgumentException
after
in interface PositionalList<E>
p
- a Position of the listIllegalArgumentException
- if p is not a valid position for this listpublic Position<E> addFirst(E e)
addFirst
in interface PositionalList<E>
e
- the new elementpublic Position<E> addLast(E e)
addLast
in interface PositionalList<E>
e
- the new elementpublic Position<E> addBefore(Position<E> p, E e) throws IllegalArgumentException
addBefore
in interface PositionalList<E>
p
- the Position before which the insertion takes placee
- the new elementIllegalArgumentException
- if p is not a valid position for this listpublic Position<E> addAfter(Position<E> p, E e) throws IllegalArgumentException
addAfter
in interface PositionalList<E>
p
- the Position after which the insertion takes placee
- the new elementIllegalArgumentException
- if p is not a valid position for this listpublic E set(Position<E> p, E e) throws IllegalArgumentException
set
in interface PositionalList<E>
p
- the Position of the element to be replacede
- the new elementIllegalArgumentException
- if p is not a valid position for this listpublic E remove(Position<E> p) throws IllegalArgumentException
remove
in interface PositionalList<E>
p
- the Position of the element to be removedIllegalArgumentException
- if p is not a valid position for this listpublic Iterable<Position<E>> positions()
positions
in interface PositionalList<E>
public String toString()
public static void main(String[] args)