Interface org.as2lib.data.holder.Queue

org.as2lib.core.BasicInterface
   +--org.as2lib.data.holder.Queue

Description

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
 

Method Index

dequeue(), enqueue(), isEmpty(), iterator(), peek(), size(), toArray()

Inherited from BasicInterface

toString()

Method Detail

enqueue

public function enqueue(value):Void

Adds the passed-in value to this queue.

Parameters

valuethe value to add

dequeue

public function dequeue(Void)

Removes and returns the firstly inserted value.

Return

the firstly inserted value

Throws

EmptyDataHolderExceptionif this queue is empty

peek

public function peek(Void)

Returns the firstly inserted value.

Return

the firstly inserted value

Throws

EmptyDataHolderExceptionif this queue is empty

iterator

public function iterator(Void):Iterator

Returns an iterator to iterate over the values of this queue.

Return

an iterator to iterate over this queue's values

isEmpty

public function isEmpty(Void):Boolean

Returns whether this queue contains any values.

Return

true if this queue contains no values else false

size

public function size(Void):Number

Returns the number of enqueued elements.

Return

the number of enqueued elements

toArray

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

Return

the array representation of this queue