Class org.as2lib.data.holder.queue.TypedQueue

Implemented Interfaces

Queue

Description

TypedQueue is a wrapper for Queue instances that ensures that only values of a specific type can be added to the wrapped queue.

This class simply delegates all method invocations to the wrapped queue. If the specific method is responsible for adding values it first checks if the values to add are of the expected type. If they are the method invocation is forwarded, otherwise an IllegalArgumentException is thrown.

Method Index

new TypedQueue()
dequeue(), enqueue(), getType(), isEmpty(), iterator(), peek(), size(), toArray(), toString()

Constructor Detail

TypedQueue

public function TypedQueue(type:Function, queue:Queue)

Constructs a new TypedQueue instance.

If the passed-in queue does already contain values, these values do not get type-checked.

Parameters

typethe type of the values that are allowed to be added
queuethe queue to wrap

Throws

IllegalArgumentExceptionif the passed-in type is null or undefined
IllegalArgumentExceptionif queue is null or undefined

Method Detail

getType

public function getType(Void):Function

Returns the type that all values in the wrapped queue have.

This is the type passed-in on construction.

Return

the type the all values of the wrapped queue have

enqueue

public function enqueue(value):Void

Adds the passed-in value to this queue.

The value is only enqueued if it is of the expected type.

Parameters

valuethe value to add

Throws

IllegalArgumentExceptionif the type of the passed-in value is invalid

Specified By

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

dequeue

public function dequeue(Void)

Removes 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

See Also

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

See Also

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 the wrapped queue.

Return

the string representation of the wrapped queue

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in org.as2lib.core.BasicClass