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.


Constructor Index

 o VectorSequence()
Constructs a new Sequence with an initial capacity of 4.
 o VectorSequence(int)
Constructs a new sequence with an underlying Vector of size initialCapacity.
 o VectorSequence(int, int)
Constructs a new sequence with an underlying Vector of size initialCapacity.

Method Index

 o after(Position)
Gets the position after a position.
 o atRank(int)
 o before(Position)
Gets the position before a position.
 o castToIndexedPosition(Position)
For the following routine, we pass back an InvalidPositionException, which will be more informational and useful to the programmer than a CCE.
 o checkEmpty()
 o checkRank(int)
 o decSize()
Provided for remove, which needs to decrease the size by one
 o elements()
Gets all the elements in this container, in order.
 o first()
Gets the first position of this sequence.
 o incSize()
Provided for insertAtRank, which needs to up the size by one
 o 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.
 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()
Tests if the container is empty.
 o last()
Gets the last position of this sequence.
 o newContainer()
Returns a new, empty VectorSequence.
 o positions()
Gets all the Positions in this container, in order.
 o rankOf(Position)
Gets the rank of a position.
 o remove(Position)
Removes and invalidates the given Position, returning the element stored at it.
 o removeAfter(Position)
 o removeAtRank(int)
Removes an element at a particular rank.
 o removeBefore(Position)
 o removeFirst()
Removes the first element of the sequence.
 o removeLast()
Removes the last element of the sequence.
 o replace(Position, Object)
Replaces the element at a position with a new element.
 o size()
Gets the size of this container.
 o swap(Position, Position)
Swaps the elements associated with the two Positions, leaving the Positions themselves "where" they were.
 o updateIndicesStartingAt(int)

Constructors

 o VectorSequence
 public VectorSequence()
Constructs a new Sequence with an initial capacity of 4.

 o VectorSequence
 public VectorSequence(int initialCapacity)
Constructs a new sequence with an underlying Vector of size initialCapacity.

 o 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.

Methods

 o newContainer
 public Container newContainer()
Returns a new, empty VectorSequence.

 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 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

 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 removeAfter
 public Object removeAfter(Position p)
 o removeBefore
 public Object removeBefore(Position p)
 o incSize
 protected void incSize()
Provided for insertAtRank, which needs to up the size by one

 o decSize
 protected void decSize()
Provided for remove, which needs to decrease the size by one

 o 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
 o 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
 o 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.
 o 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
 o 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.
 o 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
 o 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
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o positions
 public Enumeration positions()
Gets all the Positions in this container, in order.

Returns:
An Enumeration of all Positions in the container
 o 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.
 o 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
 o 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.
 o isEmpty
 public boolean isEmpty()
Tests if the container is empty.

Returns:
true if the container is empty, and false otherwise.
 o elements
 public Enumeration elements()
Gets all the elements in this container, in order.

Returns:
A Enumeration of all elements in the container
 o 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.

 o checkEmpty
 protected void checkEmpty() throws EmptyContainerException
 o checkRank
 protected void checkRank(int rank) throws BoundaryViolationException
 o updateIndicesStartingAt
 protected void updateIndicesStartingAt(int index)

All Packages  Class Hierarchy  This Package  Previous  Next  Index