public class DefaultStackModel extends DefaultListModel implements StackModel
StackModel
interface. It inherits its base functionality from
DefaultListModel
, and adds only methods for dealing with
stack operations.listenerList
Constructor and Description |
---|
DefaultStackModel()
Construct a new
DefaultStackModel . |
Modifier and Type | Method and Description |
---|---|
void |
addStackDataListener(ListDataListener listener)
Add a
ListDataListener to this model's list of listeners. |
void |
append(Object obj)
Append an object to the bottom of the stack.
|
void |
drop()
Drop an item off the stack.
|
int |
getDepth()
Get the depth of the stack.
|
boolean |
isEmpty()
Determine if the stack is empty.
|
Object |
peek()
Retrieve the topmost item from the stack (without removing the item from
the stack).
|
Object |
pick(int index)
Remove an object from the stack.
|
Object |
pop()
Pop an object off the stack.
|
void |
push(Object obj)
Push an object on the stack.
|
void |
removeStackDataListener(ListDataListener listener)
Remove a
ListDataListener from this model's list of
listeners. |
void |
swap()
Swap the topmost items on the stack.
|
add, addElement, capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, setSize, size, toArray, toString, trimToSize
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addListDataListener, getElementAt, getSize, removeListDataListener
public DefaultStackModel()
DefaultStackModel
.public void push(Object obj)
push
in interface StackModel
obj
- The object to push.public Object pop() throws EmptyStackException
pop
in interface StackModel
EmptyStackException
public void drop() throws EmptyStackException
drop
in interface StackModel
EmptyStackException
- If the stack is empty.public Object peek() throws EmptyStackException
peek
in interface StackModel
EmptyStackException
- If the stack is empty.public int getDepth()
getDepth
in interface StackModel
public void swap() throws EmptyStackException
swap
in interface StackModel
EmptyStackException
- If the stack is empty.public boolean isEmpty()
isEmpty
in interface StackModel
isEmpty
in class DefaultListModel
true
if there are no items in the stack, and
false
otherwise.public Object pick(int index) throws ArrayIndexOutOfBoundsException, EmptyStackException
pick
in interface StackModel
index
- The offset (from the top of the stack) of the item to
remove.EmptyStackException
- If the stack is empty.ArrayIndexOutOfBoundsException
- If the value of
index
is out of range.public void append(Object obj)
append
in interface StackModel
obj
- The object to append.public void addStackDataListener(ListDataListener listener)
ListDataListener
to this model's list of listeners.
Since a stack is essentially a list with some special semantics,
ListDataListeners
are used.addStackDataListener
in interface StackModel
listener
- The listener to add.public void removeStackDataListener(ListDataListener listener)
ListDataListener
from this model's list of
listeners. Since a stack is essentially a list with some special
semantics, ListDataListeners
are used.removeStackDataListener
in interface StackModel
listener
- The listener to add.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses