All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface jdsl.core.api.Sequence

public interface Sequence
extends PositionalSequence
Interface for a Sequence. A sequence is a positional container whose positions are linearly arranged and that supports both position-based and rank-based operations. It is a generalization of basic data structures such as stacks, queues, deques, arrays, vectors, and linked lists.

This interface defines Sequence by extending PositionalSequence with the rank-based methods rankOf, atRank and insertAtRank. However, it does not extend simple.api.RankedSequence as BookSequence does.

The enumerations returned by methods Container.elements() and PositionalContainer.positions() are guaranteed to give the elements/position in the same order as they are arranged in the sequence.

See Also:
PositionalSequence, PositionalContainer, BookSequence, RankedSequence

Method Index

 o atRank(int)
Return the position with the specified rank.
 o insertAtRank(int, Object)
Insert a new position into the sequence at the specified rank, and store the given element into the position.
 o rankOf(Position)
Return the rank of the specified position.
 o removeAtRank(int)
Remove the position at the designated rank

Methods

 o atRank
 public abstract Position atRank(int rank) throws BoundaryViolationException
Return the position with the specified rank.

Note that the first position of a sequence has rank 0.

A BoundaryViolationException is thrown if rank < 0 or if rank > n - 1, where n is the size (number of positions) of the sequence.

Parameters:
rank - integer specifying the rank.
Returns:
position at the specified rank.
 o rankOf
 public abstract int rankOf(Position p) throws InvalidPositionException
Return the rank of the specified position. Note that the first position has rank 0, and the last position has rank n - 1, where n is the size (number of positions) of the sequence.

Parameters:
p - position
Returns:
rank of the specified position in the sequence.
 o insertAtRank
 public abstract Position insertAtRank(int rank,
                                       Object newElement) throws BoundaryViolationException
Insert a new position into the sequence at the specified rank, and store the given element into the position. Return the newly created position.

Parameters:
rank - rank that the new position should have. For example, if rank = 0, the insertion is done at the beginning, and if rank = n, where n is the old size (number of positions) of the sequence, the insertion is done at the end.
newElement - new element to be inserted.
Returns:
newly created position.
 o removeAtRank
 public abstract Object removeAtRank(int rank) throws BoundaryViolationException
Remove the position at the designated rank

Parameters:
rank - Index of the position to be removed
Returns:
Element formerly stored at the position removed

All Packages  Class Hierarchy  This Package  Previous  Next  Index