Queue
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.
new 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.
type | the type of the values that are allowed to be added |
queue | the queue to wrap |
| IllegalArgumentException | if the passed-in type is null
or undefined
|
| IllegalArgumentException | if queue is null or
undefined
|
public function getType(Void):FunctionReturns the type that all values in the wrapped queue have.
This is the type passed-in on construction.
the type the all values of the wrapped queue have
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.
value | the value to add |
| IllegalArgumentException | if the type of the passed-in value is
invalid
|
public function dequeue(Void)Removes the firstly inserted value.
the firstly inserted value
| EmptyDataHolderException | if this queue is empty |
public function peek(Void)Returns the firstly inserted value.
the firstly inserted value
| EmptyDataHolderException | if this queue is empty |
public function iterator(Void):IteratorReturns an iterator that can be used to iterate over the values of this queue.
an iterator to iterate over this queue's values
iterator() in org.as2lib.data.holder.Queue
public function isEmpty(Void):BooleanReturns whether this queue contains any values.
true if this queue contains no values else false
public function size(Void):NumberReturns the number of enqueued elements.
the number of enqueued elements
size() in org.as2lib.data.holder.Queue
public function toArray(Void):ArrayReturns 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.
the array representation of this queue
public function toString():StringReturns the string representation of the wrapped queue.
the string representation of the wrapped queue
toString() in org.as2lib.core.BasicInterface