Class SizeLimitedStack<T>

java.lang.Object
org.csstudio.opibuilder.util.SizeLimitedStack<T>

public class SizeLimitedStack<T> extends Object
A stack with limited size. If the stack is full, the oldest element will be removed when new element was pushed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SizeLimitedStack(int sizeLimit)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Empty the stack.
    boolean
    Returns true if this stack contains the specified element.
    Looks at the object at the top of this stack without removing it from the stack.
    pop()
    Removes the object at the top of this stack and returns that object as the value of this function.
    void
    push(T e)
    Pushes an item onto the top of this stack.
    int
    Returns the number of elements in this stack.
    Return an array of all elements in the stack.

    Methods inherited from class java.lang.Object

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

    • SizeLimitedStack

      public SizeLimitedStack(int sizeLimit)
      Constructor
      Parameters:
      sizeLimit - the maximum number of elements in the stack. If the stack is full, the oldest element will be removed when new element was pushed.
  • Method Details

    • push

      public void push(T e)
      Pushes an item onto the top of this stack.
      Parameters:
      e - the item to be pushed onto this stack.
    • pop

      public T pop()
      Removes the object at the top of this stack and returns that object as the value of this function.
      Returns:
      The object at the top of this stack (the last item of the Vector object).
      Throws:
      NoSuchElementException - if this list is empty
    • peek

      public T peek()
      Looks at the object at the top of this stack without removing it from the stack.
      Returns:
      the object at the top of this stack (the last item of the Vector object).
      Throws:
      NoSuchElementException - if this list is empty
    • clear

      public void clear()
      Empty the stack.
    • toArray

      public Object[] toArray()
      Return an array of all elements in the stack. The oldest element is the first element of the returned array.
      Returns:
      the array contained all elements in the stack.
    • size

      public int size()
      Returns the number of elements in this stack.
      Returns:
      the number of elements in this stack
    • contains

      public boolean contains(T o)
      Returns true if this stack contains the specified element. More formally, returns true if and only if this stack contains at least one element e such that (o==null ? e==null : o.equals(e)).
      Parameters:
      o - element whose presence in this stack is to be tested
      Returns:
      true if this list contains the specified element