Packageorg.as3collections.queues
Classpublic class TypedQueue
InheritanceTypedQueue Inheritance TypedCollection Inheritance Object
Implements IQueue

TypedQueue works as a wrapper for a queue. Since ActionScript 3.0 does not support typed arrays, TypedQueue is a way to create typed queues. It stores the wrapQueue constructor's argument in the wrappedQueue variable. So every method call to this class is forwarded to the wrappedQueue object. The methods that need to be checked for the type of the elements are previously validated with the validateType or validateCollection method before forward the call. If the type of an element requested to be added to this list is incompatible with the type of the list, the method offer returns false and the method add throws org.as3coreaddendum.errors.ClassCastError. The calls that are forwarded to the wrappedQueue returns the return of the wrappedQueue call.

TypedQueue does not allow null elements.

You can also create unique and typed queues. See below the link "QueueUtil.getUniqueTypedQueue()".

View the examples

See also

QueueUtil.getTypedQueue()
QueueUtil.getUniqueTypedQueue()


Public Properties
 PropertyDefined By
 InheritedallEquatable : Boolean
[read-only] Indicates whether all elements in this collection implement the interface org.as3coreaddendum.system.IEquatable.
TypedCollection
 Inheritedtype : *
Defines the acceptable type of the elements by this collection.
TypedCollection
Public Methods
 MethodDefined By
  
TypedQueue(wrapQueue:IQueue, type:*)
Constructor, creates a new TypedQueue object.
TypedQueue
  
add(element:*):Boolean
[override] If the element argument is null throws ArgumentError.
TypedQueue
 Inherited
addAll(collection:ICollection):Boolean
The collection is validated with the validateCollection method to be forwarded to wrappedCollection.addAll.
TypedCollection
 Inherited
clear():void
Forwards the call to wrappedCollection.clear.
TypedCollection
  
clone():*
[override] Creates and return a new TypedQueue object with the clone of the wrappedQueue object.
TypedQueue
 Inherited
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains.
TypedCollection
 Inherited
containsAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.containsAll.
TypedCollection
  
Forwards the call to wrappedQueue.dequeue.
TypedQueue
  
Forwards the call to wrappedQueue.element.
TypedQueue
  
equals(other:*):Boolean
[override] This method first checks if other argument is a TypedQueue.
TypedQueue
 Inherited
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty.
TypedCollection
 Inherited
Forwards the call to wrappedCollection.iterator.
TypedCollection
  
offer(element:*):Boolean
If isValidType(element) returns false then returns false.
TypedQueue
  
peek():*
Forwards the call to wrappedQueue.peek.
TypedQueue
  
poll():*
Forwards the call to wrappedQueue.poll.
TypedQueue
 Inherited
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove.
TypedCollection
 Inherited
removeAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.removeAll.
TypedCollection
 Inherited
retainAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.retainAll.
TypedCollection
 Inherited
size():int
Forwards the call to wrappedCollection.size.
TypedCollection
 Inherited
toArray():Array
Forwards the call to wrappedCollection.toArray.
TypedCollection
 Inherited
toString():String
Returns the string representation of this instance.
TypedCollection
Constructor Detail
TypedQueue()Constructor
public function TypedQueue(wrapQueue:IQueue, type:*)

Constructor, creates a new TypedQueue object.

Parameters
wrapQueue:IQueue — the target queue to wrap.
 
type:* — the type of the elements allowed by this queue.

Throws
ArgumentError — if the wrapQueue argument is null.
 
ArgumentError — if the type argument is null.
 
org.as3coreaddendum.errors:ClassCastError — if the types of one or more elements in the wrapQueue argument are incompatible with the type argument.
Method Detail
add()method
override public function add(element:*):Boolean

If the element argument is null throws ArgumentError. Otherwise the element is validated with the validateType method to be forwarded to wrappedCollection.add.

Parameters

element:* — the element to forward to wrappedCollection.add.

Returns
Boolean — the return of the call wrappedCollection.add.

Throws
ArgumentError — if the element argument is null.
 
org.as3coreaddendum.errors:ClassCastError — if the type of the element is incompatible with the type of this collection.
clone()method 
override public function clone():*

Creates and return a new TypedQueue object with the clone of the wrappedQueue object.

Returns
* — a new TypedQueue object with the clone of the wrappedQueue object.
dequeue()method 
public function dequeue():*

Forwards the call to wrappedQueue.dequeue.

Returns
* — the return of the call wrappedQueue.dequeue.
element()method 
public function element():*

Forwards the call to wrappedQueue.element.

Returns
* — the return of the call wrappedQueue.element.
equals()method 
override public function equals(other:*):Boolean

This method first checks if other argument is a TypedQueue. If not it returns false. If true it checks the type property of both queues. If they are different it returns false. Otherwise it uses CollectionUtil.equalConsideringOrder method to perform equality, sending this queue and other argument.

Parameters

other:* — the object to be compared for equality.

Returns
Booleantrue if the arbitrary evaluation considers the objects equal.

See also

offer()method 
public function offer(element:*):Boolean

If isValidType(element) returns false then returns false. Otherwise, it forwards the call to wrappedQueue.offer.

Parameters

element:* — the element to forward to wrappedQueue.offer.

Returns
Booleanfalse if isValidType(element) returns false. Otherwise returns the return of the call wrappedQueue.offer.
peek()method 
public function peek():*

Forwards the call to wrappedQueue.peek.

Returns
* — the return of the call wrappedQueue.peek.
poll()method 
public function poll():*

Forwards the call to wrappedQueue.poll.

Returns
* — the return of the call wrappedQueue.poll.
Examples
     import org.as3collections.IQueue;
     import org.as3collections.queues.LinearQueue;
     import org.as3collections.queues.TypedQueue;
     import org.as3collections.utils.QueueUtil;
     
     var q1:IQueue = new LinearQueue([1, 5, 3, 7]);
     
     var queue1:IQueue = new TypedQueue(q1, int); // you can use this way
     
     //var queue1:IQueue = QueueUtil.getTypedQueue(q1); // or you can use this way
     
     queue1                      // [1,5,3,7]
     queue1.size():              // 4
     queue1.isEmpty()            // false
     
     queue1.poll()               // 1
     queue1                      // [5,3,7]
     
     queue1.offer(2)             // true
     queue1                      // [5,3,7,2]
     
     queue1.offer(5)             // true
     queue1                      // [5,3,7,2,5]
     
     queue1.offer("a")           // false
     queue1                      // [5,3,7,2,5]
     
     queue1.add("a")             // ClassCastError: Invalid element type. element: a | type: String | expected type: int