Packageorg.as3collections.queues
Classpublic class UniqueQueue
InheritanceUniqueQueue Inheritance UniqueCollection Inheritance 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()".

View the examples

See also

QueueUtil.getUniqueQueue()
QueueUtil.getUniqueTypedQueue()


Public Properties
 PropertyDefined By
 InheritedallEquatable : Boolean
[read-only] Indicates whether all elements in this collection implement the interface org.as3coreaddendum.system.IEquatable.
UniqueCollection
Public Methods
 MethodDefined 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
 Inherited
addAll(collection:ICollection):Boolean
If the specified collection is empty returns false.
UniqueCollection
 Inherited
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
 Inherited
contains(o:*):Boolean
Forwards the call to wrappedCollection.contains.
UniqueCollection
 Inherited
containsAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.containsAll.
UniqueCollection
  
Forwards the call to wrappedQueue.dequeue.
UniqueQueue
  
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
 Inherited
isEmpty():Boolean
Forwards the call to wrappedCollection.isEmpty.
UniqueCollection
 Inherited
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
 Inherited
remove(o:*):Boolean
Forwards the call to wrappedCollection.remove.
UniqueCollection
 Inherited
removeAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.removeAll.
UniqueCollection
 Inherited
retainAll(collection:ICollection):Boolean
Forwards the call to wrappedCollection.retainAll.
UniqueCollection
 Inherited
size():int
Forwards the call to wrappedCollection.size.
UniqueCollection
 Inherited
toArray():Array
Forwards the call to wrappedCollection.toArray.
UniqueCollection
 Inherited
toString():String
Returns the string representation of this instance.
UniqueCollection
Constructor Detail
UniqueQueue()Constructor
public function UniqueQueue(wrapQueue:IQueue)

Constructor, creates a new UniqueQueue object.

Parameters
wrapQueue:IQueue — the target queue to wrap.

Throws
ArgumentError — if the wrapQueue argument is null.
Method Detail
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.

Returns
Booleantrue if this queue changed as a result of the call.

Throws
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.

Returns
* — a new UniqueQueue 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 uses CollectionUtil.equalConsideringOrder method to perform equality, sending this list 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 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.

Returns
Booleanfalse 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.

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.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