algoanim.primitives
Class VisualStack<T>

java.lang.Object
  extended by algoanim.primitives.Primitive
      extended by algoanim.primitives.VisualStack<T>
Direct Known Subclasses:
ArrayBasedStack, ConceptualStack, ListBasedStack

public abstract class VisualStack<T>
extends Primitive

Base abstract class for all the (LIFO-)stacks in animalscriptapi.primitives.
VisualStack represents the common visual features of all the subclasses and manges the actual data using an internal java.util.Stack.
The stored objects are of the generic data type T, so it is generally possible to use VisualStack with any objects.

Author:
Dima Vronskyi
See Also:
ConceptualStack, ArrayBasedStack, ListBasedStack

Field Summary
 
Fields inherited from class algoanim.primitives.Primitive
gen
 
Constructor Summary
VisualStack(GeneratorInterface g, Node upperLeftCorner, java.util.List<T> content, java.lang.String name, DisplayOptions display, StackProperties sp)
          Constructor of the VisualStack.
 
Method Summary
 java.util.List<T> getInitContent()
          Returns the initial content of the stack.
 StackProperties getProperties()
          Returns the properties of the stack.
 java.util.Stack<T> getStack()
          Returns the internal java.util.Stack.
 Node getUpperLeft()
          Returns the upper left corner of the stack.
 boolean isEmpty()
          Tests if the stack is empty.
 T pop()
          Removes and returns the element at the top of the stack.
 void push(T elem)
          Pushes the element elem onto the top of the stack.
 void setName(java.lang.String newName)
          Sets the name of this Primitive.
 T top()
          Retrieves (without removing) the element at the top of the stack.
 
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

VisualStack

public VisualStack(GeneratorInterface g,
                   Node upperLeftCorner,
                   java.util.List<T> content,
                   java.lang.String name,
                   DisplayOptions display,
                   StackProperties sp)
Constructor of the VisualStack.

Parameters:
g - the appropriate code Generator.
upperLeftCorner - the upper left corner of this VisualStack.
content - the initial content of the VisualStack, consisting of the elements of the generic type T.
name - the name of this VisualStack.
display - [optional] the DisplayOptions of this VisualStack.
sp - [optional] the properties of this VisualStack.
Method Detail

push

public void push(T elem)
Pushes the element elem onto the top of the stack. Unlike the push-method of java.util.Stack it doesn't return the element to be pushed.

Parameters:
elem - the element to be pushed onto the stack.
See Also:
Stack.push(Object)

pop

public T pop()
Removes and returns the element at the top of the stack.

Returns:
The element at the top of the stack.
See Also:
Stack.pop()

top

public T top()
Retrieves (without removing) the element at the top of the stack.

Returns:
The element at the top of the stack.
See Also:
Stack.peek()

isEmpty

public boolean isEmpty()
Tests if the stack is empty.

Returns:
true if and only if the stack contains no elements; false otherwise.
See Also:
Stack.empty()

getUpperLeft

public Node getUpperLeft()
Returns the upper left corner of the stack.

Returns:
The upper left corner of the stack.

setName

public void setName(java.lang.String newName)
Description copied from class: Primitive
Sets the name of this Primitive.

Overrides:
setName in class Primitive
Parameters:
newName - the new name for this Primitive.
See Also:
Primitive.setName(java.lang.String)

getProperties

public StackProperties getProperties()
Returns the properties of the stack.

Returns:
The properties of the stack.

getStack

public java.util.Stack<T> getStack()
Returns the internal java.util.Stack.

Returns:
The internal java.util.Stack.

getInitContent

public java.util.List<T> getInitContent()
Returns the initial content of the stack.

Returns:
The initial content of the stack.