Package ghidra.util.datastruct
Class Stack<E>
java.lang.Object
ghidra.util.datastruct.Stack<E>
- All Implemented Interfaces:
Iterable<E>
- Direct Known Subclasses:
FixedSizeStack
The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class ArrayList with five operations that allow an array list to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top.
When a stack is first created, it contains no items.
Note: This implementation is not synchronized!
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Appends the given item to the top of the stack.void
clear()
Clears the stack.boolean
get
(int depth) Returns the element at the specified depth in this stack.int
hashCode()
boolean
isEmpty()
Tests if this stack is empty.iterator()
Returns an iterator over the items of the stack.peek()
Looks at the object at the top of this stack without removing it from the stack.pop()
Removes the object at the top of this stack and returns that object as the value of this function.Pushes an item onto the top of this stack.int
Returns the position where an object is on this stack.int
size()
Returns the number of elements in this stack.stream()
Returns a stream over this collection.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
list
-
-
Constructor Details
-
Stack
public Stack()Creates an empty Stack. -
Stack
public Stack(int initialCapacity) Creates an empty Stack with specified capacity.- Parameters:
initialCapacity
- the initial capacity.
-
Stack
Copy Constructor. Creates a new stack using the items of the given stack. Only a shallow copy is performed.- Parameters:
stack
- the stack to copy
-
-
Method Details
-
isEmpty
public boolean isEmpty()Tests if this stack is empty. -
peek
Looks at the object at the top of this stack without removing it from the stack. -
pop
Removes the object at the top of this stack and returns that object as the value of this function. -
push
Pushes an item onto the top of this stack.- Parameters:
item
- the object to push onto the stack.
-
search
Returns the position where an object is on this stack.- Parameters:
o
- the object to search for.
-
size
public int size()Returns the number of elements in this stack.- Returns:
- the number of elements in this stack
-
get
Returns the element at the specified depth in this stack. 0 indicates the bottom of the stack. size()-1 indicates the top of the stack.- Parameters:
depth
- the depth in the stack.- Returns:
- the element at the specified depth in this stack
-
add
Appends the given item to the top of the stack.- Parameters:
item
- the new top of the stack
-
clear
public void clear()Clears the stack. All items will be removed. -
iterator
Returns an iterator over the items of the stack. The iterator starts from the bottom of the stack. -
stream
Returns a stream over this collection.- Returns:
- a stream over this collection.
-
hashCode
public int hashCode() -
equals
-
toString
-