| Package | org.as3collections.utils |
| Class | public class QueueUtil |
| Inheritance | QueueUtil Object |
IQueue interface.
| Method | Defined By | ||
|---|---|---|---|
QueueUtil is a static class and shouldn't be instantiated. | QueueUtil | ||
[static]
Returns a new TypedQueue with the wrapList argument wrapped. | QueueUtil | ||
[static]
Returns a new UniqueQueue with the wrapQueue argument wrapped. | QueueUtil | ||
[static]
Returns a new TypedQueue that wraps a new UniqueQueue that wraps the wrapQueue argument. | QueueUtil | ||
| QueueUtil | () | Constructor |
public function QueueUtil()
QueueUtil is a static class and shouldn't be instantiated.
IllegalOperationError — QueueUtil is a static class and shouldn't be instantiated.
|
| getTypedQueue | () | method |
public static function getTypedQueue(wrapQueue:IQueue, type:*):TypedQueue
Returns a new TypedQueue with the wrapList argument wrapped.
Parameters
wrapQueue:IQueue — the target queue to be wrapped by the TypedQueue.
| |
type:* — the type of the elements allowed by the returned TypedQueue.
|
TypedQueue — a new TypedQueue with the queue argument wrapped.
|
ArgumentError — if the queue 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.
|
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 = QueueUtil.getTypedQueue(q1);
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
| getUniqueQueue | () | method |
public static function getUniqueQueue(wrapQueue:IQueue):UniqueQueue
Returns a new UniqueQueue with the wrapQueue argument wrapped.
Parameters
wrapQueue:IQueue — the target queue to be wrapped by the UniqueQueue.
|
UniqueQueue — a new UniqueQueue with the queue argument wrapped.
|
ArgumentError — if the queue argument is null.
|
import org.as3collections.IQueue;
import org.as3collections.queues.LinearQueue;
import org.as3collections.queues.UniqueQueue;
import org.as3collections.utils.QueueUtil;
var q1:IQueue = new LinearQueue([1, 5, 3, 7]);
var queue1:IQueue = new UniqueQueue(q1); // you can use this way
//var queue1:IQueue = QueueUtil.getUniqueQueue(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) // false
queue1 // [5,3,7,2]
queue1.add(5) // Error: UniqueQueue is a unique queue and does not allow duplicated elements. Requested element: 5
| getUniqueTypedQueue | () | method |
public static function getUniqueTypedQueue(wrapQueue:IQueue, type:*):TypedQueue
Returns a new TypedQueue that wraps a new UniqueQueue that wraps the wrapQueue argument.
The result will be a unique and typed array queue, despite of the return type TypedQueue.
Parameters
wrapQueue:IQueue — the target queue to be wrapped.
| |
type:* — the type of the elements allowed by the returned TypedQueue.
|
TypedQueue — a new TypedQueue with the queue argument wrapped.
|
ArgumentError — if the queue 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.
|
import org.as3collections.IQueue;
import org.as3collections.queues.Queue;
import org.as3collections.queues.TypedQueue;
import org.as3collections.utils.QueueUtil;
var q1:IQueue = new LinearQueue([1, 5, 3, 7]);
var queue1:IQueue = QueueUtil.getUniqueTypedQueue(q1, int);
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) // false
queue1 // [5,3,7,2]
queue1.add(5) // Error: UniqueQueue is a unique queue and does not allow duplicated elements. Requested element: 5
queue1.offer("a") // false
queue1 // [5,3,7,2]
queue1.add("a") // ClassCastError: Invalid element type. element: a | type: String | expected type: int