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
-
ArraySequence()
- Default constructor, it creates an array of positions with the
default array length
-
ArraySequence(int)
- Second constructor, it creates an array of positions with the
given array length
-
after(Position)
-
-
atRank(int)
-
-
before(Position)
-
-
elements()
-
-
first()
-
-
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.
-
insertAtRank(int, Object)
-
Inserts the given element at the given rank, creating and returning
a new Position at which to store the element.
-
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.
-
insertFirst(Object)
-
Inserts the given element first in the sequence, creating and
returning a new Position at which to store the element.
-
insertLast(Object)
-
Inserts the given element last in the sequence, creating and
returning a new Position at which to store the element.
-
isEmpty()
-
-
last()
-
-
newContainer()
-
-
positions()
-
Enumeration is guaranteed to hold only Positions.
-
rankOf(Position)
-
Zero-based: rankOf ( first() ) == 0
-
remove(Position)
-
Removes and invalidates the given Position, returning the element
stored at it.
-
removeAfter(Position)
-
Removes the given element after the given Position, invalidating
the position and returning the element.
-
removeAtRank(int)
-
Removes the given element at the given rank, invalidating
the position and returning the element
-
removeBefore(Position)
-
Removes the given element before the given Position, invalidating
the position and returning the element.
-
removeFirst()
-
Removes the first position in the sequence, invalidating
the Position.
-
removeLast()
-
Removes the last position in the sequence, invalidating
the Position
-
replace(Position, Object)
-
Guaranteed to be a constant-time operation.
-
size()
-
-
swap(Position, Position)
-
Swaps the elements associated with the two Positions,
leaving the Positions themselves "where" they were.
ArraySequence
public ArraySequence()
- Default constructor, it creates an array of positions with the
default array length
ArraySequence
public ArraySequence(int length)
- Second constructor, it creates an array of positions with the
given array length
first
public Position first() throws EmptyContainerException
- Returns:
- Position of first element in the sequence, if any
last
public Position last() throws EmptyContainerException
- Returns:
- Position of last element in the sequence, if any
before
public Position before(Position successor) throws InvalidPositionException, BoundaryViolationException
- Parameters:
- successor - A Position in this sequence
- Returns:
- The Position before the given Position
after
public Position after(Position predecessor) throws InvalidPositionException, BoundaryViolationException
- Parameters:
- predecessor - A Position in this sequence
- Returns:
- The Position after the given Position
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
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
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
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
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
removeFirst
public Object removeFirst() throws EmptyContainerException
- Removes the first position in the sequence, invalidating
the Position.
- Returns:
- Object that was removed
removeLast
public Object removeLast() throws EmptyContainerException
- Removes the last position in the sequence, invalidating
the Position
- Returns:
- Object that was removed
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
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
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
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
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
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
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
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
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.
size
public int size()
- Returns:
- The number of elements in the sequence
isEmpty
public boolean isEmpty()
- Returns:
- Whether the sequence is empty or not
elements
public Enumeration elements() throws InvalidContainerException
newContainer
public Container newContainer() throws InvalidContainerException
All Packages Class Hierarchy This Package Previous Next Index