Class PeekStack<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<T>
org.opentrafficsim.road.network.factory.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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Peter Knoppers
See Also:
  • Constructor Details

    • PeekStack

      public PeekStack()
  • Method Details

    • 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
    • toString

      public final String toString()
      Overrides:
      toString in class AbstractCollection<T>