|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--jdsl.core.ref.VectorSequence
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 Summary | |
VectorSequence()
Constructs a new Sequence with an initial capacity of 4. |
|
VectorSequence(int initialCapacity)
Constructs a new sequence with an underlying Vector of size initialCapacity. |
|
VectorSequence(int initialCapacity,
int capacityIncrement)
Constructs a new sequence with an underlying Vector of size initialCapacity. |
|
| Method Summary | |
Position |
after(Position successor)
Gets the position after a position. |
Position |
atRank(int rank)
|
Position |
before(Position successor)
Gets the position before a position. |
java.util.Enumeration |
elements()
Gets all the elements in this container, in order. |
Position |
first()
Gets the first position of this sequence. |
Position |
insertAfter(Position predecessor,
java.lang.Object o)
Inserts the given element before the given Position, creating
and returning a new Position (before the given one) at which to
store the element. |
Position |
insertAtRank(int rank,
java.lang.Object o)
Inserts the given element at the given rank, creating and returning a new Position at which to store the element. |
Position |
insertBefore(Position successor,
java.lang.Object o)
Inserts the given element before the given Position, creating
and returning a new Position (before the given one) at which to
store the element. |
Position |
insertFirst(java.lang.Object o)
Inserts the given element first in the sequence, creating and returning a new Position at which to store the element. |
Position |
insertLast(java.lang.Object o)
Inserts the given element last in the sequence, creating and returning a new Position at which to store the element. |
boolean |
isEmpty()
Tests if the container is empty. |
Position |
last()
Gets the last position of this sequence. |
Container |
newContainer()
Returns a new, empty VectorSequence. |
java.util.Enumeration |
positions()
Gets all the Positions in this container, in order. |
int |
rankOf(Position p)
Gets the rank of a position. |
java.lang.Object |
remove(Position p)
Removes and invalidates the given Position, returning the element stored at it. |
java.lang.Object |
removeAfter(Position p)
|
java.lang.Object |
removeAtRank(int i)
Removes an element at a particular rank. |
java.lang.Object |
removeBefore(Position p)
|
java.lang.Object |
removeFirst()
Removes the first element of the sequence. |
java.lang.Object |
removeLast()
Removes the last element of the sequence. |
java.lang.Object |
replace(Position p,
java.lang.Object newElement)
Replaces the element at a position with a new element. |
int |
size()
Gets the size of this container. |
void |
swap(Position a,
Position b)
Swaps the elements associated with the two Positions, leaving the Positions themselves "where" they were. |
| Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public VectorSequence()
public VectorSequence(int initialCapacity)
initialCapacity.
public VectorSequence(int initialCapacity,
int capacityIncrement)
initialCapacity. Every time the Vector resizes, it
increases by capicityIncrement.| Method Detail |
public Container newContainer()
public Position atRank(int rank)
throws BoundaryViolationException
rank - An integer between 0 and N-1, where N is the size() of
the sequence
public Position insertAtRank(int rank,
java.lang.Object o)
throws BoundaryViolationException
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
public java.lang.Object remove(Position p)
throws InvalidPositionException
p - A Position in this sequencepublic java.lang.Object removeAfter(Position p)
public java.lang.Object removeBefore(Position p)
public Position first()
throws EmptyContainerException
Position for first element in the sequence, if anypublic Position last()
public Position before(Position successor)
throws InvalidPositionException,
BoundaryViolationException
successor - A Position in this sequencePosition before the given Positionsuccessor is not from
this container.successor is the first
position of this sequence.
public Position after(Position successor)
throws InvalidPositionException,
BoundaryViolationException
predecessor - A Position in this sequencePosition after the given Position
public int rankOf(Position p)
throws InvalidPositionException
rankOf (
first() ) == 0p - A Position in this sequencep is null * or not from this container.public Position insertFirst(java.lang.Object o)
o - Any java.lang.Objectpublic Position insertLast(java.lang.Object o)
Position at which to store the element.o - Any java.lang.Object
public Position insertBefore(Position successor,
java.lang.Object o)
throws InvalidPositionException,
BoundaryViolationException
Position, creating
and returning a new Position (before the given one) at which to
store the element.successor - Position that will follow the inserted
Positiono - Any java.lang.Objectpredecessor is
null not from this container.predecessor is the
last position of this sequence.
public Position insertAfter(Position predecessor,
java.lang.Object o)
throws InvalidPositionException,
BoundaryViolationException
Position, creating
and returning a new Position (before the given one) at which to
store the element.successor - Position that will follow the inserted
Positiono - Any java.lang.Objectpredecessor is
null not from this container.predecessor is the
last position of this sequence.
public java.lang.Object removeLast()
throws EmptyContainerException
public java.lang.Object removeFirst()
throws EmptyContainerException
public java.lang.Object removeAtRank(int i)
throws EmptyContainerException,
BoundaryViolationException
i - The rank of the element to remove.ii is out of
bounds.public java.util.Enumeration positions()
Positions in this container, in order.Enumeration of all Positions in the
container
public java.lang.Object replace(Position p,
java.lang.Object newElement)
throws InvalidPositionException
p - The Position at which replacement is to occur.newElement - The element now to be stored at Position pPosition pp is null
or not from this container.
public void swap(Position a,
Position b)
throws InvalidPositionException
a - b - nullpublic int size()
public boolean isEmpty()
true if the container is empty, and
false otherwise.public java.util.Enumeration elements()
Enumeration of all elements in the container
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||