Class SizeLimitedStack<T>
java.lang.Object
org.eclipse.nebula.visualization.internal.xygraph.undo.SizeLimitedStack<T>
public class SizeLimitedStack<T>
extends java.lang.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
clear()
Empty the stack.T
peek()
Looks at the object at the top of this stack without removing it from the stack.T
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
size()
Returns the number of elements in this stack.java.lang.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:
java.util.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:
java.util.NoSuchElementException
- if this list is empty
-
clear
public void clear()Empty the stack. -
toArray
public java.lang.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
-