kiwi.ui.model
Interface StackModel

All Known Implementing Classes:
DefaultStackModel

public abstract interface StackModel
extends ListModel

An interface describing the data model for a stack. This interface extends ListModel as a stack is essentially a list with special semantics.

Version:
1.0 (10/98)
Author:
Mark Lindner, PING Software Group
See Also:
StackView

Method Summary
 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.
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, getElementAt, getSize, removeListDataListener
 

Method Detail

push

public void push(Object obj)
Push an object on the stack. The object becomes the topmost item on the stack.
Parameters:
obj - The object to push.

pop

public Object pop()
           throws EmptyStackException
Pop an object off the stack. Pulls the topmost item off the stack.
Returns:
The popped object.

drop

public void drop()
Drop an item off the stack. Pops and discards the topmost item on the stack.
Throws:
EmptyStackException - If the stack is empty.

peek

public Object peek()
            throws ArrayIndexOutOfBoundsException
Retrieve the topmost item from the stack (without removing the item from the stack).
Returns:
The topmost item on the stack.
Throws:
EmptyStackException - If the stack is empty.

getDepth

public int getDepth()
Get the depth of the stack.
Returns:
The number of items in the stack.

swap

public void swap()
          throws EmptyStackException
Swap the topmost items on the stack. If the stack contains only one item, calling this method has no effect.
Throws:
EmptyStackException - If the stack is empty.

isEmpty

public boolean isEmpty()
Determine if the stack is empty.
Returns:
true if there are no items in the stack, and false otherwise.

pick

public Object pick(int index)
            throws ArrayIndexOutOfBoundsException,
                   EmptyStackException
Remove an object from the stack. Retrieves (and removes) an object from the given offset in the stack.
Parameters:
index - The offset (from the top of the stack) of the item to remove.
Returns:
The object that was removed.
Throws:
EmptyStackException - If the stack is empty.
ArrayIndexOutOfBoundsException - If the value of index is out of range.

append

public void append(Object obj)
Append an object to the bottom of the stack.
Parameters:
obj - The object to append.

addStackDataListener

public void addStackDataListener(ListDataListener listener)
Add a ListDataListener to this model's list of listeners. Since a stack is essentially a list with some special semantics, ListDataListeners are used.
Parameters:
listener - The listener to add.

removeStackDataListener

public void removeStackDataListener(ListDataListener listener)
Remove a ListDataListener from this model's list of listeners. Since a stack is essentially a list with some special semantics, ListDataListeners are used.
Parameters:
listener - The listener to add.