Class StandardStack<T>

  • Type Parameters:
    T - The type of things stored in the stack
    All Implemented Interfaces:
    Stack<T>

    public final class StandardStack<T>
    extends Object
    implements Stack<T>
    A general-purpose stack impl supporting null values.
    • Constructor Detail

      • StandardStack

        public StandardStack​(Class<T> type)
      • StandardStack

        public StandardStack​(Class<T> type,
                             T initial)
    • Method Detail

      • push

        public void push​(T e)
        Description copied from interface: Stack
        Push the new element on the top of the stack
        Specified by:
        push in interface Stack<T>
      • pop

        public T pop()
        Description copied from interface: Stack
        Pop (remove and return) the current element off the stack
        Specified by:
        pop in interface Stack<T>
      • getCurrent

        public T getCurrent()
        Description copied from interface: Stack
        The element currently at the top of the stack
        Specified by:
        getCurrent in interface Stack<T>
      • peek

        public T peek​(int offsetFromTop)
        Description copied from interface: Stack
        The element at the given offset, relative to the top of the stack
        Specified by:
        peek in interface Stack<T>
      • getRoot

        public T getRoot()
        Description copied from interface: Stack
        The element currently at the bottom of the stack
        Specified by:
        getRoot in interface Stack<T>
      • depth

        public int depth()
        Description copied from interface: Stack
        How many elements are currently on the stack?
        Specified by:
        depth in interface Stack<T>
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Stack
        Are there no elements currently in the stack?
        Specified by:
        isEmpty in interface Stack<T>
      • clear

        public void clear()
        Description copied from interface: Stack
        Remove all elements from the stack
        Specified by:
        clear in interface Stack<T>
      • visitRootFirst

        public void visitRootFirst​(Consumer<T> action)
        Description copied from interface: Stack
        Visit all elements in the stack, starting with the root and working "forward"
        Specified by:
        visitRootFirst in interface Stack<T>
      • findCurrentFirst

        public <X> X findCurrentFirst​(Function<T,​X> function)
        Description copied from interface: Stack
        Find an element on the stack and return a value. The first non-null element returned from `action` stops the iteration and is returned from here
        Specified by:
        findCurrentFirst in interface Stack<T>
      • findCurrentFirstWithParameter

        public <X,​Y> X findCurrentFirstWithParameter​(Y parameter,
                                                           BiFunction<T,​Y,​X> biFunction)
        Description copied from interface: Stack
        Runs a function on each couple defined as {Y,T} in which Y is fixed, and T is each instance of this stack. Not all Ts might be presented as the iteration is interrupted as soon as the first non-null value is returned by the (bi)function, which is then returned from this function.
        Specified by:
        findCurrentFirstWithParameter in interface Stack<T>
        Type Parameters:
        X - the return type of the function
        Y - the type of the fixed parameter
        Parameters:
        parameter - a parameter to be passed to the (bi)funtion
        biFunction - a (bi)function taking as input parameter Y and each of the T from the current stack, and return type of X.
        Returns:
        the first non-null result by the function, or null if no matches.