Package org.csstudio.opibuilder.util
Class SizeLimitedStack<T>
java.lang.Object
org.csstudio.opibuilder.util.SizeLimitedStack<T>
A stack with limited size. If the stack is full, the oldest element will be removed when new element was pushed.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Empty the stack.boolean
Returns true if this stack contains the specified element.peek()
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
Pushes an item onto the top of this stack.int
size()
Returns the number of elements in this stack.Object[]
toArray()
Return an array of all elements in the stack.
-
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
Pushes an item onto the top of this stack.- Parameters:
e
- the item to be pushed onto this stack.
-
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
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
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
Returns true if this stack contains the specified element. More formally, returns true if and only if this stack contains at least one elemente
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
-