Packagecom.developmentarc.framework.datastructures.utils
Classpublic class Queue

The Queue is a datastructure that allows items to be added in a specified order then retrived by calling the next() method. The Queue is defined as either "First in First Out" (FIFO) or "Last in First Out" (LIFO). A FIFO structure removes items in the order they were added, the first item added will be the first item returned when next() is called. A LIFO strucutre returns the last item added when next() is called.



Public Properties
 PropertyDefined by
  hasItems : Boolean
[read-only] Used to determine if items are currently stored inside the Queue.
Queue
  length : int
[read-only] The number of items currently in the Queue.
Queue
Public Methods
 MethodDefined by
  
Queue(direction:String)
Creates a new Queue passing in the direction of Queue.
Queue
  
add(item:*):void
Adds an item to the Queue.
Queue
  
addAt(item:*, position:int = -1):void
Adds an item to the Queue at the location specified.
Queue
  
last():*
This method is used to access the last item in the Queue depending upon the direction of the Queue.
Queue
  
next():*
This method is used to access the next item in the Queue depending upon the direction of the Queue.
Queue
  
remove(item:*, numberOfItems:int):void
Removes the specfied item from the queue.
Queue
  
removeAll():void
Removes all items from the queue.
Queue
  
removeAt(position:int):Boolean
Removes an item at the specified position.
Queue
Public Constants
 ConstantDefined by
  FIFO : String = "FIFO"
[static]
Queue
  LIFO : String = "LIFO"
[static]
Queue
Property detail
hasItemsproperty
hasItems:Boolean  [read-only]

Used to determine if items are currently stored inside the Queue.

Implementation
    public function get hasItems():Boolean
lengthproperty 
length:int  [read-only]

The number of items currently in the Queue.

Implementation
    public function get length():int
Constructor detail
Queue()constructor
public function Queue(direction:String)

Creates a new Queue passing in the direction of Queue. The default direction is FIFO, accepted values are FIFO and LIFO.

Parameters
direction:String — The order items are removed by the nex() call.
Method detail
add()method
public function add(item:*):void

Adds an item to the Queue. The order the items are added to the queue is important because this determines the order they are removed when next() is called.

Parameters
item:* — The item to add to the end of the Queue.
addAt()method 
public function addAt(item:*, position:int = -1):void

Adds an item to the Queue at the location specified. If the value is less then zero the item is put at the beginning of the queue. If the value is equal to or greater then the length of the Queue then the item is put at the end of the Queue.

Parameters
item:* — The item to add to the Queue.
 
position:int (default = -1) — The position to place the item at.
last()method 
public function last():*

This method is used to access the last item in the Queue depending upon the direction of the Queue. If the Queue is typed FIFO (default) the last item in the Queue, i.e. length -1, is returned. If the the Queue is typed LIFO then the first item in the queue, i.e. position 0, is returned.

Returns
* — The last item in the Queue dependent upon the direction.
next()method 
public function next():*

This method is used to access the next item in the Queue depending upon the direction of the Queue. If the Queue is typed FIFO (default) the first item in the Queue, i.e. position 0, is returned. If the the Queue is typed LIFO then the last item in the queue, i.e. position length -1, is returned.

Returns
* — The next item in the Queue dependent upon the direction.
remove()method 
public function remove(item:*, numberOfItems:int):void

Removes the specfied item from the queue. If the item is in the Queue more then one time then the numberOfItems value is used to determine how many of the repeated items should be remove. The default is all items are removed from the queue. Passing 1 or more will then determine how many times the item is removed.

The order items are removed depends on the direction of the the Queue. If the Queue is FIFO then the removal starts at the beginning of the Queue to find items to remove. If the Queue is LIFO the method starts at the end of the Queue and works forward.

Parameters
item:* — The item to find and remove.
 
numberOfItems:int — The number of instances of the item to remove.
removeAll()method 
public function removeAll():void

Removes all items from the queue.

removeAt()method 
public function removeAt(position:int):Boolean

Removes an item at the specified position. If the position is invalid then a false value is returned stating that the item was not removed at the provided position. If the position is valid the method returns a true for success.

Parameters
position:int — The position in the Queue to remove.

Returns
Boolean — True for successful removal, false for an invalid position.
Constant detail
FIFOconstant
public static const FIFO:String = "FIFO"
LIFOconstant 
public static const LIFO:String = "LIFO"