Class PeekStack<T>

  • Type Parameters:
    T - type of the objects stored on this PeekStack
    All Implemented Interfaces:
    Serializable, Cloneable, Iterable<T>, Collection<T>, List<T>, RandomAccess

    public class PeekStack<T>
    extends ArrayList<T>
    Stack object that allows easy verification of the values of the last few entries.

    Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $, initial version 24 jun. 2015

    Author:
    Peter Knoppers
    See Also:
    Serialized Form
    • Constructor Detail

      • PeekStack

        public PeekStack()
    • Method Detail

      • push

        public final void push​(T element)
        Push an element on this stack.
        Parameters:
        element - T; the element to push onto this stack
      • pop

        public final T pop()
        Pop an element off this stack.
        Returns:
        T; the element that was popped of this stack
      • peekNthLast

        public final T peekNthLast​(int offset)
        Return the N-from-last element of this PeekStack.
        Parameters:
        offset - int; if 0 the last pushed, but not yet popped element is returned; if offset is 1, the before last pushed, but not yet popped element is returned; etc.
        Returns:
        T; the addressed element
      • topEntriesEqual

        public final boolean topEntriesEqual​(T... entries)
        Check if the elements on the top of this PeekStack are equal to the provided entries.
        Parameters:
        entries - T...; the provided entries
        Returns:
        boolean; true if this PeekStack contains, at the top, the provided entries in the specified order; false otherwise