Class org.as2lib.data.holder.queue.LinearQueue

org.as2lib.core.BasicClass
   +--org.as2lib.data.holder.queue.LinearQueue

Implemented Interfaces

Queue

Description

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"]); // ..

Method Index

new LinearQueue()

dequeue(), enqueue(), getStringifier(), isEmpty(), iterator(), peek(), setStringifier(), size(), toArray(), toString()

Constructor Detail

LinearQueue

public 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

Method Detail

getStringifier

static public 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.

Return

the stringifier that stringifies queues

setStringifier

static public 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

queueStringifierthe new queue stringifier

enqueue

public function enqueue(value):Void

Adds the passed-in value to this queue.

null and undefined values are allowed.

Parameters

valuethe value to add

Specified By

enqueue() in org.as2lib.data.holder.Queue

dequeue

public function dequeue(Void)

Removes and returns the firstly inserted value.

Return

the firstly inserted value

Throws

EmptyDataHolderExceptionif this queue is empty

Specified By

dequeue() in org.as2lib.data.holder.Queue

peek

public function peek(Void)

Returns the firstly inserted value.

Return

the firstly inserted value

Throws

EmptyDataHolderExceptionif this queue is empty

Specified By

peek() in org.as2lib.data.holder.Queue

iterator

public function iterator(Void):Iterator

Returns an iterator that can be used to iterate over the values of this queue.

Return

an iterator to iterate over this queue's values

Specified By

iterator() in org.as2lib.data.holder.Queue

isEmpty

public function isEmpty(Void):Boolean

Returns whether this queue contains any values.

Return

true if this queue contains no values else false

Specified By

isEmpty() in org.as2lib.data.holder.Queue

size

public function size(Void):Number

Returns the number of enqueued elements.

Return

the number of enqueued elements

Specified By

size() in org.as2lib.data.holder.Queue

toArray

public 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. ################################################################################

Return

the array representation of this queue

Specified By

toArray() in org.as2lib.data.holder.Queue

toString

public function toString():String

Returns the string representation of this queue.

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

Return

the string representation of this queue

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in org.as2lib.core.BasicClass