Packagesystem.data.queues
Classpublic class CircularQueue
InheritanceCircularQueue Inheritance Object
Implements Boundable, Queue

The CircularQueue class allows for storing objects in a circular queue of a predefined size.

Example :

     import system.data.Iterator ;
     import system.datas.queues.CircularQueue ;
     
     var q:CircularQueue = new CircularQueue(5) ;
     
     trace ("maxSize : " + q.maxSize()) ;
     trace ("enqueue item1 : " + q.enqueue ("item1")) ;
     trace ("enqueue item2 : " + q.enqueue ("item2")) ;
     trace ("enqueue item3 : " + q.enqueue ("item3")) ;
     trace ("enqueue item4 : " + q.enqueue ("item4")) ;
     trace ("enqueue item5 : " + q.enqueue ("item5")) ;
     trace ("enqueue item6 : " + q.enqueue ("item6")) ;
     
     trace ("element : " + q.element()) ;
     trace ("dequeue : " + q.dequeue()) ;
     trace ("element : " + q.element()) ;
     trace ("size : " + q.size()) ;
     trace ("isFull : " + q.isFull()) ;
     trace ("array : " + q.toArray()) ;
     
     trace("") ;
     
     trace ("queue : " + q) ;
     
     trace("") ;
     
     trace ("dequeue : " + q.dequeue()) ;
     trace ("enqueue item6 : " + q.enqueue("item6")) ;
     trace ("enqueue item7 : " + q.enqueue("item7")) ;
     trace ("peek : " + q.peek()) ;
     trace ("size : " + q.size()) ;
     trace ("isFull : " + q.isFull()) ;
     
     trace("") ;
     
     trace ("q : " + q) ;
     
     trace ("------- clone") ;
     
     var clone:CircularQueue = q.clone() ;
     
     trace ("dequeue clone : " + clone.dequeue()) ;
     trace ("enqueue clone item8 : " + clone.enqueue("item8")) ;
     trace ("original queue : " + q) ;
     trace ("clone queue : " + clone) ;
     trace ("clone iterator :") ;
     
     var i:Iterator = clone.iterator() ;
     while (i.hasNext()) 
     {
         trace ("\t+ " + i.next()) ;
     }
     
     trace("clone.toSource : " + clone.toSource()) ;
     



Public Properties
 PropertyDefined By
  MAX_CAPACITY : uint = 4.294967295E9
[static] The default numbers of elements in the queue.
CircularQueue
Public Methods
 MethodDefined By
  
CircularQueue(qSize:uint, elements:Array = null)
Creates a new CircularQueue instance.
CircularQueue
  
add(o:*):Boolean
Unsupported method in all CircularQueue objects.
CircularQueue
  
clear():void
Clear all elements in the queue.
CircularQueue
  
clone():*
Returns a shallow copy of the queue.
CircularQueue
  
contains(o:*):Boolean
Returns true if the queue contains the object passed in argument.
CircularQueue
  
dequeue():Boolean
Retreives the first element in the queue object, return a boolean.
CircularQueue
  
Returns the value of the first element in the queue.
CircularQueue
  
enqueue(o:*):Boolean
Enqueue a new element in the queue if the que is not full, return a boolean.
CircularQueue
  
get(key:*):*
Unsupported method in all CircularQueue objects.
CircularQueue
  
indexOf(o:*, fromIndex:uint = 0):int
Unsupported method in all CircularQueue objects.
CircularQueue
  
isEmpty():Boolean
Returns true if the queue is empty.
CircularQueue
  
isFull():Boolean
Returns true if the queue is full.
CircularQueue
  
Returns the iterator representation of the queue.
CircularQueue
  
maxSize():uint
Returns the max number of occurrences in the given queue.
CircularQueue
  
peek():*
Retrieves, but does not remove, the head of this queue, returning null if this queue is empty.
CircularQueue
  
poll():*
Retrieves and removes the head of this queue.
CircularQueue
  
remove(o:*):*
Unsupported method in all CircularQueue objects.
CircularQueue
  
size():uint
Returns the number of elements in the CircularQueue.
CircularQueue
  
toArray():Array
Returns the array representation of the CircularQueue.
CircularQueue
  
toSource(indent:int = 0):String
Returns the source representation of the object.
CircularQueue
  
toString():String
Returns the string representation of this instance.
CircularQueue
Property Detail
MAX_CAPACITYproperty
public static var MAX_CAPACITY:uint = 4.294967295E9

The default numbers of elements in the queue.

Constructor Detail
CircularQueue()Constructor
public function CircularQueue(qSize:uint, elements:Array = null)

Creates a new CircularQueue instance.

Parameters
qSize:uint (default = NaN) — the max number of element in the queue
 
elements:Array (default = null) — an array with elements to enqueue in the current stack.
Method Detail
add()method
public function add(o:*):Boolean

Unsupported method in all CircularQueue objects.

Parameters

o:*

Returns
Boolean

Throws
IllegalOperationError — the add() method is unsupported in a CircularQueue instance.
clear()method 
public function clear():void

Clear all elements in the queue.

clone()method 
public function clone():*

Returns a shallow copy of the queue.

Returns
* — a shallow copy of the queue.
contains()method 
public function contains(o:*):Boolean

Returns true if the queue contains the object passed in argument.

Parameters

o:*

Returns
Booleantrue if the queue contains the object passed in argument.
dequeue()method 
public function dequeue():Boolean

Retreives the first element in the queue object, return a boolean.

Returns
Booleantrue if the first element in the queue is dequeue.
element()method 
public function element():*

Returns the value of the first element in the queue.

Returns
* — the value of the first element in the queue.
enqueue()method 
public function enqueue(o:*):Boolean

Enqueue a new element in the queue if the que is not full, return a boolean.

Parameters

o:*

Returns
Boolean
get()method 
public function get(key:*):*

Unsupported method in all CircularQueue objects.

Parameters

key:*

Returns
*

Throws
IllegalOperationError — the get() method is unsupported in a CircularQueue instance.
indexOf()method 
public function indexOf(o:*, fromIndex:uint = 0):int

Unsupported method in all CircularQueue objects.

Parameters

o:*
 
fromIndex:uint (default = 0)

Returns
int

Throws
IllegalOperationError — the indexOf() method is unsupported in a CircularQueue instance.
isEmpty()method 
public function isEmpty():Boolean

Returns true if the queue is empty.

Returns
Booleantrue if the queue is empty.
isFull()method 
public function isFull():Boolean

Returns true if the queue is full.

Returns
Booleantrue if the queue is full.
iterator()method 
public function iterator():Iterator

Returns the iterator representation of the queue.

Returns
Iterator — the iterator representation of the queue.

See also

maxSize()method 
public function maxSize():uint

Returns the max number of occurrences in the given queue.

Returns
uint — the max number of occurrences in the given queue.
peek()method 
public function peek():*

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

Returns
*
poll()method 
public function poll():*

Retrieves and removes the head of this queue.

Returns
*
remove()method 
public function remove(o:*):*

Unsupported method in all CircularQueue objects.

Parameters

o:*

Returns
*

Throws
IllegalOperationError — the remove() method is unsupported in a CircularQueue instance.
size()method 
public function size():uint

Returns the number of elements in the CircularQueue.

Returns
uint — the number of elements in the CircularQueue.
toArray()method 
public function toArray():Array

Returns the array representation of the CircularQueue.

Returns
Array — the array representation of the CircularQueue.
toSource()method 
public function toSource(indent:int = 0):String

Returns the source representation of the object.

Parameters

indent:int (default = 0)

Returns
String — the source representation of the object.
toString()method 
public function toString():String

Returns the string representation of this instance.

Returns
String — the string representation of this instance