All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jdsltools.examples.ArraySequence

java.lang.Object
   |
   +----jdsltools.examples.ArraySequence

public class ArraySequence
extends Object
implements Sequence
Interface to a sequential data structure that abstracts out the functionality of a linked list. Positions are stored linearly, and operations occur only relative to other Positions, except for method that allow finding the first and last Positions in the chain.

Version:
Mon Aug 11 20:22:42 EDT 1997 revised by RT Sun Aug 31 15:13:51 EDT 1997
Author:
Mark Handy

Constructor Index

 o ArraySequence()
Default constructor, it creates an array of positions with the default array length
 o ArraySequence(int)
Second constructor, it creates an array of positions with the given array length

Method Index

 o after(Position)
 o atRank(int)
 o before(Position)
 o elements()
 o first()
 o insertAfter(Position, Object)
Inserts the given element after the given Position, creating and returning a new Position (after the given one) at which to store the element.
 o insertAtRank(int, Object)
Inserts the given element at the given rank, creating and returning a new Position at which to store the element.
 o insertBefore(Position, Object)
Inserts the given element before the given Position, creating and returning a new Position (before the given one) at which to store the element.
 o insertFirst(Object)
Inserts the given element first in the sequence, creating and returning a new Position at which to store the element.
 o insertLast(Object)
Inserts the given element last in the sequence, creating and returning a new Position at which to store the element.
 o isEmpty()
 o last()
 o newContainer()
 o positions()
Enumeration is guaranteed to hold only Positions.
 o rankOf(Position)
Zero-based: rankOf ( first() ) == 0
 o remove(Position)
Removes and invalidates the given Position, returning the element stored at it.
 o removeAfter(Position)
Removes the given element after the given Position, invalidating the position and returning the element.
 o removeAtRank(int)
Removes the given element at the given rank, invalidating the position and returning the element
 o removeBefore(Position)
Removes the given element before the given Position, invalidating the position and returning the element.
 o removeFirst()
Removes the first position in the sequence, invalidating the Position.
 o removeLast()
Removes the last position in the sequence, invalidating the Position
 o replace(Position, Object)
Guaranteed to be a constant-time operation.
 o size()
 o swap(Position, Position)
Swaps the elements associated with the two Positions, leaving the Positions themselves "where" they were.

Constructors

 o ArraySequence
 public ArraySequence()
Default constructor, it creates an array of positions with the default array length

 o ArraySequence
 public ArraySequence(int length)
Second constructor, it creates an array of positions with the given array length

Methods

 o first
 public Position first() throws EmptyContainerException
Returns:
Position of first element in the sequence, if any
 o last
 public Position last() throws EmptyContainerException
Returns:
Position of last element in the sequence, if any
 o before
 public Position before(Position successor) throws InvalidPositionException, BoundaryViolationException
Parameters:
successor - A Position in this sequence
Returns:
The Position before the given Position
 o after
 public Position after(Position predecessor) throws InvalidPositionException, BoundaryViolationException
Parameters:
predecessor - A Position in this sequence
Returns:
The Position after the given Position
 o insertFirst
 public Position insertFirst(Object o) throws SequenceFullException
Inserts the given element first in the sequence, creating and returning a new Position at which to store the element.

Parameters:
o - Any java.lang.Object
Returns:
Position at which the inserted element is located
 o insertLast
 public Position insertLast(Object o) throws SequenceFullException
Inserts the given element last in the sequence, creating and returning a new Position at which to store the element.

Parameters:
o - Any java.lang.Object
Returns:
Position at which the inserted element is located
 o insertBefore
 public Position insertBefore(Position toBeAfter,
                              Object o) throws InvalidPositionException, SequenceFullException
Inserts the given element before the given Position, creating and returning a new Position (before the given one) at which to store the element.

Parameters:
successor - Position that will follow the inserted Position
o - Any java.lang.Object
Returns:
Position at which the inserted element is located
 o insertAfter
 public Position insertAfter(Position toBeBefore,
                             Object o) throws InvalidPositionException, SequenceFullException
Inserts the given element after the given Position, creating and returning a new Position (after the given one) at which to store the element.

Parameters:
predecessor - Position that will precede the inserted Position
o - Any java.lang.Object
Returns:
Position at which the inserted element is located
 o remove
 public Object remove(Position p) throws InvalidPositionException
Removes and invalidates the given Position, returning the element stored at it. The ranks of all following Positions decrease by 1.

Parameters:
p - A Position in this sequence
Returns:
Object formerly stored at Position p
 o removeFirst
 public Object removeFirst() throws EmptyContainerException
Removes the first position in the sequence, invalidating the Position.

Returns:
Object that was removed
 o removeLast
 public Object removeLast() throws EmptyContainerException
Removes the last position in the sequence, invalidating the Position

Returns:
Object that was removed
 o removeBefore
 public Object removeBefore(Position toBeAfter) throws InvalidPositionException
Removes the given element before the given Position, invalidating the position and returning the element.

Parameters:
successor - Position that will follow the removeed Position
Returns:
Object that was removed
 o removeAfter
 public Object removeAfter(Position toBeBefore) throws InvalidPositionException
Removes the given element after the given Position, invalidating the position and returning the element.

Parameters:
successor - Position that will follow the removeed Position
Returns:
Object that was removed
 o atRank
 public Position atRank(int rank) throws BoundaryViolationException
Parameters:
rank - An integer between 0 and N-1, where N is the size() of the sequence
Returns:
The Position at that rank
 o rankOf
 public int rankOf(Position p) throws InvalidPositionException
Zero-based: rankOf ( first() ) == 0

Parameters:
p - A Position in this sequence
Returns:
An integer representing the rank of the given Position in the sequence
 o insertAtRank
 public Position insertAtRank(int rank,
                              Object o) throws BoundaryViolationException, SequenceFullException
Inserts the given element at the given rank, creating and returning a new Position at which to store the element.

Parameters:
rank - Rank that Object element should have after it is inserted, where the first element in the sequence has rank 0. If the sequence is empty, inserting at rank 0 is acceptable, but inserting at any other rank gets a BoundaryViolationException (in general, inserting at rank==size() appends to the end). After the element is inserted, the rank of all subsequent elements is increased by 1.
o - Any java.lang.Object
Returns:
Position of that Object
 o removeAtRank
 public Object removeAtRank(int rank) throws EmptyContainerException, BoundaryViolationException
Removes the given element at the given rank, invalidating the position and returning the element

Parameters:
rank - Rank that Object element should have after it is removeed, where the first element in the sequence has rank 0. If the sequence is empty, removing should cause an EmptyContainerException to be thrown. Otherwise, if the sequence is not empty, then the rank must be between 0 and N-1 where N is size of the sequence.
Returns:
Object that was removed
 o positions
 public Enumeration positions() throws InvalidContainerException
Enumeration is guaranteed to hold only Positions. Some subinterfaces of PositionalContainer guarantee a certain order of the Positions in the Enumeration.

Returns:
Enumeration of all Positions in the container
 o replace
 public Object replace(Position p,
                       Object newElement) throws InvalidPositionException, InvalidContainerException
Guaranteed to be a constant-time operation.

Parameters:
p - Position at which replacement is to occur
newElement - Element now to be stored at Position p
Returns:
Old element, formerly stored at Position p
 o swap
 public void swap(Position a,
                  Position b) throws InvalidPositionException, InvalidContainerException
Swaps the elements associated with the two Positions, leaving the Positions themselves "where" they were. One of the Positions can be from another container, and the swap will be across containers.

 o size
 public int size()
Returns:
The number of elements in the sequence
 o isEmpty
 public boolean isEmpty()
Returns:
Whether the sequence is empty or not
 o elements
 public Enumeration elements() throws InvalidContainerException
 o newContainer
 public Container newContainer() throws InvalidContainerException

All Packages  Class Hierarchy  This Package  Previous  Next  Index