Package org.glassfish.pfl.basic.contain
Class MarkStack<E>
java.lang.Object
org.glassfish.pfl.basic.contain.MarkStack<E>
A stack with additional operations that support recording
the current top of stack as a mark, and then later popping
all items pushed since the last mark call.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
Return true iff the stack is empty.void
mark()
Record the current position in the stack for a subsequent popMark call.peek()
Return the top element of the stack.pop()
Return the top element of the stack and remove it from the stack.popMark()
Return an ordered list of stack elements starting with the element that was on top of the stack when mark was called.
-
Field Details
-
items
-
marks
-
-
Constructor Details
-
MarkStack
public MarkStack()
-
-
Method Details
-
push
-
pop
Return the top element of the stack and remove it from the stack.- Throws:
EmptyStackException
- is thrown if the stack is empty.IllegalStateException
- if an attempt is made to pop past the top mark.
-
isEmpty
public boolean isEmpty()Return true iff the stack is empty. -
peek
Return the top element of the stack. Does not change the stack.- Throws:
EmptyStackException
- is thrown if the stack is empty.
-
mark
public void mark()Record the current position in the stack for a subsequent popMark call. This allow marking the start of a related group of items on the stack that can be popped together later by popMark. Multiple mark calls are supported. -
popMark
Return an ordered list of stack elements starting with the element that was on top of the stack when mark was called.
-