Queue

Interface
Inherits from:BasicInterface
  • Author: Simon Wacker
  • Classpath: org.as2lib.data.holder.Queue
  • File last modified: Wednesday, 06 April 2005, 13:18:24
Queue is the base interface for data holders that follow the 'first-in, first-out' policy.

It offers the opposite functionality of a stack which follows the 'last-in, first-out' policy.

'first-in, first-out' means that the first value that has been enqueued/added to the queue is the first that gets dequeued/removed.

The usage of a queue is quite simple. You have one method to add/enqueue values enqueue and one method to remove/dequeue them dequeue. You can also peek at the beginning of the queue to see what value has been added/enqueued at first without removing it peek.

If you want to iterate over the values of the queue you can either use the iterator returned by the iterator method or the array that contains the queue's values returned by the toArray method.

The two methods isEmpty and size let you find out whether the queue contains values and how many values it contains.

Example:

// the queue gets set up
var queue:Queue = new MyQueue();
queue.enqueue("value1");
queue.enqueue("value2");
queue.enqueue("value3");
// the queue gets used somewhere in your application
trace(queue.peek()); // traces the first element without removing it
while (!queue.isEmpty()) {
    trace(queue.dequeue());
}

Output:

value1
value1
value2
value3

Summary

Instance methods
Instance methods inherited from BasicInterface

Instance methods

dequeue

function dequeue (
Void)
Removes and returns the firstly inserted value.
Returns:
the firstly inserted value
Throws:
EmptyDataHolderException if this queue is empty

enqueue

function enqueue (
value) : Void
Adds the passed-in value to this queue.
Parameters:
value:
the value to add

isEmpty

function isEmpty (
Void) : Boolean
Returns whether this queue contains any values.
Returns:
true if this queue contains no values else false

iterator

function iterator (
Void) : Iterator
Returns an iterator to iterate over the values of this queue.
Returns:
an iterator to iterate over this queue's values
See also:

peek

function peek (
Void)
Returns the firstly inserted value.
Returns:
the firstly inserted value
Throws:
EmptyDataHolderException if this queue is empty

size

function size (
Void) : Number
Returns the number of enqueued elements.
Returns:
the number of enqueued elements
See also:

toArray

function toArray (
Void) : Array
Returns the array representation of this queue.

The elements are copied onto the array in a 'first-in, first-out' order, similar to the order of the elements returned by a succession of calls to the dequeue method.

Returns:
the array representation of this queue