Class org.as2lib.util.ArrayUtil

org.as2lib.core.BasicClass
   +--org.as2lib.util.ArrayUtil

Description

ArrayUtil contains fundamental methods to manipulate Arrays.

Method Index

clone(), contains(), indexOf(), isSame(), removeAllOccurances(), removeElement(), removeFirstOccurance(), removeLastOccurance(), shuffle(), swap()

Inherited from BasicClass

toString()

Method Detail

clone

static public function clone(array:Array):Array

Clones an array.

Parameters

arraythe array to clone

Return

a clone of the passed-in array

removeElement

static public function removeElement(array:Array, element):Boolean

Removes the given element out of the passed-in array.

Parameters

arraythe array to remove the element out of
elementthe element to remove

Return

true if element was removed and false if it was not contained in the passed-in array

removeAllOccurances

static public function removeAllOccurances(array:Array, element):Boolean

Removes all occurances of a the given element out of the passed-in array.

Parameters

arraythe array to remove the element out of
elementthe element to remove

Return

true if element was removed and false if it was not contained in the passed-in array

removeLastOccurance

static public function removeLastOccurance(array:Array, element):Boolean

Removes the last occurance of the given element out of the passed-in array.

Parameters

arraythe array to remove the element out of
elementthe element to remove

Return

true if element was removed and false if it was not contained in the passed-in array

removeFirstOccurance

static public function removeFirstOccurance(array:Array, element):Boolean

Removes the first occurance of the given element out of the passed-in array.

Parameters

arraythe array to remove the element out of
elementthe element to remove

Return

true if element was removed and false if it was not contained in the passed-in array

contains

static public function contains(array:Array, object):Boolean

Checks if the passed-in array contains the given object.

The content is searched through with a for..in loop. This enables any type of array to be passed-in, indexed and associative arrays.

Parameters

arraythe array that may contain the object
objectthe object that may be contained in the array

Return

true if the array contains the object else false

indexOf

static public function indexOf(array:Array, object):Number

Returns the index of the given object within the passed-in array.

The content of the array is searched through by iterating through the array. This method returns the first occurence of the passed-in object within the array. If the object could not be found -1 will be returned.

Parameters

arraythe array to search through
objectthe object to return the position of

Return

the position of the object within the array or -1

shuffle

static public function shuffle(array:Array):Void

Shuffles the passed-in array.

Parameters

arraythe array to shuffle

swap

static public function swap(array:Array, i:Number, j:Number):Array

Swaps the value at position i with the value at position j of the passed-in array.

The modifications are directly made to the passed-in array.

Parameters

arraythe array whose elements to swap
ithe index of the first value
jthe index of the second value

Return

array the passed-in array

Throws

IllegalArgumentExceptionif the argument array is null
NoSuchElementExceptionif the passed-in positions i and j are less than 0 or greater than the array's length

isSame

static public function isSame(array1:Array, array2:Array):Boolean

Compares the two arrays array1 and array2, whether they contain the same values at the same positions.

Parameters

array1the first array for the comparison
array2the second array for the comparison

Return

true if the two arrays contain the same values at the same positions else false