Package | org.as3collections.queues |
Class | public class LinearQueue |
Inheritance | LinearQueue AbstractQueue AbstractArrayCollection Object |
Subclasses | SortedQueue |
LinearQueue
orders elements in a FIFO (first-in-first-out) manner.
LinearQueue
does not allow null
elements.
Method | Defined By | ||
---|---|---|---|
LinearQueue(source:Array = null)
Constructor, creates a new LinearQueue object. | LinearQueue | ||
add(element:*):Boolean [override]
Inserts the specified element into this queue if it is possible to do so immediately without violating restrictions. | AbstractQueue | ||
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 | ||
contains(o:*):Boolean
Returns true if this collection contains the specified object. | AbstractArrayCollection | ||
containsAll(collection:ICollection):Boolean
Returns true if this collection contains all of the elements in the specified collection. | AbstractArrayCollection | ||
dequeue():*
Retrieves and removes the head of this queue. | AbstractQueue | ||
element():*
Retrieves, but does not remove, the head of this queue. | AbstractQueue | ||
equals(other:*):Boolean [override]
This method uses CollectionUtil.equalConsideringOrder method to perform equality, sending this list and other argument. | AbstractQueue | ||
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 | ||
remove(o:*):Boolean
Removes a single instance (only one occurrence) of the specified object from this collection, if it is present (optional operation). | AbstractArrayCollection | ||
removeAll(collection:ICollection):Boolean
Removes all of this collection's elements that are also contained in the specified collection (optional operation). | AbstractArrayCollection | ||
retainAll(collection:ICollection):Boolean
Retains only the elements in this collection that are contained in the specified collection (optional operation). | AbstractArrayCollection | ||
size():int
Returns the number of elements in this collection. | AbstractArrayCollection | ||
toArray():Array
Returns an array containing all of the elements in this collection. | AbstractArrayCollection | ||
toString():String
Returns the string representation of this instance. | AbstractArrayCollection |
LinearQueue | () | Constructor |
public function LinearQueue(source:Array = null)
Constructor, creates a new LinearQueue
object.
source:Array (default = null ) — an array to fill the queue.
|
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).
* — 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.
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.
|
Boolean — true 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.
* — 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.
* — the head of this queue, or null if this queue is empty.
|
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.
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