|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavafe.util.StackVector
A stack of Vector objects.
Contains 1 or more Vectors arranged in a stack. Direct access is allowed only to the elements of the top Vector via a subset of the usual java.util.Vector operations. These Vectors may not contain null elements.
push() pushs a zero-length Vector on the stack, pop() discards the top Vector, and merge() combines the top two Vectors.
The caller is responsible for ensuring that pop() and merge() are called only when the stack has at least 2 Vectors on it.
All the elements in the Vectors must be of type elementType.
Note: Although this class as a whole is thread safe, individual
instances are not. Thus, different threads can safely access
different instances of StackVector
without any
synchronization, but different threads accessing the same
instance will have to lock and synchronize.
Field Summary | |
private int |
currentStackBottom
|
private int |
elementCount
|
private java.lang.Object[] |
elements
Our data representation is as follows: elements[0], ..., elements[elementCount-1] contain the Vectors on our stack, stored as sequences of elements from the bottom of the stack (pushed longest ago) to the top of the stack. |
private int |
vectorCount
|
Constructor Summary | |
StackVector()
Create a StackVector that contains only 1 zero-length Vector. |
Method Summary | |
void |
addElement(java.lang.Object x)
Add an element at the end of the top Vector. |
private void |
addElementInternal(java.lang.Object x)
Add x to the end of the top Vector. |
private void |
checkBounds(int index)
|
void |
clear()
Reset us to the state where we contain only 1 Vector, which has zero-length. |
boolean |
contains(java.lang.Object o)
Return true iff the top Vector contains o. |
void |
copyInto(java.lang.Object[] dst)
|
java.lang.Object |
elementAt(int i)
Return the element in the top Vector at the given index. |
void |
merge()
Merge the top Vector with the Vector just under it by appending the former to the latter. |
void |
pop()
Pop off the current top Vector. |
void |
push()
Push a zero-length Vector. |
void |
removeAllElements()
Zero the top Vector. |
void |
setElementAt(java.lang.Object o,
int i)
|
int |
size()
Return the size of the top Vector. |
java.util.Vector |
stackContents()
Returns the contents of all the vectors on the stack as a single vector. |
java.lang.String |
toString()
|
int |
vectors()
Return the number of Vectors on our stack. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private java.lang.Object[] elements
elements[0], ..., elements[elementCount-1] contain the Vectors on our stack, stored as sequences of elements from the bottom of the stack (pushed longest ago) to the top of the stack. Each sequence is seperated by a null element.
Example: [1, 2, null, 3, 4, null, 5, 6] represents the stack [1, 2], [3, 4], [5, 6] where the Vector [5, 6] is on top so elementAt(1) will return 6.
To speed access to the top Vector, currentStackBottom points to the first element of the top Vector (5 in the example). Note that this may point just beyond the last element of elements if the top Vector is zero-length.
vectorCount holds the # of Vectors; it exists so that clients can make sure they've left a StackVector the way they found it and so that preconditions can be written for pop(), etc.
private int elementCount
private int currentStackBottom
private int vectorCount
Constructor Detail |
public StackVector()
Method Detail |
public final int size()
Indices into the top Vector range from 0 to size()-1.
private void checkBounds(int index)
public java.lang.Object elementAt(int i)
java.lang.ArrayIndexOutOfBoundsException
- if the index is out of
range.public void setElementAt(java.lang.Object o, int i)
private void addElementInternal(java.lang.Object x)
x may be null, in which case the caller needs to cleanup to ensure that a null element does not stay in the top Vector.
public final void addElement(java.lang.Object x)
public final void removeAllElements()
public final void copyInto(java.lang.Object[] dst)
public final boolean contains(java.lang.Object o)
public void clear()
public final int vectors()
public void push()
public void pop()
Precondition: at least 2 Vectors are on our stack.
public void merge()
Example: ..., A, TOP -> ..., A^TOP
Precondition: there are at least two vectors on our stack.
public java.util.Vector stackContents()
public java.lang.String toString()
|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |