algoanim.primitives
Class ArrayBasedQueue<T>

java.lang.Object
  extended by algoanim.primitives.Primitive
      extended by algoanim.primitives.VisualQueue<T>
          extended by algoanim.primitives.ArrayBasedQueue<T>

public class ArrayBasedQueue<T>
extends VisualQueue<T>

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

Author:
Dima Vronskyi

Field Summary
 
Fields inherited from class algoanim.primitives.Primitive
gen
 
Constructor Summary
ArrayBasedQueue(ArrayBasedQueueGenerator<T> abqg, Node upperLeftCorner, java.util.List<T> content, java.lang.String name, DisplayOptions display, QueueProperties qp, int capacity)
          Instantiates the ArrayBasedQueue and calls the create() method of the associated ArrayBasedQueueGenerator.
 
Method Summary
 T dequeue(Timing delay, Timing duration)
          Removes and returns the first element of the queue.
This is the delayed version as specified by delay.
 void enqueue(T elem, Timing delay, Timing duration)
          Adds the element elem as the last element to the end of the queue.
This is the delayed version as specified by delay.
 T front(Timing delay, Timing duration)
          Retrieves (without removing) the first element of the queue.
This is the delayed version as specified by delay.
 int getCapacity()
          Returns the capacity limit of the queue.
 void highlightFrontCell(Timing delay, Timing duration)
          Highlights the cell which contains the first element of the queue.
 void highlightFrontElem(Timing delay, Timing duration)
          Highlights the first element of the queue.
 void highlightTailCell(Timing delay, Timing duration)
          Highlights the cell which contains the last element of the queue.
 void highlightTailElem(Timing delay, Timing duration)
          Highlights the last element of the queue.
 boolean isEmpty(Timing delay, Timing duration)
          Tests if the queue is empty.
This is the delayed version as specified by delay.
 boolean isFull(Timing delay, Timing duration)
          Tests if the queue is full.
This is the delayed version as specified by delay.
 T tail(Timing delay, Timing duration)
          Retrieves (without removing) the last element of the queue.
This is the delayed version as specified by delay.
 void unhighlightFrontCell(Timing delay, Timing duration)
          Unhighlights the cell which contains the first element of the queue.
 void unhighlightFrontElem(Timing delay, Timing duration)
          Unhighlights the first element of the queue.
 void unhighlightTailCell(Timing delay, Timing duration)
          Unhighlights the cell which contains the last element of the queue.
 void unhighlightTailElem(Timing delay, Timing duration)
          Unhighlights the last element of the queue.
 
Methods inherited from class algoanim.primitives.VisualQueue
dequeue, enqueue, front, getInitContent, getProperties, getQueue, getUpperLeft, isEmpty, setName, tail
 
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

ArrayBasedQueue

public ArrayBasedQueue(ArrayBasedQueueGenerator<T> abqg,
                       Node upperLeftCorner,
                       java.util.List<T> content,
                       java.lang.String name,
                       DisplayOptions display,
                       QueueProperties qp,
                       int capacity)
Instantiates the ArrayBasedQueue and calls the create() method of the associated ArrayBasedQueueGenerator.

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

enqueue

public void enqueue(T elem,
                    Timing delay,
                    Timing duration)
Adds the element elem as the last element to the end of the queue.
This is the delayed version as specified by delay. The duration of this operation may also be specified.

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

dequeue

public T dequeue(Timing delay,
                 Timing duration)
Removes and returns the first element of the queue.
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 first element of the queue.
Throws:
java.util.NoSuchElementException - - if the queue is empty.

front

public T front(Timing delay,
               Timing duration)
Retrieves (without removing) the first element of the queue.
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 first element of the queue.
Throws:
java.util.NoSuchElementException - - if the queue is empty.

tail

public T tail(Timing delay,
              Timing duration)
Retrieves (without removing) the last element of the queue.
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 last element of the queue.
Throws:
java.util.NoSuchElementException - - if the queue is empty.

isEmpty

public boolean isEmpty(Timing delay,
                       Timing duration)
Tests if the queue 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 queue contains no elements; false otherwise.

isFull

public boolean isFull(Timing delay,
                      Timing duration)
Tests if the queue 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 queue is full; false otherwise.

getCapacity

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

Returns:
The capacity limit of the queue.

highlightFrontElem

public void highlightFrontElem(Timing delay,
                               Timing duration)
Highlights the first element of the queue. 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.

unhighlightFrontElem

public void unhighlightFrontElem(Timing delay,
                                 Timing duration)
Unhighlights the first element of the queue. 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.

highlightFrontCell

public void highlightFrontCell(Timing delay,
                               Timing duration)
Highlights the cell which contains the first element of the queue. 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.

unhighlightFrontCell

public void unhighlightFrontCell(Timing delay,
                                 Timing duration)
Unhighlights the cell which contains the first element of the queue. 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.

highlightTailElem

public void highlightTailElem(Timing delay,
                              Timing duration)
Highlights the last element of the queue. 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.

unhighlightTailElem

public void unhighlightTailElem(Timing delay,
                                Timing duration)
Unhighlights the last element of the queue. 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.

highlightTailCell

public void highlightTailCell(Timing delay,
                              Timing duration)
Highlights the cell which contains the last element of the queue. 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.

unhighlightTailCell

public void unhighlightTailCell(Timing delay,
                                Timing duration)
Unhighlights the cell which contains the last element of the queue. 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.