Class DefaultValueStack<V>
java.lang.Object
org.parboiled.support.DefaultValueStack<V>
- Type Parameters:
V- the type of the value objects
- All Implemented Interfaces:
Iterable<V>, ValueStack<V>
- Direct Known Subclasses:
DebuggingValueStack
An implementation of a stack of value objects providing an efficient snapshot capability and a number of convenience
methods. The current state of the stack can be saved and restored in small constant time with the methods
takeSnapshot() and restoreSnapshot(Object) ()}. The implementation also serves as an Iterable
over the current stack values (the values are being provided with the last value (on top of the stack) first).-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInitializes an empty value stack.DefaultValueStack(Iterable<V> values) Initializes a value stack containing the given values with the last value being at the top of the stack. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all values.voiddup()Duplicates the top value.booleanisEmpty()Determines whether the stack is empty.iterator()peek()Returns the value at the top of the stack without removing it.peek(int down) Returns the value the given number of elements below the top of the stack without removing it.voidReplaces the element the given number of elements below the current top of the stack.voidReplaces the current top value with the given value.pop()Removes the value at the top of the stack and returns it.pop(int down) Removes the value the given number of elements below the top of the stack.voidInserts the given value a given number of elements below the current top of the stack.voidPushes the given value onto the stack.voidPushes all given elements onto the stack (in the order as given).voidPushes all given elements onto the stack (in the order as given).voidrestoreSnapshot(Object snapshot) Restores the stack state as previously returned byValueStack.takeSnapshot().intsize()Returns the number of elements currently on the stack.voidswap()Swaps the top two stack values.voidswap3()Reverses the order of the top 3 stack values.voidswap4()Reverses the order of the top 4 stack values.voidswap5()Reverses the order of the top 5 stack values.voidswap6()Reverses the order of the top 5 stack values.Returns an object representing the current state of the stack.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
head
-
tempValue
-
-
Constructor Details
-
DefaultValueStack
public DefaultValueStack()Initializes an empty value stack. -
DefaultValueStack
-
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:ValueStackDetermines whether the stack is empty.- Specified by:
isEmptyin interfaceValueStack<V>- Returns:
- true if empty
-
size
public int size()Description copied from interface:ValueStackReturns the number of elements currently on the stack.- Specified by:
sizein interfaceValueStack<V>- Returns:
- the number of elements
-
clear
public void clear()Description copied from interface:ValueStackClears all values.- Specified by:
clearin interfaceValueStack<V>
-
takeSnapshot
Description copied from interface:ValueStackReturns an object representing the current state of the stack. This cost of running this operation is negligible and independent from the size of the stack.- Specified by:
takeSnapshotin interfaceValueStack<V>- Returns:
- an object representing the current state of the stack
-
restoreSnapshot
Description copied from interface:ValueStackRestores the stack state as previously returned byValueStack.takeSnapshot(). This cost of running this operation is negligible and independent from the size of the stack.- Specified by:
restoreSnapshotin interfaceValueStack<V>- Parameters:
snapshot- a snapshot object previously returned byValueStack.takeSnapshot()
-
push
Description copied from interface:ValueStackPushes the given value onto the stack. Equivalent to push(0, value).- Specified by:
pushin interfaceValueStack<V>- Parameters:
value- the value
-
push
Description copied from interface:ValueStackInserts the given value a given number of elements below the current top of the stack.- Specified by:
pushin interfaceValueStack<V>- Parameters:
down- the number of elements to skip before inserting the value (0 being equivalent to push(value))value- the value
-
pushAll
Description copied from interface:ValueStackPushes all given elements onto the stack (in the order as given).- Specified by:
pushAllin interfaceValueStack<V>- Parameters:
firstValue- the first valuemoreValues- the other values
-
pushAll
Description copied from interface:ValueStackPushes all given elements onto the stack (in the order as given).- Specified by:
pushAllin interfaceValueStack<V>- Parameters:
values- the values
-
pop
Description copied from interface:ValueStackRemoves the value at the top of the stack and returns it.- Specified by:
popin interfaceValueStack<V>- Returns:
- the current top value
-
pop
Description copied from interface:ValueStackRemoves the value the given number of elements below the top of the stack.- Specified by:
popin interfaceValueStack<V>- Parameters:
down- the number of elements to skip before removing the value (0 being equivalent to pop())- Returns:
- the value
-
peek
Description copied from interface:ValueStackReturns the value at the top of the stack without removing it.- Specified by:
peekin interfaceValueStack<V>- Returns:
- the current top value
-
peek
Description copied from interface:ValueStackReturns the value the given number of elements below the top of the stack without removing it.- Specified by:
peekin interfaceValueStack<V>- Parameters:
down- the number of elements to skip (0 being equivalent to peek())- Returns:
- the value
-
poke
Description copied from interface:ValueStackReplaces the current top value with the given value. Equivalent to poke(0, value).- Specified by:
pokein interfaceValueStack<V>- Parameters:
value- the value
-
poke
Description copied from interface:ValueStackReplaces the element the given number of elements below the current top of the stack.- Specified by:
pokein interfaceValueStack<V>- Parameters:
down- the number of elements to skip before replacing the value (0 being equivalent to poke(value))value- the value to replace with
-
dup
public void dup()Description copied from interface:ValueStackDuplicates the top value. Equivalent to push(peek()).- Specified by:
dupin interfaceValueStack<V>
-
swap
public void swap()Description copied from interface:ValueStackSwaps the top two stack values.- Specified by:
swapin interfaceValueStack<V>
-
swap3
public void swap3()Description copied from interface:ValueStackReverses the order of the top 3 stack values.- Specified by:
swap3in interfaceValueStack<V>
-
swap4
public void swap4()Description copied from interface:ValueStackReverses the order of the top 4 stack values.- Specified by:
swap4in interfaceValueStack<V>
-
swap5
public void swap5()Description copied from interface:ValueStackReverses the order of the top 5 stack values.- Specified by:
swap5in interfaceValueStack<V>
-
swap6
public void swap6()Description copied from interface:ValueStackReverses the order of the top 5 stack values.- Specified by:
swap6in interfaceValueStack<V>
-
iterator
-