Package | org.as3collections.queues |
Class | public class TypedQueue |
Inheritance | TypedQueue TypedCollection 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()".
See also
Method | Defined 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 | ||
addAll(collection:ICollection):Boolean
The collection is validated with the validateCollection method to be forwarded to wrappedCollection.addAll. | TypedCollection | ||
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 | ||
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains. | TypedCollection | ||
containsAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.containsAll. | TypedCollection | ||
dequeue():*
Forwards the call to wrappedQueue.dequeue. | TypedQueue | ||
element():*
Forwards the call to wrappedQueue.element. | TypedQueue | ||
equals(other:*):Boolean [override]
This method first checks if other argument is a TypedQueue. | TypedQueue | ||
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty. | TypedCollection | ||
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 | ||
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove. | TypedCollection | ||
removeAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.removeAll. | TypedCollection | ||
retainAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.retainAll. | TypedCollection | ||
size():int
Forwards the call to wrappedCollection.size. | TypedCollection | ||
toArray():Array
Forwards the call to wrappedCollection.toArray. | TypedCollection | ||
toString():String
Returns the string representation of this instance. | TypedCollection |
TypedQueue | () | Constructor |
public function TypedQueue(wrapQueue:IQueue, type:*)
Constructor, creates a new TypedQueue
object.
wrapQueue:IQueue — the target queue to wrap.
| |
type:* — the type of the elements allowed by this queue.
|
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.
|
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 .
|
Boolean — the return of the call wrappedCollection.add .
|
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.
* — a new TypedQueue object with the clone of the wrappedQueue object.
|
dequeue | () | method |
public function dequeue():*
Forwards the call to wrappedQueue.dequeue
.
* — the return of the call wrappedQueue.dequeue .
|
element | () | method |
public function element():*
Forwards the call to wrappedQueue.element
.
* — 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.
|
Boolean — true 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 .
|
Boolean — false 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
.
* — the return of the call wrappedQueue.peek .
|
poll | () | method |
public function poll():*
Forwards the call to wrappedQueue.poll
.
* — the return of the call wrappedQueue.poll .
|
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