algoanim.primitives
Class ArrayBasedStack<T>

java.lang.Object
  extended by algoanim.primitives.Primitive
      extended by algoanim.primitives.VisualStack<T>
          extended by algoanim.primitives.ArrayBasedStack<T>

public class ArrayBasedStack<T>
extends VisualStack<T>

Represents a stack which has an usual LIFO-functionality and will be visualized using an array.
The stored objects are of the generic data type T, so it is generally possible to use ArrayBasedStack with any objects.

Author:
Dima Vronskyi

Field Summary
 
Fields inherited from class algoanim.primitives.Primitive
gen
 
Constructor Summary
ArrayBasedStack(ArrayBasedStackGenerator<T> absg, Node upperLeftCorner, java.util.List<T> content, java.lang.String name, DisplayOptions display, StackProperties sp, int capacity)
          Instantiates the ArrayBasedStack and calls the create() method of the associated ArrayBasedStackGenerator.
 
Method Summary
 int getCapacity()
          Returns the capacity limit of the stack.
 void highlightTopCell(Timing delay, Timing duration)
          Highlights the cell which contains the top element of the stack.
 void highlightTopElem(Timing delay, Timing duration)
          Highlights the top element of the stack.
 boolean isEmpty(Timing delay, Timing duration)
          Tests if the stack is empty.
This is the delayed version as specified by delay.
 boolean isFull(Timing delay, Timing duration)
          Tests if the stack is full.
This is the delayed version as specified by delay.
 T pop(Timing delay, Timing duration)
          Removes and returns the element at the top of the stack.
This is the delayed version as specified by delay.
 void push(T elem, Timing delay, Timing duration)
          Pushes the element elem onto the top of the stack if it is not full.
 T top(Timing delay, Timing duration)
          Retrieves (without removing) the element at the top of the stack.
This is the delayed version as specified by delay.
 void unhighlightTopCell(Timing delay, Timing duration)
          Unhighlights the cell which contains the top element of the stack.
 void unhighlightTopElem(Timing delay, Timing duration)
          Unhighlights the top element of the stack.
 
Methods inherited from class algoanim.primitives.VisualStack
getInitContent, getProperties, getStack, getUpperLeft, isEmpty, pop, push, setName, top
 
Methods inherited from class algoanim.primitives.Primitive
changeColor, exchange, getDisplayOptions, getName, hide, hide, moveBy, moveTo, moveVia, rotate, rotate, show, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayBasedStack

public ArrayBasedStack(ArrayBasedStackGenerator<T> absg,
                       Node upperLeftCorner,
                       java.util.List<T> content,
                       java.lang.String name,
                       DisplayOptions display,
                       StackProperties sp,
                       int capacity)
Instantiates the ArrayBasedStack and calls the create() method of the associated ArrayBasedStackGenerator.

Parameters:
absg - the appropriate code Generator.
upperLeftCorner - the upper left corner of this ArrayBasedStack.
content - the initial content of the ArrayBasedStack, consisting of the elements of the generic type T.
name - the name of this ArrayBasedStack.
display - [optional] the DisplayOptions of this ArrayBasedStack.
sp - [optional] the properties of this ArrayBasedStack.
capacity - the capacity limit of this ArrayBasedStack; must be nonnegative.
Throws:
java.lang.IllegalArgumentException - - if the given capacity is negative.
Method Detail

push

public void push(T elem,
                 Timing delay,
                 Timing duration)
Pushes the element elem onto the top of the stack if it is not full. Unlike the push-method of java.util.Stack it doesn't return the element to be pushed.
This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
elem - the element to be pushed onto the stack.
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.
Throws:
java.lang.IndexOutOfBoundsException - - if the stack is full.

pop

public T pop(Timing delay,
             Timing duration)
Removes and returns the element at the top of the stack.
This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.
Returns:
The element at the top of the stack.
Throws:
java.util.EmptyStackException - - if the stack is empty.

top

public T top(Timing delay,
             Timing duration)
Retrieves (without removing) the element at the top of the stack.
This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.
Returns:
The element at the top of the stack.
Throws:
java.util.EmptyStackException - - if the stack is empty.

isEmpty

public boolean isEmpty(Timing delay,
                       Timing duration)
Tests if the stack is empty.
This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.
Returns:
true if and only if the stack contains no elements; false otherwise.

isFull

public boolean isFull(Timing delay,
                      Timing duration)
Tests if the stack is full.
This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.
Returns:
true if and only if the stack is full; false otherwise.

getCapacity

public int getCapacity()
Returns the capacity limit of the stack.

Returns:
The capacity limit of the stack.

highlightTopElem

public void highlightTopElem(Timing delay,
                             Timing duration)
Highlights the top element of the stack. This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.

unhighlightTopElem

public void unhighlightTopElem(Timing delay,
                               Timing duration)
Unhighlights the top element of the stack. This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.

highlightTopCell

public void highlightTopCell(Timing delay,
                             Timing duration)
Highlights the cell which contains the top element of the stack. This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.

unhighlightTopCell

public void unhighlightTopCell(Timing delay,
                               Timing duration)
Unhighlights the cell which contains the top element of the stack. This is the delayed version as specified by delay. The duration of this operation may also be specified.

Parameters:
delay - [optional] the delay which shall be applied to the operation.
duration - [optional] the duration this action needs.