jdsl.core.ref
Class NodeCircularSequence

java.lang.Object
  |
  +--jdsl.core.ref.AbstractPositionalContainer
        |
        +--jdsl.core.ref.AbstractCircularSequence
              |
              +--jdsl.core.ref.NodeCircularSequence
All Implemented Interfaces:
CircularSequence, Container, InspectableCircularSequence, InspectableContainer, InspectablePositionalContainer, PositionalContainer, java.io.Serializable

public class NodeCircularSequence
extends AbstractCircularSequence
implements java.io.Serializable

A CircularSequence implemented with a linked list whose nodes are Positions.

Version:
$Id: NodeCircularSequence.java,v 1.11 2000/07/25 17:32:51 lv Exp $
Author:
Mark Handy (mdh), Ryan Baker (rsb), Benoit Hudson (bh), Andrew Schwerin (schwerin), Keith Schmidt (kas), Luca Vismara (lv)
See Also:
Serialized Form

Constructor Summary
NodeCircularSequence()
          default Constructor for a NodeCircularSequence, the only one.
 
Method Summary
 Position after(Position pos)
          O(1)
 Position before(Position pos)
          O(1)
 jdsl.core.ref.NodeCircularSequence.NCSNode castPosition(Accessor pos)
          Convenience method to check if an Accessor can be used in this * Sequence.
 void checkEmpty()
          Simple convenience method to handle throwing an EmptyContainerException if the Sequence is empty.
 void checkValidity(CircularSequence cSeq)
          This is a convenience method that tests a CircularSequence for any condition which would cause invalidity, specifically : 1) it is null, 2) it is an incompatible type of CircularSequence, 3) the CircularSequence has been deliberately invalidated.
 boolean contains(Accessor acc)
          O(1)
 ObjectIterator elements()
          O(1) if the structure and elements do not change, O(N) otherwise.
 Position insertAfter(Position p, java.lang.Object element)
          O(1)
 Position insertBefore(Position p, java.lang.Object element)
          O(1)
 Position insertInitial(java.lang.Object element)
          O(1)
 boolean isEmpty()
          O(1)
 Container newContainer()
          O(1)
 PositionIterator positions()
          O(1) if the structure does not change, O(N) otherwise.
 java.lang.Object remove(Position pos)
          O(1)
 java.lang.Object replaceElement(Accessor acc, java.lang.Object newElt)
          O(1)
 void setStartingPosition(Position pos)
          O(1)
 int size()
          O(1)
 void splice(Position afterWhich, CircularSequence toMerge, Position newSuccessor)
          O(N)
 CircularSequence split(Position inNewA, Position inNewB)
          O(N)
 Position startingPosition()
          O(1)
 java.lang.String toString()
           
 
Methods inherited from class jdsl.core.ref.AbstractCircularSequence
removeAfter, removeBefore
 
Methods inherited from class jdsl.core.ref.AbstractPositionalContainer
swapElements
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jdsl.core.api.PositionalContainer
swapElements
 

Constructor Detail

NodeCircularSequence

public NodeCircularSequence()
default Constructor for a NodeCircularSequence, the only one.
Method Detail

newContainer

public Container newContainer()
O(1)
Following copied from interface: jdsl.core.api.Container
Returns:
A new, empty Container of the same class as this one.

contains

public boolean contains(Accessor acc)
O(1)
Following copied from interface: jdsl.core.api.InspectableContainer
Throws:
InvalidAccessorException - if a is null

positions

public PositionIterator positions()
O(1) if the structure does not change, O(N) otherwise.
Following copied from interface: jdsl.core.api.InspectablePositionalContainer
Returns:
A PositionIterator over all positions in the container

elements

public ObjectIterator elements()
O(1) if the structure and elements do not change, O(N) otherwise.
Following copied from interface: jdsl.core.api.InspectableContainer
Returns:
an iterator over all the elements stored in this container

startingPosition

public Position startingPosition()
O(1)
Following copied from interface: jdsl.core.api.InspectableCircularSequence
Returns:
An arbitrary position in the circular sequence
Throws:
EmptyContainerException - if there are no elements in this circular sequence

setStartingPosition

public void setStartingPosition(Position pos)
O(1)
Following copied from interface: jdsl.core.api.CircularSequence
Throws:
InvalidAccessorException - if p is not a valid position in this circular sequence
EmptyContainerException - if there are no elements in this circular sequence

replaceElement

public java.lang.Object replaceElement(Accessor acc,
                                       java.lang.Object newElt)
O(1)
Following copied from interface: jdsl.core.api.Container
Parameters:
a - Accessor in this container
newElement - to be stored at a
Returns:
old element, previously stored at a
Throws:
InvalidAccessorException - if a is null or does not belong to this container

isEmpty

public boolean isEmpty()
O(1)
Overrides:
isEmpty in class AbstractPositionalContainer
Following copied from interface: jdsl.core.api.InspectableContainer
Returns:
true if and only if the container is empty (holds no elements)
See Also:
InspectableBinaryTree

size

public int size()
O(1)
Following copied from interface: jdsl.core.api.InspectableContainer
Returns:
Number of elements stored by the container.

after

public Position after(Position pos)
O(1)
Following copied from interface: jdsl.core.api.InspectableCircularSequence
Parameters:
p - Position in this sequence
Returns:
Position of next element
Throws:
InvalidAccessorException - if p is not a valid position in this circular sequence.

before

public Position before(Position pos)
O(1)
Following copied from interface: jdsl.core.api.InspectableCircularSequence
Parameters:
p - Position in this sequence
Returns:
Position of previous element
Throws:
InvalidAccessorException - if p is not a valid position in this circular sequence.

insertBefore

public Position insertBefore(Position p,
                             java.lang.Object element)
                      throws InvalidAccessorException,
                             InvalidContainerException
O(1)
Following copied from interface: jdsl.core.api.CircularSequence
Parameters:
p - A position in this sequence
element - Any object
Returns:
Position of Object element, now stored before Position p (the parameter)
Throws:
InvalidAccessorException - if p is not a valid position in this circular sequence

insertAfter

public Position insertAfter(Position p,
                            java.lang.Object element)
                     throws InvalidAccessorException,
                            InvalidContainerException
O(1)
Following copied from interface: jdsl.core.api.CircularSequence
Parameters:
p - A position in this sequence
element - object
Returns:
Position of Object element, now stored after Position p (the parameter)
Throws:
InvalidAccessorException - if p is not a valid position in this circular sequence

insertInitial

public Position insertInitial(java.lang.Object element)
                       throws NonEmptyContainerException,
                              InvalidContainerException
O(1)
Following copied from interface: jdsl.core.api.CircularSequence
Parameters:
element - Any object
Returns:
Position of the inserted object
Throws:
NonEmptyContainerException - if there are no elements in this circular sequence.

remove

public java.lang.Object remove(Position pos)
                        throws InvalidAccessorException,
                               InvalidContainerException
O(1)
Following copied from interface: jdsl.core.api.CircularSequence
Parameters:
pos - the position to be removed
Returns:
the element formerly stored at pos
Throws:
InvalidAccessorException - if pos is not a valid position in the circular sequence.

split

public CircularSequence split(Position inNewA,
                              Position inNewB)
                       throws InvalidAccessorException,
                              InvalidContainerException
O(N)
Following copied from interface: jdsl.core.api.CircularSequence
Parameters:
inNewA - Start of sequence of Positions to be removed from this CircularSequence
inNewB - End of sequence of Positions to be removed from this CircularSequence
Returns:
A new CircularSequence holding inNewA, inNewB, and all the Positions after inNewA and before inNewB.
Throws:
InvalidAccessorException - if neither inNewA nor inNewB is a valid positions contained in this circular sequence.

splice

public void splice(Position afterWhich,
                   CircularSequence toMerge,
                   Position newSuccessor)
            throws InvalidAccessorException,
                   InvalidContainerException
O(N)
Following copied from interface: jdsl.core.api.CircularSequence
Parameters:
afterWhich - Position after which to break this CircularSequence
toMerge - CircularSequence to be spliced into this one
newSuccessor - Position from toMerge that will follow Position afterWhich in this CircularSequence
Throws:
InvalidAccessorException - if either afterWhich is not a valid position in this container or newSuccessor is not a valid position in toMerge
InvalidContainerException - if toMerge is null, or of the wrong implementation type, or equal to this circular sequence

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

checkValidity

public void checkValidity(CircularSequence cSeq)
                   throws InvalidContainerException
This is a convenience method that tests a CircularSequence for any condition which would cause invalidity, specifically : 1) it is null, 2) it is an incompatible type of CircularSequence, 3) the CircularSequence has been deliberately invalidated.
Throws:
InvalidContainerException -  

checkEmpty

public void checkEmpty()
                throws EmptyContainerException
Simple convenience method to handle throwing an EmptyContainerException if the Sequence is empty.
Throws:
EmptyContainerException -  

castPosition

public jdsl.core.ref.NodeCircularSequence.NCSNode castPosition(Accessor pos)
                                                        throws InvalidAccessorException
Convenience method to check if an Accessor can be used in this * Sequence. It tests against 1) null, 2) Proper type, 3) proper * containment. If all tests succed, it returns the Acessor, appropriately casted.
Throws:
InvalidAccessorException -