Access keys

ArrayUtil

Kind of class: class
Inherits from: BasicClass
Author: Simon Wacker, Martin Heidegger, Christophe Herreman
Classpath: org.as2lib.util.ArrayUtil
File last modified: Wednesday, 14 September 2005, 20:51:26
ArrayUtil contains fundamental methods to manipulate Arrays.

Summary

Class methods

clone

static function clone (
array:Array) : Array
Clones an array.
Parameters:
array:
the array to clone
Returns:
a clone of the passed-in array

contains

static 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:
array :
the array that may contain the object
object:
the object that may be contained in the array
Returns:
true if the array contains the object else
false

indexOf

static function indexOf (
array:Array, object) : Number
Returns the index of first occurance 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:
array :
the array to search through
object:
the object to return the position of
Returns:
the position of the object within the array or -1

isSame

static 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:
array1:
the first array for the comparison
array2:
the second array for the comparison
Returns:
true if the two arrays contain the same values at the same
positions else false

lastIndexOf

static function lastIndexOf (
array:Array, object) : Number
Returns the index of the last occurance 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 last occurence of the passed-in object
within the array. If the object could not be found -1 will be
returned.

Parameters:
array :
the array to search through
object:
the object to return the position of
Returns:
the position of the object within the array or -1

removeAllOccurances

static function removeAllOccurances (
array:Array, element) : Array
Removes all occurances of a the given element out of the passed-in
array.
Parameters:
array :
the array to remove the element out of
element:
the element to remove
Returns:
List that contains the index of all removed occurances

removeElement

static function removeElement (
array:Array, element) : Array
Removes the given element out of the passed-in array.
Parameters:
array :
the array to remove the element out of
element:
the element to remove
Returns:
true if element was removed and false if it was
not contained in the passed-in array

removeFirstOccurance

static function removeFirstOccurance (
array:Array, element) : Number
Removes the first occurance of the given element out of the passed-in
array.
Parameters:
array :
the array to remove the element out of
element:
the element to remove
Returns:
-1 if it could not be found, else the position where it had been deleted

removeLastOccurance

static function removeLastOccurance (
array:Array, element) : Number
Removes the last occurance of the given element out of the passed-in
array.
Parameters:
array :
the array to remove the element out of
element:
the element to remove
Returns:
-1 if it could not be found, else the position where it had been deleted

shuffle

static function shuffle (
array:Array) : Void
Shuffles the passed-in array.
Parameters:
array:
the array to shuffle

swap

static 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:
array:
the array whose elements to swap
i :
the index of the first value
j :
the index of the second value
Returns:
array the passed-in array
Throws:
org.as2lib.env.except.IllegalArgumentException if the argument array is null
org.as2lib.data.holder.NoSuchElementException if the passed-in positions i and j
are less than 0 or greater than the array's length