All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jdsl.core.ref.CircularNodeSequence

java.lang.Object
   |
   +----jdsl.core.ref.CircularNodeSequence

public class CircularNodeSequence
extends Object
implements CircularSequence
A CircularSequence implemented with nodes. This container cannot check container(), because container() is a linear time operation.

See Also:
CNSCircularNode

Constructor Index

 o CircularNodeSequence()
Constructs a new, empty sequence.

Method Index

 o after(Position)
Gets the Position after a given Position in this CircularSequence.
 o before(Position)
Gets the Position before a given Position in this CircularSequence
 o elements()
Returns an Enumeration of all the elements stored in this container.
 o insertAfter(Position, Object)
Inserts an element after a given position.
 o insertBefore(Position, Object)
Inserts an element before a given position.
 o insertInitial(Object)
Inserts an element into an empty CircularSequence.
 o isEmpty()
Tests if this container is empty.
 o newContainer()
Constructs a new CircularNodeSequence.
 o positions()
Returns all the positions in this container.
 o remove(Position)
Removes the specified position.
 o replace(Position, Object)
Replace the element at the specified position with a new element.
 o size()
Gets the number of elements in this container.
 o splice(Position, CircularSequence, Position)
Merges in another CircularNodeSequence after a given position.
 o split(Position, Position)
Snips out a chain of nodes from this CircularSequence, repairs this CircularSequence, and makes a new CircularSequence with the snipped-out nodes.
 o startingPosition()
Returns an arbitrary starting Position in this CircularSequence.
 o swap(Position, Position)
Swaps the elements at two specified positions.

Constructors

 o CircularNodeSequence
 public CircularNodeSequence()
Constructs a new, empty sequence.

Methods

 o before
 public Position before(Position successor) throws InvalidPositionException, InvalidContainerException
Gets the Position before a given Position in this CircularSequence

Parameters:
successor - Any Position in this Sequence.
Returns:
The Position before successor.
Throws: InvalidPositionException
if Position is invalid, from a different container, or null.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o after
 public Position after(Position predecessor) throws InvalidPositionException, InvalidContainerException
Gets the Position after a given Position in this CircularSequence.

Parameters:
predecessor - Any Position in this Sequence.
Returns:
The Position before predecessor.
Throws: InvalidPositionException
if Position is invalid, from a different container, or null.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o startingPosition
 public Position startingPosition() throws EmptyContainerException, InvalidContainerException
Returns an arbitrary starting Position in this CircularSequence. Note:There is no guarantee what position this method returns, nor is there any guarantee that it remains static.

Returns:
an arbitrary Position in this container.
Throws: EmptyContainerException
if this container is empty.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o insertBefore
 public Position insertBefore(Position p,
                              Object element) throws InvalidPositionException, InvalidContainerException
Inserts an element before a given position.

Parameters:
p - The Position to insert before.
element - The element to insert.
Returns:
the Position holding the new element.
Throws: InvalidPositionException
if Position is invalid, from a different container, or null.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o insertAfter
 public Position insertAfter(Position p,
                             Object element) throws InvalidPositionException, InvalidContainerException
Inserts an element after a given position.

Parameters:
p - The Position to insert after.
element - The element to insert.
Returns:
the Position holding the new element.
Throws: InvalidPositionException
if Position is invalid, from a different container, or null.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o insertInitial
 public Position insertInitial(Object element) throws InvalidContainerException
Inserts an element into an empty CircularSequence. The counterpart to startingPosition: intended for use only in an empty circular sequence, where there is no position before or after which you can insert.

Parameters:
element - Any Object
Returns:
Position of the object inserted
Throws: NotEmptyContainerException
if this sequence is not empty.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o remove
 public Object remove(Position p) throws EmptyContainerException, InvalidPositionException, InvalidContainerException
Removes the specified position.

Parameters:
p - The Position of the element after the element to be removed.
Returns:
The removed element.
Throws: EmptyContainerException
If there are no elements in this container.
Throws: InvalidPositionException
if p is null or not in this CircularSequence
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o split
 public CircularSequence split(Position inNewA,
                               Position inNewB) throws EmptyContainerException, InvalidPositionException, InvalidContainerException
Snips out a chain of nodes from this CircularSequence, repairs this CircularSequence, and makes a new CircularSequence with the snipped-out nodes. If inNewA==inNewB, only that one Position is removed from this CircularSequence. @param inNewA Start of sequence of Positions to be removed from this CircularSequence. This method takes constant time.

Parameters:
inNewA - Beginning of sequence of Positions to be removed from.
inNewB - End of sequence of Positions to be removed from this CircularSequence.
Returns:
A new CircularSequence holding inNewA, inNewB, and all the Positions between them
Throws: EmptyContainerException
if this container is empty.
Throws: InvalidPositionException
if inNewA or inNewB is null, from a different container, or of an incompatible type.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o splice
 public void splice(Position afterWhich,
                    CircularSequence toMerge,
                    Position newSuccessor) throws InvalidContainerException, InvalidPositionException, InvalidArgumentException
Merges in another CircularNodeSequence after a given position. That is, this CircularNodeSequence is snipped after a given Position, and the merged-in CircularSequence is snipped before a given Position. toMerge will be invalidated after this method returns. This method takes constant time.

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 from this CircularSequence.
Throws: InvalidContainerException
If this container is invalid or if toMerge is invalid or of an incompatible type.
Throws: InvalidArgumentException
if toMerge is the same container as splice is called on.
Throws: InvalidPositionException
if afterWhich or newSuccessor is either null, or of the wrong type.
See Also:
size
 o positions
 public Enumeration positions() throws InvalidContainerException
Returns all the positions in this container.

Returns:
An Enumeration of all positions in this container.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o replace
 public Object replace(Position p,
                       Object newElement) throws InvalidPositionException, InvalidContainerException
Replace the element at the specified position with a new element.

Parameters:
p - position at which the replacement is to occur
newElement - new element to be stored at position p
Returns:
old element formerly stored at position p
Throws: InvalidPositionException
is thrown if the specified position does not belong to the container or if the position is null.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o swap
 public void swap(Position a,
                  Position b) throws InvalidPositionException, InvalidContainerException
Swaps the elements at two specified positions.

Parameters:
p - first position participating in the swap.
q - second position participating in the swap.
Throws: InvalidPositionException
if thrown if on or both of the specified Positions does not belong to this implementation of Container, or if either Position is null.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o size
 public int size() throws InvalidContainerException
Gets the number of elements in this container. Each element is counted a number of times according to its multiplicity. This is a linear time operation.

Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o isEmpty
 public boolean isEmpty() throws InvalidContainerException
Tests if this container is empty.

Returns:
true if this container is empty, false otherwise.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o newContainer
 public Container newContainer()
Constructs a new CircularNodeSequence.

Returns:
a new, empty container identical to this one.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice
 o elements
 public Enumeration elements()
Returns an Enumeration of all the elements stored in this container. Duplicated elements appear as many times as they are in the container. Elements are returned in the order they are inserted.

Returns:
An Enumeration of all elements in the container.
Throws: InvalidContainerException
if this container has been invalidated.
See Also:
splice

All Packages  Class Hierarchy  This Package  Previous  Next  Index