jdsl.core.api
Interface BookSequence


public abstract interface BookSequence
extends PositionalSequence, RankedSequence

Interface for a sequence, as it is described in the Goodrich-Tamassia book. It extends core.api.PositionalSequence and simple.api.RankedSequence.

Author:
Michael T. Goodrich, Roberto Tamassia
See Also:
Sequence, PositionalSequence, RankedSequence

Method Summary
 Position atRank(int rank)
          Return the position with the specified rank.
 Position insertAtRank(int rank, java.lang.Object newElement)
          Insert a new position into the sequence at the specified rank, and store the given element into the position.
 int rankOf(Position p)
          Return the rank of the specified position.
 
Methods inherited from interface jdsl.core.api.PositionalSequence
after, before, first, insertAfter, insertBefore, insertFirst, insertLast, last, remove, removeAfter, removeBefore, removeFirst, removeLast
 
Methods inherited from interface jdsl.simple.api.RankedSequence
elemAtRank, insertElemAtRank, removeElemAtRank, replaceElemAtRank
 
Methods inherited from interface jdsl.core.api.PositionalContainer
positions, replace, swap
 
Methods inherited from interface jdsl.core.api.Container
elements, newContainer
 

Method Detail

atRank

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

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.

rankOf

public 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.

insertAtRank

public Position insertAtRank(int rank,
                             java.lang.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.