All Packages Class Hierarchy This Package Previous Next Index
Class jdsl.core.ref.VectorSequence
java.lang.Object
|
+----jdsl.core.ref.VectorSequence
- public class VectorSequence
- extends Object
- implements Sequence
A Sequence implemented with a java.util.Vector. You will probably need to
read it to understand the operation and the time complexities of this class.
In particular, since Vector allocates a new array and copies the old array
into the new one whenever it runs out of space, calls like
vec_.insertElementAt(object,index) are NOT constant-time operations.
- Version:
- $Revision: 1.4 $, $Date: 1998/07/13 20:03:52 $
- Author:
- Ryan Shaun Baker, Benoit Hudson (bh), Mike Boilen (mgb)
-
VectorSequence()
- Constructs a new Sequence with an initial capacity of 4.
-
VectorSequence(int)
- Constructs a new sequence with an underlying Vector of size
initialCapacity
.
-
VectorSequence(int, int)
- Constructs a new sequence with an underlying Vector of size
initialCapacity
.
-
after(Position)
-
Gets the position after a position.
-
atRank(int)
-
-
before(Position)
-
Gets the position before a position.
-
castToIndexedPosition(Position)
- For the following routine, we pass back an InvalidPositionException,
which will be more informational and useful to the programmer than a
CCE.
-
checkEmpty()
-
-
checkRank(int)
-
-
decSize()
-
Provided for remove, which needs to decrease the size by one
-
elements()
-
Gets all the elements in this container, in order.
-
first()
-
Gets the first position of this sequence.
-
incSize()
-
Provided for insertAtRank, which needs to up the size by one
-
insertAfter(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.
-
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()
- Tests if the container is empty.
-
last()
-
Gets the last position of this sequence.
-
newContainer()
- Returns a new, empty VectorSequence.
-
positions()
-
Gets all the
Positions
in this container, in order.
-
rankOf(Position)
-
Gets the rank of a position.
-
remove(Position)
-
Removes and invalidates the given Position, returning the element
stored at it.
-
removeAfter(Position)
-
-
removeAtRank(int)
- Removes an element at a particular rank.
-
removeBefore(Position)
-
-
removeFirst()
- Removes the first element of the sequence.
-
removeLast()
- Removes the last element of the sequence.
-
replace(Position, Object)
-
Replaces the element at a position with a new element.
-
size()
-
Gets the size of this container.
-
swap(Position, Position)
-
Swaps the elements associated with the two Positions, leaving the
Positions themselves "where" they were.
-
updateIndicesStartingAt(int)
-
VectorSequence
public VectorSequence()
- Constructs a new Sequence with an initial capacity of 4.
VectorSequence
public VectorSequence(int initialCapacity)
- Constructs a new sequence with an underlying Vector of size
initialCapacity
.
VectorSequence
public VectorSequence(int initialCapacity,
int capacityIncrement)
- Constructs a new sequence with an underlying Vector of size
initialCapacity
. Every time the Vector resizes, it
increases by capicityIncrement
.
newContainer
public Container newContainer()
- Returns a new, empty VectorSequence.
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
insertAtRank
public Position insertAtRank(int rank,
Object o) throws BoundaryViolationException
- Inserts the given element at the given rank, creating and returning
a new Position at which to store the element.
- Parameters:
- rank - Integer representing the rank of the newly inserted
element after insertion is completely (i.e., the ranks of all
following positions will increase by 1)
- 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
removeAfter
public Object removeAfter(Position p)
removeBefore
public Object removeBefore(Position p)
incSize
protected void incSize()
- Provided for insertAtRank, which needs to up the size by one
decSize
protected void decSize()
- Provided for remove, which needs to decrease the size by one
first
public Position first() throws EmptyContainerException
- Gets the first position of this sequence.
- Returns:
-
Position
for first element in the sequence, if any
- Throws: EmptyContainerException
- if the container is empty
last
public Position last()
- Gets the last position of this sequence.
- Returns:
- Position for last element in the sequence, if any
- Throws: EmptyContainerException
- if the container is empty
before
public Position before(Position successor) throws InvalidPositionException, BoundaryViolationException
- Gets the position before a position.
- Parameters:
- successor - A
Position
in this sequence
- Returns:
- The
Position
before the given Position
- Throws: InvalidPositionException
- if
successor
is not from
this container.
- Throws: BoundaryViolationException
- if
successor
is the first
position of this sequence.
after
public Position after(Position successor) throws InvalidPositionException, BoundaryViolationException
- Gets the position after a position.
- Parameters:
- predecessor - A
Position
in this sequence
- Returns:
- The
Position
after the given Position
rankOf
public int rankOf(Position p) throws InvalidPositionException
- Gets the rank of a position. Note that this is 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
- Throws: InvalidPositionException
- if
p
is null
* or not from this container.
insertFirst
public Position insertFirst(Object o)
- 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)
- 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 successor,
Object o) throws InvalidPositionException, BoundaryViolationException
- 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
- Throws: InvalidPositionException
- if
predecessor
is
null
not from this container.
- Throws: BoundaryViolationException
- if
predecessor
is the
last position of this sequence.
insertAfter
public Position insertAfter(Position predecessor,
Object o) throws InvalidPositionException, BoundaryViolationException
- 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
- Throws: InvalidPositionException
- if
predecessor
is
null
not from this container.
- Throws: BoundaryViolationException
- if
predecessor
is the
last position of this sequence.
removeLast
public Object removeLast() throws EmptyContainerException
- Removes the last element of the sequence.
- Returns:
- The last element of the sequence.
- Throws: EmptyContainerException
- if the container is empty.
removeFirst
public Object removeFirst() throws EmptyContainerException
- Removes the first element of the sequence.
- Returns:
- The first element of the sequence.
- Throws: EmptyContainerException
- if the container is empty.
removeAtRank
public Object removeAtRank(int i) throws EmptyContainerException, BoundaryViolationException
- Removes an element at a particular rank.
- Parameters:
- i - The rank of the element to remove.
- Returns:
- The element at rank
i
- Throws: EmptyContainerException
- if the container is empty.
- Throws: BoundaryViolationException
- if
i
is out of
bounds.
positions
public Enumeration positions()
- Gets all the
Positions
in this container, in order.
- Returns:
- An
Enumeration
of all Positions
in the
container
replace
public Object replace(Position p,
Object newElement) throws InvalidPositionException
- Replaces the element at a position with a new element.
- Parameters:
- p - The
Position
at which replacement is to occur.
- newElement - The element now to be stored at
Position p
- Returns:
- The old element, formerly stored at
Position p
- Throws: InvalidPositionException
- if
p
is null
or not from this container.
swap
public void swap(Position a,
Position b) throws InvalidPositionException
- Swaps the elements associated with the two Positions, leaving the
Positions themselves "where" they were. One of the Positions can be
from another IndexedSequence, and the swap will be across containers.
- Throws: InvalidPositionException
- if either position is
null
size
public int size()
- Gets the size of this container.
- Returns:
- Number of elements in the container, where each occurrence
of a duplicated element adds 1 to the size() of the container.
isEmpty
public boolean isEmpty()
- Tests if the container is empty.
- Returns:
-
true
if the container is empty, and
false
otherwise.
elements
public Enumeration elements()
- Gets all the elements in this container, in order.
- Returns:
- A
Enumeration
of all elements in the container
castToIndexedPosition
protected IndexedPosition castToIndexedPosition(Position p) throws InvalidPositionException
- For the following routine, we pass back an InvalidPositionException,
which will be more informational and useful to the programmer than a
CCE.
checkEmpty
protected void checkEmpty() throws EmptyContainerException
checkRank
protected void checkRank(int rank) throws BoundaryViolationException
updateIndicesStartingAt
protected void updateIndicesStartingAt(int index)
All Packages Class Hierarchy This Package Previous Next Index