Class ContextStack<T>


  • public class ContextStack<T>
    extends java.lang.Object
    A simple stack, with factory methods for making mutated copies
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ContextStack<T> copy()
      Return a new stack based with the same contents
      ContextStack<T> copyPop()
      Return a new stack with the same contents but pop a value
      ContextStack<T> copyPush​(T value)
      Return a new stack based with the same contents and one value pushed
      static <T> ContextStack<T> create​(T value)
      Create a new stack with a single item
      T peek()
      Peek at the top value
      T pop()
      Pop a value.
      void push​(T value)
      push a value
      int size()
      Return the stack size
      java.util.List<T> stack()
      Return a copy of the stack
      java.lang.String toString()
      Joins the context stack items with ":"
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ContextStack

        public ContextStack()
      • ContextStack

        public ContextStack​(java.util.List<T> stack)
      • ContextStack

        public ContextStack​(T item)
    • Method Detail

      • push

        public void push​(T value)
        push a value
      • pop

        public T pop()
        Pop a value.
        Throws:
        java.lang.IllegalStateException - if no values remain
      • peek

        public T peek()
        Peek at the top value
        Throws:
        java.lang.IllegalStateException - if no values remain
      • copy

        public ContextStack<T> copy()
        Return a new stack based with the same contents
      • copyPush

        public ContextStack<T> copyPush​(T value)
        Return a new stack based with the same contents and one value pushed
      • copyPop

        public ContextStack<T> copyPop()
        Return a new stack with the same contents but pop a value
      • size

        public int size()
        Return the stack size
      • create

        public static <T> ContextStack<T> create​(T value)
        Create a new stack with a single item
      • stack

        public java.util.List<T> stack()
        Return a copy of the stack
      • toString

        public java.lang.String toString()
        Joins the context stack items with ":"
        Overrides:
        toString in class java.lang.Object