Packageorg.as3collections.queues
Classpublic class LinearQueue
InheritanceLinearQueue Inheritance AbstractQueue Inheritance AbstractArrayCollection Inheritance Object
Subclasses SortedQueue

LinearQueue orders elements in a FIFO (first-in-first-out) manner.

LinearQueue does not allow null elements.

View the examples



Public Properties
 PropertyDefined By
 InheritedallEquatable : Boolean
[read-only] Indicates whether all elements in this collection implement the interface org.as3coreaddendum.system.IEquatable.
AbstractArrayCollection
Public Methods
 MethodDefined By
  
LinearQueue(source:Array = null)
Constructor, creates a new LinearQueue object.
LinearQueue
 Inherited
add(element:*):Boolean
[override] Inserts the specified element into this queue if it is possible to do so immediately without violating restrictions.
AbstractQueue
 Inherited
addAll(collection:ICollection):Boolean
Adds all of the elements in the specified collection to this collection (optional operation).
AbstractArrayCollection
  
clear():void
[override] Removes all of the elements from this queue.
LinearQueue
  
clone():*
[override] Creates and return a new LinearQueue object containing all elements in this queue (in the same order).
LinearQueue
 Inherited
contains(o:*):Boolean
Returns true if this collection contains the specified object.
AbstractArrayCollection
 Inherited
containsAll(collection:ICollection):Boolean
Returns true if this collection contains all of the elements in the specified collection.
AbstractArrayCollection
 Inherited
Retrieves and removes the head of this queue.
AbstractQueue
 Inherited
Retrieves, but does not remove, the head of this queue.
AbstractQueue
 Inherited
equals(other:*):Boolean
[override] This method uses CollectionUtil.equalConsideringOrder method to perform equality, sending this list and other argument.
AbstractQueue
 Inherited
isEmpty():Boolean
Returns true if this collection contains no elements.
AbstractArrayCollection
  
[override] Returns an iterator over a set of elements.
LinearQueue
  
offer(element:*):Boolean
[override] Inserts the specified element into this queue if it is possible to do so immediately without violating restrictions.
LinearQueue
  
peek():*
[override] Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
LinearQueue
  
poll():*
[override] Retrieves and removes the head of this queue, or returns null if this queue is empty.
LinearQueue
 Inherited
remove(o:*):Boolean
Removes a single instance (only one occurrence) of the specified object from this collection, if it is present (optional operation).
AbstractArrayCollection
 Inherited
removeAll(collection:ICollection):Boolean
Removes all of this collection's elements that are also contained in the specified collection (optional operation).
AbstractArrayCollection
 Inherited
retainAll(collection:ICollection):Boolean
Retains only the elements in this collection that are contained in the specified collection (optional operation).
AbstractArrayCollection
 Inherited
size():int
Returns the number of elements in this collection.
AbstractArrayCollection
 Inherited
toArray():Array
Returns an array containing all of the elements in this collection.
AbstractArrayCollection
 Inherited
toString():String
Returns the string representation of this instance.
AbstractArrayCollection
Constructor Detail
LinearQueue()Constructor
public function LinearQueue(source:Array = null)

Constructor, creates a new LinearQueue object.

Parameters
source:Array (default = null) — an array to fill the queue.
Method Detail
clear()method
override public function clear():void

Removes all of the elements from this queue. The queue will be empty after this method returns.

clone()method 
override public function clone():*

Creates and return a new LinearQueue object containing all elements in this queue (in the same order).

Returns
* — a new LinearQueue object containing all elements in this queue (in the same order).
iterator()method 
override public function iterator():IIterator

Returns an iterator over a set of elements.

This implementation returns an ArrayIterator object.

Returns
IIterator — an iterator over a set of elements.

See also

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

Inserts the specified element into this queue if it is possible to do so immediately without violating restrictions. When using a restricted queue (like TypedQueue and UniqueQueue), this method is generally preferable to add, which can fail to insert an element only by throwing an error.

This implementation adds the element to the tail of the queue.

Parameters

element:* — the element to add.

Returns
Booleantrue if the element was added to this queue, else false.
peek()method 
override public function peek():*

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Returns
* — the head of this queue, or null if this queue is empty.
poll()method 
override public function poll():*

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns
* — the head of this queue, or null if this queue is empty.
Examples
Example 1
     import org.as3collections.IQueue;
     import org.as3collections.queues.LinearQueue;
     
     var queue:IQueue = new LinearQueue();
     
     queue                       // []
     queue.size()                // 0
     queue.isEmpty()             // true
     
     queue.peek()                // null
     queue.element()             // NoSuchElementError: The queue is empty.
     
     queue.offer(3)              // true
     queue                       // [3]
     queue.size()                // 1
     queue.isEmpty()             // false
     
     queue.offer("a")            // true
     queue                       // [3,a]
     
     queue.offer(1)              // true
     queue                       // [3,a,1]
     
     queue.offer(7)              // true
     queue                       // [3,a,1,7]
     
     queue.offer(null)           // false
     queue.add(null)             // ArgumentError: The 'element' argument must not be 'null'.
     queue                       // [3,a,1,7]
     
     queue.peek()                // 3
     queue.element()             // 3
     queue:                      // [3,a,1,7]
     
     queue.poll()                // 3
     queue                       // [a,1,7]
     
     queue.dequeue()             // a
     queue                       // [1,7]
     
     queue.remove(10)            // false
     queue                       // [1,7]
     
     queue.remove(7)             // true
     queue                       // [1]
     
     queue.clear()
     queue                       // []
     queue.size()                // 0
     queue.isEmpty()             // true
     
     queue.poll()                // null
     queue.dequeue()             // NoSuchElementError: The queue is empty.
     
Example 2
     import org.as3collections.IQueue;
     import org.as3collections.queues.LinearQueue;
     
     var queue1:IQueue = new LinearQueue([1, 5, 3, 7]);
     
     queue1                      // [1,5,3,7]
     queue1.size()               // 4
     queue1.isEmpty()            // false
     
     var queue2:IQueue = queue1.clone();
     
     queue2                      // [1,5,3,7]
     queue2.size()               // 4
     queue2.isEmpty()            // false
     
     queue2.equals(queue1)       // true
     queue1.equals(queue2)       // true
     
     queue2.poll()               // 1
     queue2                      // [5,3,7]
     
     queue2.equals(queue1)       // false
     queue1.equals(queue2)       // false
     queue2.equals(queue2)       // true
     
     queue1.clear()
     queue1                      // []
     
     queue2.clear()
     queue2:                     // []
     
     queue2.equals(queue1)       // true