Access keys

LinearQueue

Kind of class: class
Inherits from: BasicClass
Implements:
Author: Simon Wacker
Classpath: org.as2lib.data.holder.queue.LinearQueue
File last modified: Tuesday, 10 May 2005, 17:06:16
LinearQueue stores values in a 'first-in, first-out' manner.

This class is a linear implementation of the Queue interface. This
means that enqueued values are stored in a linear manner and that you can store
as many values as you please. There are also queues that store values in a cyclic
manner. These queues can normally only hold a prescribed number of values and
overwrite old values or throw an exception if you try to enqueue more values.

'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.

You can modify the string representation that is returned by the toString
method with the static setStringifier method.

Example:

// construct the queue
var queue:Queue = new LinearQueue();
queue.enqueue("value1");
queue.enqueue("value2");
queue.enqueue("value3");
// use the queue
trace(queue.peek());
while (!queue.isEmpty()) {
    trace(queue.pop());
}

Output:

value1
value1
value2
value3

You can alternatively pass-in the content of the queue on construction.

var queue:Queue = new LinearQueue(["value1", "value2", "value3"]);
// ..

Summary

Constructor
Instance methods
Instance methods inherited from BasicClass

Constructor

LinearQueue

function LinearQueue (
source:Array)
Constructs a new LinearQueue instance.

The queue steps through the passed-in source beginning at position 0
and enqueues all contained elements.

Example:

var queue:LinearQueue = new LinearQueue([1, 2, 3]);
while (!queue.isEmpty()) {
       trace(queue.dequeue());
}

The output is made in the following order: 1, 2, 3

Parameters:
source:
(optional) an array that contains values to populate this queue with

Class methods

getStringifier

static function getStringifier (
Void) : Stringifier
Returns the stringifier that stringifies queues.

If no stringifier has been set manually via the static setStringifier
method an instance of class QueueStringifier will be returned.

Returns:
the stringifier that stringifies queues

setStringifier

static function setStringifier (
queueStringifier:Stringifier) : Void
Sets the new stringifier that stringifies queues.

If the passed-in queueStringifier is null or undefined,
the static getStringifier method will return the default stringifier.

Parameters:
queueStringifier:
the new queue stringifier

Instance methods

dequeue

function dequeue (
Void)
Removes and returns the firstly inserted value.
Returns:
the firstly inserted value

enqueue

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

null and undefined values are allowed.

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 that can be used 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

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 an 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

toString

function toString (
) : String
Returns the string representation of this queue.

The string representation is obtained via the stringifier returned by the
static getStringifier method.

Returns:
the string representation of this queue