Packagesekati.utils
Classpublic class ArrayPeer

Helper for shortcutting searching in arrays



Public Methods
 MethodDefined by
  
ArrayPeer Static Constructor
ArrayPeer
  
find(array:Array, conditions:Object, options:Object = null):*
[static] Searches an array using simple or complex conditions.
ArrayPeer
  
findAll(array:Array, conditions:Object):Array
[static] Shortcut for searching by a single property
ArrayPeer
  
findBy(array:Array, property:String, value:Object, options:* = null):*
[static] Shortcut for searching by a single property
ArrayPeer
  
findFirst(array:Array, conditions:Object):*
[static] Shortcut for retrieving the first matching item
ArrayPeer
  
findLast(array:Array, conditions:Object):*
[static] Shortcut for retrieving the last matching item
ArrayPeer
Public Constants
 ConstantDefined by
  ALL : String = "all"
[static]
ArrayPeer
  FIRST : String = "first"
[static]
ArrayPeer
  LAST : String = "last"
[static]
ArrayPeer
Constructor detail
ArrayPeer()constructor
public function ArrayPeer()

ArrayPeer Static Constructor

Method detail
find()method
public static function find(array:Array, conditions:Object, options:Object = null):*

Searches an array using simple or complex conditions.

The conditons are evaluated and compared strictly equal and the item must match all conditions to be in the returned array.

Conditions with Class, Function or RegExp as the expected values are subject to some additional rules regarding matches.

Class
If the actual value is a Class then they are compared with ===, else the actual value will be checked to see if it is of the Class type.
Function
If the actual value is a Function then they are compared with ===, else the expected function is called with the item and the actual value as parameters. This function needs to return a Boolean. eg var condtions:Object = { someProperty: function(item: actual::Boolean { return actual != null; } }
RegExp
If the actual value is a RegExp then they are compared with ===, else the actual value is tested with the RegExp.

All other expected value are compared with ===

Parameters
array:Array
 
conditions:Object
 
options:Object (default = null)

Returns
*

Example
Some example uses
   var movies:Array = []; // retrieve from some datasource
   // find with simple property value condition
   var moviesByMichaelBay:Array = ArrayPeer.find( movies, { director: 'Michael Bay' } );
   // find with property chain condition (assuming the 'released' property returns a Date instance)
   var moviesByMichaelByReleasedIn2007:Array = ArrayPeer.find( moviesByMichaelBay, { 'released.fullYear': 2007 }
   // find with Class condition
   // todo: add example
   // find with Function condition
   var moviesWithAverageRatings:Array = ArrayPeer.find( movies, { rating: function(item:Movie, actual:Number):Boolean { return actual > 2.4 && actual < 3.7; } })
   // find with RegExp
   var moviesTheBeginWithTr:Array = ArrayPeer.find( movies, { name: new RegExp('^Tr.) });
   // find with sub-array query (assuming the 'cast' property returns an Array of Actors with the property 'name')
   var moviesWithMeganFox:Array = ArrayPeer.find( movies, { 'cast.name': 'Megan Fox' })
   

findAll()method 
public static function findAll(array:Array, conditions:Object):Array

Shortcut for searching by a single property

Parameters
array:Array
 
conditions:Object

Returns
Array
findBy()method 
public static function findBy(array:Array, property:String, value:Object, options:* = null):*

Shortcut for searching by a single property

Parameters
array:Array
 
property:String
 
value:Object
 
options:* (default = null)

Returns
*
findFirst()method 
public static function findFirst(array:Array, conditions:Object):*

Shortcut for retrieving the first matching item

Parameters
array:Array
 
conditions:Object

Returns
*
findLast()method 
public static function findLast(array:Array, conditions:Object):*

Shortcut for retrieving the last matching item

Parameters
array:Array
 
conditions:Object

Returns
*
Constant detail
ALLconstant
public static const ALL:String = "all"
FIRSTconstant 
public static const FIRST:String = "first"
LASTconstant 
public static const LAST:String = "last"