|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgoldman.collection.positional.Stack<E>
public class Stack<E>
More specialized than a buffer, a stack is natural for applications that insert and remove elements only at one end of the buffer. That is, a stack implements a last-in-first-out (LIFO) line. A stack is a more specialized abstraction than a buffer that maintains a last-in, first-out (LIFO) line. A stack is logically viewed as a vertical line in which elements are inserted and removed at the "top" of the stack.
Constructor Summary | |
---|---|
Stack()
Creates an bounded, untracked stack with a default initial capacity |
|
Stack(int capacity)
Creates an unbounded, untracked stack with the given capacity |
|
Stack(int capacity,
boolean bounded)
Creates an untracked stack satisfying the given requirements |
|
Stack(int capacity,
boolean bounded,
boolean tracked)
Creates a stack satisfying the given requirements |
Method Summary | |
---|---|
void |
clear()
Removes all elements from the stack. |
boolean |
contains(E value)
Returns true if and only if the given value is contained within the stack. |
int |
getSize()
Returns the number of elements in the stack. |
boolean |
isEmpty()
Returns true if and only if there are no elements in the stack. |
Locator<E> |
iterator()
Returns an iterator initialized at FORE. |
E |
peek()
Returns the object on the top of the stack. |
E |
pop()
Removes the item at the top of the stack |
void |
push(E element)
Inserts the given element at the top of the stack. |
String |
toString()
Returns a string representation of the elements in the stack. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Stack(int capacity, boolean bounded, boolean tracked)
capacity
- the initial capacity for the stackbounded
- a boolean that indicates if the stack should be boundedtracked
- a boolean that indicates if a tracked implementation is neededpublic Stack()
public Stack(int capacity)
capacity
- the initial capacity for the stackpublic Stack(int capacity, boolean bounded)
capacity
- the initial capacity for the stackbounded
- which indicates if the stack should be boundedMethod Detail |
---|
public boolean contains(E value)
public void clear()
public int getSize()
public boolean isEmpty()
public Locator<E> iterator()
public String toString()
toString
in class Object
public E peek()
public void push(E element)
element
- the new element to insert
AtCapacityException
- a bounded stack is fullpublic E pop()
NoSuchElementException
- the stack is empty
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |