FileDocCategorySizeDatePackage
BoolStack.javaAPI DocJava SE 5 API4322Fri Aug 26 14:56:04 BST 2005com.sun.org.apache.xml.internal.utils

BoolStack

public final class BoolStack extends Object implements Cloneable
Simple stack for boolean values.
xsl.usage
internal

Fields Summary
private boolean[]
m_values
Array of boolean values
private int
m_allocatedSize
Array size allocated
private int
m_index
Index into the array of booleans
Constructors Summary
public BoolStack()
Default constructor. Note that the default block size is very small, for small lists.

    this(32);
  
public BoolStack(int size)
Construct a IntVector, using the given block size.

param
size array size to allocate


    m_allocatedSize = size;
    m_values = new boolean[size];
    m_index = -1;
  
Methods Summary
public final voidclear()
Clears the stack.

  	m_index = -1;
  
public java.lang.Objectclone()

    return super.clone();
  
private voidgrow()
Grows the size of the stack


    m_allocatedSize *= 2;

    boolean newVector[] = new boolean[m_allocatedSize];

    System.arraycopy(m_values, 0, newVector, 0, m_index + 1);

    m_values = newVector;
  
public booleanisEmpty()
Tests if this stack is empty.

return
true if this stack is empty; false otherwise.

    return (m_index == -1);
  
public final booleanpeek()
Looks at the object at the top of this stack without removing it from the stack.

return
the object at the top of this stack.
throws
EmptyStackException if this stack is empty.

    return m_values[m_index];
  
public final booleanpeekOrFalse()
Looks at the object at the top of this stack without removing it from the stack. If the stack is empty, it returns false.

return
the object at the top of this stack.

    return (m_index > -1) ? m_values[m_index] : false;
  
public final booleanpeekOrTrue()
Looks at the object at the top of this stack without removing it from the stack. If the stack is empty, it returns true.

return
the object at the top of this stack.

    return (m_index > -1) ? m_values[m_index] : true;
  
public final booleanpop()
Removes the object at the top of this stack and returns that object as the value of this function.

return
The object at the top of this stack.
throws
EmptyStackException if this stack is empty.

    return m_values[m_index--];
  
public final booleanpopAndTop()
Removes the object at the top of this stack and returns the next object at the top as the value of this function.

return
Next object to the top or false if none there


    m_index--;

    return (m_index >= 0) ? m_values[m_index] : false;
  
public final booleanpush(boolean val)
Pushes an item onto the top of this stack.

param
val the boolean to be pushed onto this stack.
return
the item argument.


    if (m_index == m_allocatedSize - 1)
      grow();

    return (m_values[++m_index] = val);
  
public final voidsetTop(boolean b)
Set the item at the top of this stack

param
b Object to set at the top of this stack

    m_values[m_index] = b;
  
public final intsize()
Get the length of the list.

return
Current length of the list

    return m_index + 1;