Class ExpressionStack


  • public class ExpressionStack
    extends Object
    A calculation stack for expression calculation.
    Author:
    Matthew Tropiano
    • 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.