Package 

Class Stack


  • 
    public class Stack<T extends Object>
    
                        

    Stack represents a Last In First Out (LIFO) data structure. It provides useful functions to manipulate the Stack.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Integer size
    • Constructor Summary

      Constructors 
      Constructor Description
      Stack(T element) Creates a Stack with vararg initial elements.
      Stack() Creates an empty Stack.
      Stack(Collection<T> elements) Creates a Stack with, given initial elements.
    • Method Summary

      Modifier and Type Method Description
      final Integer getSize()
      final T pop() Pops the topmost element in this Stack.
      final T popOrNull() Pops the topmost element in this Stack.
      final List<T> popAll(Integer numToPop) Pops the n topmost elements in this Stack, where n is specified by the parameter.
      final List<T> clear() Pops all elements in this Stack and returns them in a List, with the topmost element as the list's head i.e.
      final Unit push(T element) Pushes the supplied element onto the Stack.
      final Unit pushAll(Collection<T> elements) Pushes all the supplied elements onto the Stack.
      final Unit pushAll(T elements) Pushes all the supplied elements onto the Stack.
      final T peek() Returns the topmost element in this Stack but does not pop it.
      final T peekOrNull() Returns the topmost element in this Stack but does not pop it.
      final List<T> peekAll(Integer numToPeek) Returns all elements in this Stack, with the last pushed Element at the highest index.
      final Integer indexOf(T element) Returns the index of the first occurrence of the specified element in the Stack, or -1 if the specified element is not contained in the Stack.
      final Boolean isEmpty() Returns whether this Stack is empty or not.
      final Boolean isNotEmpty() Returns whether this Stack is not empty.
      final Unit shuffle() Shuffles this Stack.
      final Unit sort(Comparator<in T> comparator) Sorts this Stack.
      • Methods inherited from class java.lang.Object

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

      • Stack

        Stack(T element)
        Creates a Stack with vararg initial elements.
      • Stack

        Stack()
        Creates an empty Stack.
      • Stack

        Stack(Collection<T> elements)
        Creates a Stack with, given initial elements.
    • Method Detail

      • pop

         final T pop()

        Pops the topmost element in this Stack.

      • popAll

         final List<T> popAll(Integer numToPop)

        Pops the n topmost elements in this Stack, where n is specified by the parameter. The topmost element in the stack gets the list's head i.e. index 0.

        Parameters:
        numToPop - Specifies how many elements to pop.
      • clear

         final List<T> clear()

        Pops all elements in this Stack and returns them in a List, with the topmost element as the list's head i.e. index 0.

      • push

         final Unit push(T element)

        Pushes the supplied element onto the Stack.

        Parameters:
        element - The element to push onto this Stack.
      • pushAll

         final Unit pushAll(Collection<T> elements)

        Pushes all the supplied elements onto the Stack. The element at index 0 of the List is pushed first.

        Parameters:
        elements - The elements to push onto this Stack.
      • pushAll

         final Unit pushAll(T elements)

        Pushes all the supplied elements onto the Stack. The first parameter is pushed first.

        Parameters:
        elements - The elements to push onto this Stack.
      • peek

         final T peek()

        Returns the topmost element in this Stack but does not pop it.

      • peekOrNull

         final T peekOrNull()

        Returns the topmost element in this Stack but does not pop it.

      • peekAll

         final List<T> peekAll(Integer numToPeek)

        Returns all elements in this Stack, with the last pushed Element at the highest index.

      • indexOf

         final Integer indexOf(T element)

        Returns the index of the first occurrence of the specified element in the Stack, or -1 if the specified element is not contained in the Stack.