Package net.sf.saxon.tree.util
Class IndexedStack<T>
java.lang.Object
net.sf.saxon.tree.util.IndexedStack<T>
- All Implemented Interfaces:
Iterable<T>
This class replicates functionality that is available in a Java Stack, but not
in a C# Stack, for example the ability to access elements by direct index
(0-based, counting from the bottom of the stack). It is used in place of
Stack
in the few places where this functionality is
needed.
The stack is iterable, and iteration is in bottom-to-top order (like Java, but unlike a C# stack where iteration is top-to-bottom)
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty stack with a default initial space allocationIndexedStack
(int size) Create an empty stack with a specified initial space allocation -
Method Summary
Modifier and TypeMethodDescriptionboolean
Search for an item on the stackget
(int i) Get the item at position N in the stack, without changing the state of the stackint
Search for an item on the stack, starting from the bottomboolean
isEmpty()
Ask if the stack is emptyiterator()
Iterate the stack in bottom to top orderpeek()
Get the item on the top of the stack, without changing the state of the stackpop()
Get the item on the top of the stack, and remove it from the stackvoid
Add an item to the top of the stackvoid
Overwrite the item at position N in the stackint
size()
Get the current height of the stackMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
IndexedStack
public IndexedStack()Create an empty stack with a default initial space allocation -
IndexedStack
public IndexedStack(int size) Create an empty stack with a specified initial space allocation- Parameters:
size
- the number of entries to be allocated
-
-
Method Details
-
size
public int size()Get the current height of the stack- Returns:
- the number of items on the stack
-
isEmpty
public boolean isEmpty()Ask if the stack is empty- Returns:
- true if the stack contains no items
-
push
Add an item to the top of the stack- Parameters:
item
- the item to be added
-
peek
Get the item on the top of the stack, without changing the state of the stack- Returns:
- the topmost item
- Throws:
EmptyStackException
- if the stack is empty
-
pop
Get the item on the top of the stack, and remove it from the stack- Returns:
- the topmost item
- Throws:
EmptyStackException
- if the stack is empty
-
get
Get the item at position N in the stack, without changing the state of the stack- Parameters:
i
- the position of the required item, where the first item counting from the bottom of the stack is position 0 (zero)- Returns:
- the item at the specified position
- Throws:
IndexOutOfBoundsException
- ifi
is negative, or greater than or equal to the stack size
-
set
Overwrite the item at position N in the stack- Parameters:
i
- the position of the required item, where the first item counting from the bottom of the stack is position 0 (zero)value
- the item to be put at the specified position- Throws:
IndexOutOfBoundsException
- ifi
is negative, or greater than or equal to the stack size
-
contains
Search for an item on the stack- Parameters:
value
- the item being sought- Returns:
- true if the stack contains an item equal to the sought item
-
indexOf
Search for an item on the stack, starting from the bottom- Parameters:
value
- the item being sought- Returns:
- the index position of the first item found that is equal to
value
, or -1 if no such item is found
-
iterator
Iterate the stack in bottom to top order
-