|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<E>
ch.bfh.algo.core.sequence.GenericLinkedSequence<E,P>
public class GenericLinkedSequence<E,P extends GenericLinkedPosition<E,P>>
Field Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
GenericLinkedSequence(SequenceFactory<P> factory)
|
Method Summary | |
---|---|
P |
after(P position)
|
P |
after(Position<?> position)
returns the Position that is placed after position
in the sequence |
P |
before(P position)
|
P |
before(Position<?> position)
This method returns the position that is placed before the one given as argument in the sequence. |
E |
delete(P position)
|
E |
delete(Position<?> position)
Deletes the specified position and returns
the corresponding element. |
E |
element(P position)
|
E |
element(Position<?> position)
This Container determines if
it contains the position and -- if it
is found -- the corresponding element is returned. |
boolean |
encloses(P position)
|
boolean |
encloses(Position<?> position)
Tests if the specified position is
contained in this ch.bfh.algo.Container . |
P |
first()
The method first() returns the
Position containing the first element of the
sequence. |
protected P |
head()
|
P |
insert(E element)
Inserts the specified element into this
Container . |
protected P |
insert(E element,
P newPosition)
|
P |
insertAfter(P position,
E element)
|
P |
insertAfter(Position<?> position,
E element)
This method insert element in the sequence. |
P |
insertBefore(P position,
E element)
|
P |
insertBefore(Position<?> position,
E element)
This method insert element in the sequence. |
protected P |
insertBetween(P previous,
P next,
E element)
|
protected P |
insertBetween(P previous,
P next,
E element,
P position)
|
P |
last()
The method last() returns the
Position containing the last element of the
sequence. |
ListIterator<E> |
listIterator(int index)
|
P |
position(int rank)
The position method returns the
Position corresponding to a given
rank . |
PositionIterator<E,P> |
positionIterator()
An Iterator over all positions is created. |
PositionListIterator<E,P> |
positionListIterator()
The positionListIterator method creates and return a ListIterator for the Position s contained in the sequence. |
PositionListIterator<E,P> |
positionListIterator(int rank)
The positionListIterator method creates and return a ListIterator for the Position s contained in the sequence. |
int |
rank(P position)
|
int |
rank(Position<?> position)
The rank method returns the rank of the given
position , analogous to the method indexOf in the List interface. |
E |
replace(P position,
E element)
|
E |
replace(Position<?> position,
E element)
Replaces the element at the specified position with
the specified element . |
int |
size()
|
void |
swap(Position<?> position0,
Position<?> position1)
|
void |
swap(P position0,
P position1)
|
protected P |
tail()
|
protected void |
validate(P position)
|
Methods inherited from class java.util.AbstractSequentialList |
---|
add, addAll, get, iterator, remove, set |
Methods inherited from class java.util.AbstractList |
---|
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, remove, remove, removeAll, retainAll, set, subList, toArray, toArray |
Constructor Detail |
---|
public GenericLinkedSequence(SequenceFactory<P> factory)
Method Detail |
---|
public int size()
size
in interface Collection<E>
size
in interface List<E>
size
in class AbstractCollection<E>
protected P head()
protected P tail()
public P first() throws EmptySequenceException
Sequence
first()
returns the
Position
containing the first element of the
sequence.
It throws an EmptySequenceException
if the
sequence is empty.
first
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
first
in interface Sequence<E>
Position
EmptySequenceException
- if the sequence is empty.public P last() throws EmptySequenceException
Sequence
last()
returns the
Position
containing the last element of the
sequence.
It throws an EmptySequenceException
if the
sequence is empty.
last
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
last
in interface Sequence<E>
Position
in the sequence.
EmptySequenceException
- if the sequence is empty.public P before(Position<?> position) throws InvalidAccessorException, BoundaryViolationException
Sequence
before
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
before
in interface Sequence<E>
position
- Position
Position
that is before the given one
InvalidAccessorException
- if position
does not belong to this sequence.
BoundaryViolationException
- if the given position is the
first one (there is nothing before it in this case).public P before(P position) throws InvalidAccessorException, BoundaryViolationException
InvalidAccessorException
BoundaryViolationException
public P after(Position<?> position) throws InvalidAccessorException, BoundaryViolationException
Sequence
position
in the sequence
after
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
after
in interface Sequence<E>
position
- a Position<?>
position
InvalidAccessorException
- if position
does not belong to this sequence.
BoundaryViolationException
- if the given position is the
last one (there is nothing after it in this case).public P after(P position) throws InvalidAccessorException, BoundaryViolationException
InvalidAccessorException
BoundaryViolationException
protected P insertBetween(P previous, P next, E element)
protected P insertBetween(P previous, P next, E element, P position)
public P insertBefore(Position<?> position, E element) throws InvalidAccessorException
Sequence
element
in the sequence. It
creates a new Position
that is inserted before
position
. The new position contains the new
element
and is returned by the method.
insertBefore
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
insertBefore
in interface Sequence<E>
position
- a Position<?>
Position
containing element
InvalidAccessorException
- if position
does
not belong to this sequence.public P insertBefore(P position, E element) throws InvalidAccessorException
InvalidAccessorException
public P insertAfter(Position<?> position, E element) throws InvalidAccessorException
Sequence
element
in the sequence. It
creates a new Position
that is inserted after
position
. The new position contains the new
element
and is returned by the method.
insertAfter
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
insertAfter
in interface Sequence<E>
position
- a Position<?>
Position
containing element
InvalidAccessorException
- if position
does
not belong to this sequence.public P insertAfter(P position, E element) throws InvalidAccessorException
InvalidAccessorException
public P insert(E element)
Container
Inserts the specified element
into this
Container
.
insert
in interface Container<E>
insert
in interface GenericContainer<E,P extends GenericLinkedPosition<E,P>>
element
- The element
to be inserted into this
Container
.
Position
of the inserted
element
.protected P insert(E element, P newPosition)
public E replace(Position<?> position, E element) throws InvalidAccessorException
Container
Replaces the element at the specified position
with
the specified element
.
replace
in interface Container<E>
position
- The Position
where the replacement is
carried out.element
- The new element
at the specified
position
.
InvalidAccessorException
- if the position
does not belong to this Container
public E replace(P position, E element) throws InvalidAccessorException
InvalidAccessorException
public E delete(Position<?> position) throws InvalidAccessorException
Container
Deletes the specified position
and returns
the corresponding element.
delete
in interface Container<E>
position
- The Position
to be deleted
position
being deleted
InvalidAccessorException
- if the position
does not belong to this Container
public E delete(P position) throws InvalidAccessorException
InvalidAccessorException
public void swap(Position<?> position0, Position<?> position1) throws InvalidAccessorException
swap
in interface Container<E>
InvalidAccessorException
public void swap(P position0, P position1) throws InvalidAccessorException
InvalidAccessorException
public boolean encloses(Position<?> position)
Container
Tests if the specified position
is
contained in this ch.bfh.algo.Container
.
encloses
in interface Container<E>
position
- This Container
determines if
it contains the position
.
position
is contained in
this Container
, false otherwisepublic boolean encloses(P position)
public E element(Position<?> position)
Container
This Container
determines if
it contains the position
and -- if it
is found -- the corresponding element is returned.
element
in interface Container<E>
position
- The position
from which the
element is to be returned.
position
public E element(P position)
protected void validate(P position) throws InvalidAccessorException
InvalidAccessorException
public P position(int rank) throws IndexOutOfBoundsException
Sequence
position
method returns the
Position
corresponding to a given
rank
.
This method is a bridge between the methods of the
List
interface and the ones of the
Sequence
.
position
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
position
in interface Sequence<E>
rank
- an int
that denotes the index of the researched position in the sequence.
Position
containing element
IndexOutOfBoundsException
- if rank
is smaller than 0 or larger than or equal to the number of elements in the sequence.public int rank(Position<?> position)
Sequence
rank
method returns the rank of the given
position
, analogous to the method indexOf
in the List
interface.
This method is a bridge between the methods of the
List
interface and the ones of the
Sequence
.
rank
in interface Sequence<E>
position
- a Position<?>
of the sequence
position
(i.e. its index in the sequence).
If position
is not in the sequence then its rank is -1
.public int rank(P position)
public PositionListIterator<E,P> positionListIterator(int rank)
Sequence
positionListIterator
method creates and return a ListIterator
for the Position
s contained in the sequence. This iterator is initially placed at the rank given as a parmeter
This method gives the possibility to iterate over all the
Positions in the sequence.
positionListIterator
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
positionListIterator
in interface Sequence<E>
rank
- an int
denoting the initial position
of the pointer of the iterator.
ListIterator<Position<E>>
of
all the Position
s in the sequence.public PositionListIterator<E,P> positionListIterator()
Sequence
positionListIterator
method creates and return a ListIterator
for the Position
s contained in the sequence.
This method gives the possibility to iterate over all the
Positions in the sequence.
positionListIterator
in interface GenericSequence<E,P extends GenericLinkedPosition<E,P>>
positionListIterator
in interface Sequence<E>
ListIterator<Position<E>>
of all the Position
s in the sequence.public ListIterator<E> listIterator(int index) throws IndexOutOfBoundsException
listIterator
in interface List<E>
listIterator
in class AbstractSequentialList<E>
IndexOutOfBoundsException
public PositionIterator<E,P> positionIterator()
Container
An Iterator
over all positions is created.
positionIterator
in interface Container<E>
positionIterator
in interface GenericContainer<E,P extends GenericLinkedPosition<E,P>>
ch.bfh.algo.Container
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |