jdsl.core.ref
Class NodeSequence

java.lang.Object
  |
  +--jdsl.core.ref.NodeSequence
Direct Known Subclasses:
DumbEnumerationNodeSequence, FastEnumerationNodeSequence

public class NodeSequence
extends java.lang.Object
implements Sequence

This class implements the sequence interface using a double-linked list of nodes.

Author:
Natasha Gelfand

Constructor Summary
NodeSequence()
           
 
Method Summary
 Position after(Position p)
          Return position after this one
 Position atRank(int rank)
          Return the position at the given rank
 Position before(Position p)
          Return position before this one
 java.util.Enumeration elements()
          Returns an enumeration of the elements in this sequence
 Position first()
          Return the first position in the sequence
 Position insertAfter(Position p, java.lang.Object element)
          Create a new position with the given element and insert it after the given position, returning a reference the new position
 Position insertAtRank(int rank, java.lang.Object element)
          Create a new position with the given element and insert it at the given rank.
 Position insertBefore(Position p, java.lang.Object element)
          Create a new position with the given element and insert it before the given position, returning a reference to the new node
 Position insertFirst(java.lang.Object element)
          Create a new position with the given element and insert it as the first position in the sequence.
 Position insertLast(java.lang.Object element)
          Create a new position with the given element and insert it as the last position in the sequence.
 boolean isEmpty()
          Return true iff the sequence is empty
 Position last()
          Return the last position in the sequence
 Container newContainer()
          Make a new container of this type
 java.util.Enumeration positions()
          Returns an enumeration of the positions in this sequence
 int rankOf(Position p)
          Return the rank of the given position
 java.lang.Object remove(Position p)
          Remove this position from the sequence
 java.lang.Object removeAfter(Position p)
          Removes after p
 java.lang.Object removeAtRank(int i)
          Removes the position at rank i
 java.lang.Object removeBefore(Position p)
          Removes before p
 java.lang.Object removeFirst()
          Removes the first position
 java.lang.Object removeLast()
          Removes the last position
 java.lang.Object replace(Position p, java.lang.Object element)
          Replace the element of the given position with the new element and return the old value of element
 int size()
          Return the number of elements in the sequence
 void swap(Position a, Position b)
          Swap elements of two positions
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeSequence

public NodeSequence()
Method Detail

first

public Position first()
               throws EmptyContainerException
Return the first position in the sequence

last

public Position last()
              throws EmptyContainerException
Return the last position in the sequence

atRank

public Position atRank(int rank)
                throws BoundaryViolationException
Return the position at the given rank
Specified by:
atRank in interface Sequence

before

public Position before(Position p)
                throws InvalidPositionException,
                       BoundaryViolationException
Return position before this one

after

public Position after(Position p)
               throws InvalidPositionException,
                      BoundaryViolationException
Return position after this one

rankOf

public int rankOf(Position p)
           throws InvalidPositionException
Return the rank of the given position
Specified by:
rankOf in interface Sequence

insertBefore

public Position insertBefore(Position p,
                             java.lang.Object element)
                      throws InvalidPositionException
Create a new position with the given element and insert it before the given position, returning a reference to the new node

insertAfter

public Position insertAfter(Position p,
                            java.lang.Object element)
                     throws InvalidPositionException
Create a new position with the given element and insert it after the given position, returning a reference the new position

insertFirst

public Position insertFirst(java.lang.Object element)
Create a new position with the given element and insert it as the first position in the sequence.

insertLast

public Position insertLast(java.lang.Object element)
Create a new position with the given element and insert it as the last position in the sequence.

insertAtRank

public Position insertAtRank(int rank,
                             java.lang.Object element)
                      throws BoundaryViolationException
Create a new position with the given element and insert it at the given rank.
Specified by:
insertAtRank in interface Sequence

remove

public java.lang.Object remove(Position p)
                        throws InvalidPositionException
Remove this position from the sequence

size

public int size()
Return the number of elements in the sequence

isEmpty

public boolean isEmpty()
Return true iff the sequence is empty

newContainer

public Container newContainer()
Make a new container of this type

elements

public java.util.Enumeration elements()
Returns an enumeration of the elements in this sequence

positions

public java.util.Enumeration positions()
Returns an enumeration of the positions in this sequence

replace

public java.lang.Object replace(Position p,
                                java.lang.Object element)
                         throws InvalidPositionException
Replace the element of the given position with the new element and return the old value of element

swap

public void swap(Position a,
                 Position b)
          throws InvalidPositionException
Swap elements of two positions

removeAtRank

public java.lang.Object removeAtRank(int i)
Removes the position at rank i
Specified by:
removeAtRank in interface Sequence

removeBefore

public java.lang.Object removeBefore(Position p)
Removes before p

removeAfter

public java.lang.Object removeAfter(Position p)
Removes after p

removeFirst

public java.lang.Object removeFirst()
Removes the first position

removeLast

public java.lang.Object removeLast()
Removes the last position