Package | org.as3collections.queues |
Class | public class UniqueQueue |
Inheritance | UniqueQueue UniqueCollection Object |
Implements | IQueue |
UniqueQueue
works as a wrapper for a queue.
It does not allow duplicated elements in the queue.
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 duplication are previously validated before forward the call.
The calls that are forwarded to the wrappedQueue
returns the return of the wrappedQueue
call.
You can also create unique and typed queues. See below the link "QueueUtil.getUniqueTypedQueue()".
See also
Method | Defined By | ||
---|---|---|---|
UniqueQueue(wrapQueue:IQueue)
Constructor, creates a new UniqueQueue object. | UniqueQueue | ||
add(element:*):Boolean [override]
Inserts the specified element into this queue if it is possible to do so immediately without violating restrictions. | UniqueQueue | ||
addAll(collection:ICollection):Boolean
If the specified collection is empty returns false. | UniqueCollection | ||
clear():void
Forwards the call to wrappedCollection.clear. | UniqueCollection | ||
clone():* [override]
Creates and return a new UniqueQueue object with the clone of the wrappedQueue object. | UniqueQueue | ||
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains. | UniqueCollection | ||
containsAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.containsAll. | UniqueCollection | ||
dequeue():*
Forwards the call to wrappedQueue.dequeue. | UniqueQueue | ||
element():*
Forwards the call to wrappedQueue.element. | UniqueQueue | ||
equals(other:*):Boolean [override]
This method uses CollectionUtil.equalConsideringOrder method to perform equality, sending this list and other argument. | UniqueQueue | ||
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty. | UniqueCollection | ||
Forwards the call to wrappedCollection.iterator. | UniqueCollection | ||
offer(element:*):Boolean
If wrappedQueue.contains(element) returns true then returns false. | UniqueQueue | ||
peek():*
Forwards the call to wrappedQueue.peek. | UniqueQueue | ||
poll():*
Forwards the call to wrappedQueue.poll. | UniqueQueue | ||
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove. | UniqueCollection | ||
removeAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.removeAll. | UniqueCollection | ||
retainAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.retainAll. | UniqueCollection | ||
size():int
Forwards the call to wrappedCollection.size. | UniqueCollection | ||
toArray():Array
Forwards the call to wrappedCollection.toArray. | UniqueCollection | ||
toString():String
Returns the string representation of this instance. | UniqueCollection |
UniqueQueue | () | Constructor |
public function UniqueQueue(wrapQueue:IQueue)
Constructor, creates a new UniqueQueue
object.
wrapQueue:IQueue — the target queue to wrap.
|
ArgumentError — if the wrapQueue argument is null .
|
add | () | method |
override public function add(element:*):Boolean
Inserts the specified element into this queue if it is possible to do so immediately without violating restrictions.
This method differs from offer
only in that it throws an error if the element cannot be inserted.
This implementation returns the result of offer
unless the element cannot be inserted.
If wrappedQueue.contains(element)
returns true
an IllegalOperationError
is thrown.
Parameters
element:* — the element to be added.
|
Boolean — true if this queue changed as a result of the call.
|
ArgumentError — if the specified element is null .
| |
org.as3coreaddendum.errors:ClassCastError — if the class of the specified element prevents it from being added to this queue.
| |
flash.errors:IllegalOperationError — if wrappedQueue.contains(element) returns true .
|
clone | () | method |
override public function clone():*
Creates and return a new UniqueQueue
object with the clone of the wrappedQueue
object.
* — a new UniqueQueue 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 uses CollectionUtil.equalConsideringOrder
method to perform equality, sending this list 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 wrappedQueue.contains(element)
returns true
then returns false
.
Otherwise, it forwards the call to wrappedQueue.offer
.
Parameters
element:* — the element to forward to wrappedQueue.offer .
|
Boolean — false if wrappedQueue.contains(element) returns true . 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.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