| Package | net.guttershark.util |
| Class | public final class ArrayUtils |
See also
| Method | Defined by | ||
|---|---|---|---|
|
asearch(array:Array, conditions:Object, options:Object = null):*
Advanced array searching with complex matching conditions.
| ArrayUtils | ||
|
asearchAll(array:Array, conditions:Object):Array
Shortcut for advanced searching by a single property.
| ArrayUtils | ||
|
asearchBy(array:Array, property:String, value:Object, options:* = null):*
Shortcut for advanced searching by a single property.
| ArrayUtils | ||
|
asearchFirst(array:Array, conditions:Object):*
Shortcut for advanced searching for the first matching item.
| ArrayUtils | ||
|
asearchLast(array:Array, conditions:Object):*
Shortcut for advanced searching for the last matching item.
| ArrayUtils | ||
|
clone(array:Array):Array
Clones an array.
| ArrayUtils | ||
|
compare(a:Array, b:Array, ordered:Boolean = false):Boolean
Compare two arrays to see if their values (and optionally order) are identical.
| ArrayUtils | ||
|
contains(a:Array, element:Object):Boolean
Determines if a value exists within the array.
| ArrayUtils | ||
|
equals(arr1:Array, arr2:Array):Boolean
Determine if one array is identical to the other array.
| ArrayUtils | ||
|
gi():ArrayUtils
[static]
Singleton access.
| ArrayUtils | ||
|
insert(a:Array, element:Object, index:int):Array
Insert an element into an array at a specific index.
| ArrayUtils | ||
|
locatePropVal(a:Array, prop:String, val:Object, caseInsensitive:Boolean = false):Object
Search for a unique property/value match in an array of complex objects.
| ArrayUtils | ||
|
locatePropValIndex(a:Array, prop:String, val:Object, caseInsensitive:Boolean = false):int
Search for a unique property/value match in an array of
complex objects and return its index in the array.
| ArrayUtils | ||
|
matchValues(a:Array, b:Array):Boolean
Compares two arrays to see if any two indexes have the same
value as the other array.
| ArrayUtils | ||
|
maxIndex(a:Array):int
Return the array index of the maximum value in a numeric array.
| ArrayUtils | ||
|
maxVal(a:Array):Number
Return the maximum value in a numeric array.
| ArrayUtils | ||
|
merge(a:Array, b:Array):Array
Merge two arrays into one.
| ArrayUtils | ||
|
minIndex(a:Array):int
Return the array index of the minimum value in a numeric array.
| ArrayUtils | ||
|
minValue(a:Array):Number
Return the minimum value in a numeric array.
| ArrayUtils | ||
|
nearestNeighbor(val:Number, range:Array, returnIndex:Boolean = false):Number
Locate and return the (lowest) nearest neighbor or matching value in a
NUMERIC sorted array of Numbers. | ArrayUtils | ||
|
remove(a:Array, element:Object):Array
Remove all instances of an element from an array.
| ArrayUtils | ||
|
removeDuplicate(a:Array):Array
Remove duplicates from an array and return a new array.
| ArrayUtils | ||
|
shuffle(a:Array):void
Shuffle array elements.
| ArrayUtils | ||
|
sliceByPropVal(a:Array, prop:String, val:Object, caseInsensitive:Boolean = false):Array
Return a new array sliced from the original array of complex objects
based on a
prop/val match
| ArrayUtils | ||
|
swap(a:Array, index1:int, index2:int):Array
Swap two element's positions in an array.
| ArrayUtils | ||
|
uniqueCopy(a:Array):Array
Create a new array that contains unique instances of objects.
| ArrayUtils | ||
| asearch | () | method |
public function asearch(array:Array, conditions:Object, options:Object = null):*
Advanced array searching with complex matching conditions.
is of the Class type.var condtions:Object = { someProperty: function(item: actual::Boolean {return actual != null;}}
array:Array |
|
conditions:Object |
|
options:Object (default = null) |
* |
var movies:Array = []; //retrieve from some datasource
var at:ArrayUtils = ArrayUtils.gi();
//find with simple property value condition
var moviesByMichaelBay:Array = at.asearch(movies,{director:'Michael Bay'});
//find with property chain condition (assuming the 'released' property returns a Date instance)
var moviesByMichaelByReleasedIn2007:Array = at.asearch(moviesByMichaelBay,{'released.fullYear':2007});
//find only the first object.
var moviesByMichaelByReleasedIn2007:Array = at.asearch(moviesByMichaelBay,{'released.fullYear':2007,{find:"first"}});
//find only the last object.
var moviesByMichaelByReleasedIn2007:Array = at.asearch(moviesByMichaelBay,{'released.fullYear':2007,{find:"last"}});
//find all objects that match (this is the default if no options are provided).
var moviesByMichaelByReleasedIn2007:Array = at.asearch(moviesByMichaelBay,{'released.fullYear':2007,{find:"all"}});
//find with class condition - Drama is a class., so any movies[i].genre that is of type Drama, will match and be returned.
var moviesThatAreClass:Array = at.asearch(movies,{genre:Drama});
//find with Function condition.
var moviesWithAverageRatings:Array = at.asearch(movies,{rating:function(item:Movie,actual:Number):Boolean{return actual > 2.4 && actual < 3.7;}});
//find with RegExp.
var moviesTheBeginWithTr:Array = at.asearch(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 = at.asearch(movies,{'cast.name':'Megan Fox'});
Supported properties in the "options" parameter.
| asearchAll | () | method |
public function asearchAll(array:Array, conditions:Object):ArrayShortcut for advanced searching by a single property.
Parametersarray:Array — The array to search in.
|
|
conditions:Object — An object defining the conditions to use in the search.
|
Array |
| asearchBy | () | method |
public function asearchBy(array:Array, property:String, value:Object, options:* = null):*Shortcut for advanced searching by a single property.
Parametersarray:Array — The array to search in.
|
|
property:String — The property to read.
|
|
value:Object — The value of the target property.
|
|
options:* (default = null) — Find An object with find property. {find:"first"|"last"|"all"}.
|
* |
| asearchFirst | () | method |
public function asearchFirst(array:Array, conditions:Object):*Shortcut for advanced searching for the first matching item.
Parametersarray:Array — The array to search in.
|
|
conditions:Object — An object defining the conditions to use in the search.
|
* |
| asearchLast | () | method |
public function asearchLast(array:Array, conditions:Object):*Shortcut for advanced searching for the last matching item.
Parametersarray:Array — The array to search in.
|
|
conditions:Object — An object defining the conditions to use in the search.
|
* |
| clone | () | method |
public function clone(array:Array):ArrayClones an array.
Parametersarray:Array — The array to clone.
|
Array |
| compare | () | method |
public function compare(a:Array, b:Array, ordered:Boolean = false):BooleanCompare two arrays to see if their values (and optionally order) are identical.
Parametersa:Array — Whether or not the arrays will be sorted before the compare is performed.
|
|
b:Array |
|
ordered:Boolean (default = false) |
Boolean |
var a:Array = [5,4,3,2,1,'C','B','A'];
var b:Array = ['A','B','C',1,2,3,4,5];
trace("arrays (unordered) compare: " + ArrayUtil.compare(a,b)); //true
trace("arrays (ordered) compare: " + ArrayUtil.compare(a,b,true)); //false
| contains | () | method |
public function contains(a:Array, element:Object):BooleanDetermines if a value exists within the array.
Parametersa:Array — The array to search.
|
|
element:Object — The element to search for.
|
Boolean |
| equals | () | method |
public function equals(arr1:Array, arr2:Array):BooleanDetermine if one array is identical to the other array.
Parametersarr1:Array — The first array.
|
|
arr2:Array — The second array.
|
Boolean |
| gi | () | method |
| insert | () | method |
public function insert(a:Array, element:Object, index:int):ArrayInsert an element into an array at a specific index.
Parametersa:Array — The array to insert an element into.
|
|
element:Object — The object to insert.
|
|
index:int — The index the object will be inserted into.
|
Array |
| locatePropVal | () | method |
public function locatePropVal(a:Array, prop:String, val:Object, caseInsensitive:Boolean = false):ObjectSearch for a unique property/value match in an array of complex objects.
Parametersa:Array — An array of objects.
|
|
prop:String — The object property who's value will be tested.
|
|
val:Object — The value to match.
|
|
caseInsensitive:Boolean (default = false) — Whether or not prop and val should be case-insensitive (only if search val is a String).
|
Object |
| locatePropValIndex | () | method |
public function locatePropValIndex(a:Array, prop:String, val:Object, caseInsensitive:Boolean = false):intSearch for a unique property/value match in an array of complex objects and return its index in the array.
Parametersa:Array — An array of objects.
|
|
prop:String — The object property who's value will be tested.
|
|
val:Object — The value to match.
|
|
caseInsensitive:Boolean (default = false) — Whether or not prop and val should be case-insensitive (only if search val is a String).
|
int |
| matchValues | () | method |
public function matchValues(a:Array, b:Array):BooleanCompares two arrays to see if any two indexes have the same value as the other array.
Parametersa:Array — The first array.
|
|
b:Array — The second array.
|
Boolean |
| maxIndex | () | method |
public function maxIndex(a:Array):intReturn the array index of the maximum value in a numeric array.
Parametersa:Array — The array to search.
|
int |
| maxVal | () | method |
public function maxVal(a:Array):NumberReturn the maximum value in a numeric array.
Parametersa:Array — The array to search.
|
Number |
| merge | () | method |
public function merge(a:Array, b:Array):ArrayMerge two arrays into one.
Parametersa:Array — The first array.
|
|
b:Array — The second array.
|
Array |
| minIndex | () | method |
public function minIndex(a:Array):intReturn the array index of the minimum value in a numeric array.
Parametersa:Array — The array to search.
|
int |
| minValue | () | method |
public function minValue(a:Array):NumberReturn the minimum value in a numeric array.
Parametersa:Array — The array to search.
|
Number |
| nearestNeighbor | () | method |
public function nearestNeighbor(val:Number, range:Array, returnIndex:Boolean = false):Number
Locate and return the (lowest) nearest neighbor or matching value in a NUMERIC sorted array of Numbers.
val:Number — the value to find match or find nearst match of.
|
|
range:Array — of values in array.
|
|
returnIndex:Boolean (default = false) — if true return the array index of the neighbor, if false return the value of the neighbor.
|
Number |
var a:Array = [1, 3, 5, 7, 9, 11]; var nearestLow:Number = ArrayUtil.nearestNeighbor(4,a); //returns 3 (value) var nearestHigh:Number = ArrayUtil.nearestNeighbor(4,a,true); //returns 1 (index)
| remove | () | method |
public function remove(a:Array, element:Object):ArrayRemove all instances of an element from an array.
Parametersa:Array — The array to search and remove from.
|
|
element:Object — The element to remove from the array.
|
Array |
| removeDuplicate | () | method |
public function removeDuplicate(a:Array):ArrayRemove duplicates from an array and return a new array.
Parametersa:Array — The array to remove duplicates from.
|
Array |
| shuffle | () | method |
public function shuffle(a:Array):voidShuffle array elements.
Parametersa:Array — The array to shuffle.
|
| sliceByPropVal | () | method |
public function sliceByPropVal(a:Array, prop:String, val:Object, caseInsensitive:Boolean = false):Array
Return a new array sliced from the original array of complex objects
based on a prop/val match
a:Array — An array of objects.
|
|
prop:String — The object property who's value will be tested.
|
|
val:Object — The value to match.
|
|
caseInsensitive:Boolean (default = false) — Whether or not prop and val should be case-insensitive (only if search val is a String).
|
Array |
| swap | () | method |
public function swap(a:Array, index1:int, index2:int):ArraySwap two element's positions in an array.
Parametersa:Array — The target array in which the swap will occur.
|
|
index1:int — The first index.
|
|
index2:int — The second index.
|
Array |
| uniqueCopy | () | method |
public function uniqueCopy(a:Array):ArrayCreate a new array that contains unique instances of objects. This can be used to remove duplication object instances from an array.
Parametersa:Array — The array to uniquely copy.
|
Array |