Methods Summary |
---|
public java.lang.String | ElementFromTopOfTheStack(int iIndex)Purpose: gets an element from the top of the stack
using zero-based iIndex
if(iIndex < 0 || iIndex > (GetSize()-1) )
return "";
iIndex = (GetStartPos() - iIndex) & m_iMask;
return (String)m_Vector.elementAt(iIndex);
|
private int | GetNext(int iCurrent)Purpose: return (iCurrent & m_iMask);
|
public int | GetSize()Purpose: Returns the constant size of the stack return m_iMaxSize;
|
private int | GetStartPos()Purpose:
return (m_iInsertLoc -1) & m_iMask;
|
public java.lang.String | TokenAt(int iIndex)Purpose: Gets a token from the top of the stack
Note: This function was written to maintain the compatability
with ParseStack class that uses GetSize() to call TokenAt()
Later, Parser should be modified to call ElementFromTopOfTheStack()
if(iIndex < 0 || iIndex > m_iMaxSize-1)
return "";
iIndex = m_iMaxSize-iIndex-1;
return ElementFromTopOfTheStack(iIndex);
|
public java.lang.String | getClassNameFromStack(int iDepth)Purpose: searches stack up to iDepth for a class name
String strClassName = new String();
int iSize = GetSize(), n;
for(n = iDepth; n < iSize - iDepth -2; n+=3){
if( TokenAt(iSize-(n+1)).compareTo(":") != 0 ||
TokenAt(iSize-(n+2)).compareTo(":")!= 0 )
break;
}
if(m_bDebug)printStack(n);
for(; n > iDepth; n-=3)
strClassName += TokenAt(iSize-n);
strClassName+=TokenAt(iSize-iDepth);
return strClassName;
|
private void | initialize()Purpose:
for(int i = 0; i < m_iMaxSize; i++)
m_Vector.addElement("");
|
public static void | main(java.lang.String[] args)Purpose:
TokenStack stack = new TokenStack();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
stack.push("E");
stack.push("F");
stack.push("G");
stack.push("H");
stack.push("I");
stack.push("J");
stack.push("K");
stack.push("L");
stack.printStack(5);
System.out.println(stack.TokenAt(stack.GetSize() - 1));
System.out.println(stack.TokenAt(stack.GetSize() -2));
System.out.println(stack.TokenAt(stack.GetSize() -3));
System.out.println(stack.ElementFromTopOfTheStack(0));
System.out.println(stack.ElementFromTopOfTheStack(1));
System.out.println(stack.ElementFromTopOfTheStack(2));
|
public void | printStack(int iDepth)Purpose: prints the contents of the stack up the iDepth
int iSize = GetSize();
if( iDepth > iSize -1 ) System.out.println("Unable to print stack to " + String.valueOf(iDepth) + " depth");
else{
System.out.println("Printing the TokenStack: ");
for(int n = 0; n < iDepth; n++){
System.out.print(n + "th element from the top of the stack - ");
System.out.println(ElementFromTopOfTheStack(n));
}
}
|
public void | push(java.lang.String obj)Purpose: pushes the stack
Note: if there m_iMaxSize elements on the stack, the bottom most element is
removed
m_Vector.setElementAt(obj, m_iInsertLoc);
m_iSize ++;
m_iInsertLoc = m_iSize % m_iMaxSize;
if(m_iSize == m_iMaxSize)
m_iSize = 0;
|