public class FiniteStack extends java.lang.Object implements ViewableStack
| Constructor and Description |
|---|
FiniteStack()
Constructs a FiniteStack object.
|
FiniteStack(int capacity)
Constructs a FiniteStack object of specified capacity.
|
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
Returns the current total number of assignable slots.
|
java.lang.Object |
drop()
Removes and returns the oldest object of this FiniteStack;
returns null if it is empty.
|
void |
flush()
Erases all entries of this FiniteStack.
|
java.lang.Object |
get(int index)
Returns the object at the specified index where 0 is the index of
the oldest element, and size()-1 that of the latest
element.
|
boolean |
isEmpty()
Returns true iff this FiniteStack is empty.
|
boolean |
isFull()
Returns true iff this FiniteStack is full.
|
java.util.Iterator |
iterator()
Returns an iterator for this FiniteStack.
|
java.lang.Object |
latest()
Returns the latest object pushed onto this FiniteStack without
removing it, or null if it is empty.
|
int |
latestIndex()
Returns the index of the latest object in this stack, or -1 if
the stack is empty.
|
java.lang.Object |
oldest()
Returns the oldest object of this FiniteStack without removing it,
or null if it is empty.
|
int |
oldestIndex()
Returns the index of the oldest object in this stack, or -1 if
the stack is empty.
|
java.lang.Object |
peek()
Returns the latest object pushed onto this FiniteStack without
removing it, or null if it is empty.
|
java.lang.Object |
pop()
Removes and returns the latest object pushed onto this FiniteStack;
returns null if it is empty.
|
java.lang.Object |
push(java.lang.Object object)
Pushes the specified object onto this FiniteStack.
|
void |
setCapacity(int capacity)
Sets the total number of assignable slots to the specified capacity.
|
void |
setToSize()
Resizes this FiniteStack's container to the current number of
assigned slots.
|
int |
size()
Returns the current number of assigned slots.
|
java.lang.String |
toString()
Returns a printable string representation of this FiniteStack.
|
public FiniteStack()
public FiniteStack(int capacity)
public final boolean isEmpty()
isEmpty in interface ViewableStackpublic final int capacity()
public final int size()
size in interface ViewableStackpublic final boolean isFull()
public final void flush()
public final java.lang.Object peek()
peek in interface ViewableStackpublic final java.lang.Object latest()
public final java.lang.Object oldest()
public final int latestIndex()
public final int oldestIndex()
public final java.lang.Object get(int index)
get in interface ViewableStackpublic final java.lang.Object pop()
public final java.lang.Object drop()
public final java.lang.Object push(java.lang.Object object)
public final void setCapacity(int capacity)
public final void setToSize()
public final java.util.Iterator iterator()
iterator in interface ViewableStackpublic java.lang.String toString()
toString in class java.lang.Object