|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--jdsl.ArrayListSequence
A Sequence implemented with a java.util.ArrayList. You will probably need to read it to understand the operation and the time complexities of this class. In particular, since ArrayList allocates a new array and copies the old array into the new one whenever it runs out of space, calls like vec_.add(index,object) are NOT constant-time operations.
| Constructor Summary | |
ArrayListSequence()
Constructs a new Sequence with an initial capacity of 4. |
|
ArrayListSequence(int initialCapacity)
Constructs a new sequence with an underlying ArrayList 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. |
protected jdsl.IndexedPosition |
castToIndexedPosition(Position p)
For the following routine, we pass back an InvalidPositionException, which will be more informational and useful to the programmer than a CCE. |
protected void |
checkEmpty()
|
protected void |
checkRank(int rank)
|
protected void |
decSize()
Provided for remove, which needs to decrease the size by one |
java.util.Iterator |
elements()
Gets all the elements in this container, in order. |
Position |
first()
Gets the first position of this sequence. |
protected void |
incSize()
Provided for insertAtRank, which needs to up the size by one |
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 ArrayListSequence. |
java.util.Iterator |
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. |
protected void |
updateIndicesStartingAt(int index)
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public ArrayListSequence()
public ArrayListSequence(int initialCapacity)
initialCapacity.| 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)
protected void incSize()
protected void decSize()
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.Iterator positions()
Positions in this container, in order.Iterator 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.Iterator elements()
Iterator of all elements in the container
protected jdsl.IndexedPosition castToIndexedPosition(Position p)
throws InvalidPositionException
protected void checkEmpty()
throws EmptyContainerException
protected void checkRank(int rank)
throws BoundaryViolationException
protected void updateIndicesStartingAt(int index)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||