|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Sequence<E>
The Sequence
interface is used to store elements in a flat
datastructure. Its implementation can be done using a doubly linked
list or an array.
In the following example, we use two positions to visit a sequence
Position<Integer> pos1 = seq.first(); while(pos1!=seq.last()){ pos2=seq.after(pos1); if( pos1.element()> pos2.element()){ Integer tmp = pos1.element(); seq.replace(pos1,pos2.element()); seq.replace(pos2,tmp); } }But since a sequence is also a
java.util.List
, one
can use the programs written for such datastructures. We can for
instance use the foreach loops:
Sequence<String> seq = ...; for(String s : seq){ System.out.prinln(s); }
Method Summary | |
---|---|
Position<E> |
after(Position<?> position)
returns the Position that is placed after position
in the sequence |
Position<E> |
before(Position<?> position)
This method returns the position that is placed before the one given as argument in the sequence. |
Position<E> |
first()
The method first() returns the
Position containing the first element of the
sequence. |
Position<E> |
insertAfter(Position<?> position,
E element)
This method insert element in the sequence. |
Position<E> |
insertBefore(Position<?> position,
E element)
This method insert element in the sequence. |
Position<E> |
last()
The method last() returns the
Position containing the last element of the
sequence. |
Position<E> |
position(int rank)
The position method returns the
Position corresponding to a given
rank . |
ListIterator<Position<E>> |
positionListIterator()
The positionListIterator method creates and return a ListIterator for the Position s contained in the sequence. |
ListIterator<Position<E>> |
positionListIterator(int rank)
The positionListIterator method creates and return a ListIterator for the Position s contained in the sequence. |
int |
rank(Position<?> position)
The rank method returns the rank of the given
position , analogous to the method indexOf in the List interface. |
Methods inherited from interface ch.bfh.algo.Container |
---|
delete, element, encloses, insert, positionIterator, replace, swap |
Methods inherited from interface java.util.List |
---|
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray |
Method Detail |
---|
Position<E> first() throws EmptySequenceException
first()
returns the
Position
containing the first element of the
sequence.
It throws an EmptySequenceException
if the
sequence is empty.
Position
EmptySequenceException
- if the sequence is empty.Position<E> last() throws EmptySequenceException
last()
returns the
Position
containing the last element of the
sequence.
It throws an EmptySequenceException
if the
sequence is empty.
Position
in the sequence.
EmptySequenceException
- if the sequence is empty.Position<E> before(Position<?> position) throws InvalidAccessorException, BoundaryViolationException
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).Position<E> after(Position<?> position) throws InvalidAccessorException, BoundaryViolationException
position
in the sequence
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).Position<E> insertBefore(Position<?> position, E element) throws InvalidAccessorException
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.
position
- a Position<?>
Position
containing element
InvalidAccessorException
- if position
does
not belong to this sequence.Position<E> insertAfter(Position<?> position, E element) throws InvalidAccessorException
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.
position
- a Position<?>
Position
containing element
InvalidAccessorException
- if position
does
not belong to this sequence.Position<E> position(int rank) throws IndexOutOfBoundsException
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
.
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.int rank(Position<?> position)
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
.
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
.ListIterator<Position<E>> positionListIterator()
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.
ListIterator<Position<E>>
of all the Position
s in the sequence.ListIterator<Position<E>> positionListIterator(int rank) throws IndexOutOfBoundsException
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.
rank
- an int
denoting the initial position
of the pointer of the iterator.
ListIterator<Position<E>>
of
all the Position
s in the sequence.
IndexOutOfBoundsException
- if rank
is smaller than 0 or larger than the number of elements in the sequence.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |