Package com.blackrook.expression
Class ExpressionStack
- java.lang.Object
-
- com.blackrook.expression.ExpressionStack
-
public class ExpressionStack extends Object
A calculation stack for expression calculation.- Author:
- Matthew Tropiano
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CAPACITY
Default capacity.
-
Constructor Summary
Constructors Constructor Description ExpressionStack()
Creates a stack with a default size.ExpressionStack(int capacity)
Creates a context with a default size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the context.boolean
isEmpty()
ExpressionValue
peek()
Peeks at a value on the top of the stack.ExpressionValue
pop()
Pops a value off the stack.void
push(boolean value)
Pushes a value onto the stack.void
push(double value)
Pushes a value onto the stack.void
push(long value)
Pushes a value onto the stack.void
push(ExpressionValue value)
Pushes a value onto the stack.int
size()
String
toString()
-
-
-
Field Detail
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITY
Default capacity.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExpressionStack
public ExpressionStack()
Creates a stack with a default size.- See Also:
DEFAULT_CAPACITY
-
ExpressionStack
public ExpressionStack(int capacity)
Creates a context with a default size.- Parameters:
capacity
- the initial capacity.
-
-
Method Detail
-
push
public void push(boolean value)
Pushes a value onto the stack.- Parameters:
value
- the value to push.
-
push
public void push(long value)
Pushes a value onto the stack.- Parameters:
value
- the value to push.
-
push
public void push(double value)
Pushes a value onto the stack.- Parameters:
value
- the value to push.
-
push
public void push(ExpressionValue value)
Pushes a value onto the stack.- Parameters:
value
- the value to push.
-
pop
public ExpressionValue pop()
Pops a value off the stack.- Returns:
- the value at the top of the stack, or null if none left.
-
peek
public ExpressionValue peek()
Peeks at a value on the top of the stack.- Returns:
- the value at the top of the stack, or null if none left.
-
clear
public void clear()
Clears the context.
-
size
public int size()
- Returns:
- the stack size.
-
isEmpty
public boolean isEmpty()
- Returns:
- true if the stack is empty, false if not.
-
-