Package | com.threerings.util |
Class | public class ArrayUtil |
Method | Defined by | ||
---|---|---|---|
contains(arr:Array, element:Object):Boolean
[static]
| ArrayUtil | ||
copy(src:Array, srcoffset:uint, dst:Array, dstoffset:uint, count:uint):void
[static]
Copy a segment of one array to another.
| ArrayUtil | ||
copyOf(arr:Array):Array
[static]
Creates a shallow copy of the array.
| ArrayUtil | ||
create(size:uint, val:* = null):Array
[static]
Creates a new Array and fills it with a default value.
| ArrayUtil | ||
equals(ar1:Array, ar2:Array):Boolean
[static]
Do the two arrays contain elements that are all equals()?
| ArrayUtil | ||
findIf(arr:Array, predicate:Function):*
[static]
Returns the first item in the array for which the predicate function returns true, or
undefined if no such item was found.
| ArrayUtil | ||
indexIf(arr:Array, predicate:Function):int
[static]
Returns the index of the first item in the array for which the predicate function
returns true, or -1 if no such item was found.
| ArrayUtil | ||
indexOf(arr:Array, element:Object):int
[static]
Returns the first index of the supplied element in the array.
| ArrayUtil | ||
padToLength(arr:Array, size:uint, val:* = null):Array
[static]
Pad the array to the specified length with the value specified, returning the passed-in
array for convenience.
| ArrayUtil | ||
removeAll(arr:Array, element:Object):Boolean
[static]
Removes all instances of the specified element from the array.
| ArrayUtil | ||
removeAllIf(arr:Array, pred:Function):Boolean
[static]
Removes all elements in the array for which the specified predicate returns true.
| ArrayUtil | ||
removeFirst(arr:Array, element:Object):Boolean
[static]
Remove the first instance of the specified element from the array.
| ArrayUtil | ||
removeFirstIf(arr:Array, pred:Function):Boolean
[static]
Removes the first element in the array for which the specified predicate returns true.
| ArrayUtil | ||
removeLast(arr:Array, element:Object):Boolean
[static]
Remove the last instance of the specified element from the array.
| ArrayUtil | ||
removeLastIf(arr:Array, pred:Function):Boolean
[static]
Removes the last element in the array for which the specified predicate returns true.
| ArrayUtil | ||
resize(arr:Array, newLength:uint):void
[static]
Properly resizes an Array, truncating if it's too large, and padding it with 'undefined'
if too small.
| ArrayUtil | ||
[static]
Randomly shuffle the elements in the specified array.
| ArrayUtil | ||
sort(arr:Array):void
[static]
Sort the specified array according to natural order- all elements
must implement Comparable or be null.
| ArrayUtil | ||
sortedInsert(arr:Array, val:Function, comp:* = null):int
[static]
Inserts an object into a sorted Array in its correct, sorted location.
| ArrayUtil | ||
sortOn(arr:Array, sortFields:Array):void
[static]
Sort the specified array according to one or more fields of the objects in the Array.
| ArrayUtil | ||
splice(arr:Array, index:int, deleteCount:int, insertions:Array = null):Array
[static]
A splice that takes an optional Array of elements to splice in.
| ArrayUtil | ||
stableSort(arr:Array, comp:Function = null):void
[static]
Perform a stable sort on the specified array.
| ArrayUtil | ||
transpose(x:Array, y:Array, ... arrays):Array
[static]
Returns an array whose nth element is an array of the nth elements of each of the passed
in arrays.
| ArrayUtil |
contains | () | method |
public static function contains(arr:Array, element:Object):Boolean
Parameters
arr:Array |
|
element:Object |
Boolean — true if the specified element, or one that is Equalable.equals() to it, is
contained in the array.
|
copy | () | method |
public static function copy(src:Array, srcoffset:uint, dst:Array, dstoffset:uint, count:uint):void
Copy a segment of one array to another.
Parameterssrc:Array — the array to copy from
|
|
srcoffset:uint — the position in the source array to begin copying from
|
|
dst:Array — the array to copy into
|
|
dstoffset:uint — the position in the destition array to begin copying into
|
|
count:uint — the number of elements to copy
|
copyOf | () | method |
public static function copyOf(arr:Array):Array
Creates a shallow copy of the array.
Parametersarr:Array |
Array |
create | () | method |
public static function create(size:uint, val:* = null):Array
Creates a new Array and fills it with a default value.
Parameterssize:uint — the size of the array
|
|
val:* (default = null ) — the value to store at each index of the Array
|
Array |
equals | () | method |
public static function equals(ar1:Array, ar2:Array):Boolean
Do the two arrays contain elements that are all equals()?
Parametersar1:Array |
|
ar2:Array |
Boolean |
findIf | () | method |
public static function findIf(arr:Array, predicate:Function):*
Returns the first item in the array for which the predicate function returns true, or undefined if no such item was found. The predicate function should be of type: function (element : :Boolean { }
Parametersarr:Array |
|
predicate:Function |
* — the matching element, or undefined if no matching element was found.
|
indexIf | () | method |
public static function indexIf(arr:Array, predicate:Function):int
Returns the index of the first item in the array for which the predicate function returns true, or -1 if no such item was found. The predicate function should be of type: function (element : :Boolean { }
Parametersarr:Array |
|
predicate:Function |
int — the zero-based index of the matching element, or -1 if none found.
|
indexOf | () | method |
public static function indexOf(arr:Array, element:Object):int
Returns the first index of the supplied element in the array. Note that if the element implements Equalable, an element that is equals() will have its index returned, instead of requiring the search element to be === (strictly equal) to an element in the array like Array.indexOf().
Parametersarr:Array |
|
element:Object |
int — the zero-based index of the matching element, or -1 if none found.
|
padToLength | () | method |
public static function padToLength(arr:Array, size:uint, val:* = null):Array
Pad the array to the specified length with the value specified, returning the passed-in array for convenience.
Parametersarr:Array |
|
size:uint |
|
val:* (default = null )
|
Array |
removeAll | () | method |
public static function removeAll(arr:Array, element:Object):Boolean
Removes all instances of the specified element from the array.
Parametersarr:Array |
|
element:Object |
Boolean — true if at least one element was removed, false otherwise.
|
removeAllIf | () | method |
public static function removeAllIf(arr:Array, pred:Function):Boolean
Removes all elements in the array for which the specified predicate returns true.
Parametersarr:Array — a Function of the form: function (element : :Boolean
|
|
pred:Function |
Boolean — true if an element was removed, false otherwise.
|
removeFirst | () | method |
public static function removeFirst(arr:Array, element:Object):Boolean
Remove the first instance of the specified element from the array.
Parametersarr:Array |
|
element:Object |
Boolean — true if an element was removed, false otherwise.
|
removeFirstIf | () | method |
public static function removeFirstIf(arr:Array, pred:Function):Boolean
Removes the first element in the array for which the specified predicate returns true.
Parametersarr:Array — a Function of the form: function (element : :Boolean
|
|
pred:Function |
Boolean — true if an element was removed, false otherwise.
|
removeLast | () | method |
public static function removeLast(arr:Array, element:Object):Boolean
Remove the last instance of the specified element from the array.
Parametersarr:Array |
|
element:Object |
Boolean — true if an element was removed, false otherwise.
|
removeLastIf | () | method |
public static function removeLastIf(arr:Array, pred:Function):Boolean
Removes the last element in the array for which the specified predicate returns true.
Parametersarr:Array — a Function of the form: function (element : :Boolean
|
|
pred:Function |
Boolean — true if an element was removed, false otherwise.
|
resize | () | method |
public static function resize(arr:Array, newLength:uint):void
Properly resizes an Array, truncating if it's too large, and padding it with 'undefined' if too small. An Array grown with the Array class's length setter will not actually have the number of elements that it claims to.
Parametersarr:Array |
|
newLength:uint |
shuffle | () | method |
public static function shuffle(arr:Array, rando:Random = null):void
Randomly shuffle the elements in the specified array.
Parametersarr:Array — a random number generator to use, or null if you don't care.
|
|
rando:Random (default = null )
|
sort | () | method |
public static function sort(arr:Array):void
Sort the specified array according to natural order- all elements must implement Comparable or be null.
Parametersarr:Array |
sortedInsert | () | method |
public static function sortedInsert(arr:Array, val:Function, comp:* = null):int
Inserts an object into a sorted Array in its correct, sorted location.
Parametersarr:Array — a function that takes two objects in the array and returns -1 if the first
object should appear before the second in the container, 1 if it should appear after,
and 0 if the order does not matter. If omitted, Comparators.compareComparables is used and
the array elements should be Comparable objects.
|
|
val:Function |
|
comp:* (default = null )
|
int — the index of the inserted item
|
sortOn | () | method |
public static function sortOn(arr:Array, sortFields:Array):void
Sort the specified array according to one or more fields of the objects in the Array. Array.sortOn() only works with public variables, and not with public getters. This implementation works with both.
Parametersarr:Array — an Array of Strings, representing the order of fields to sort the array by
|
|
sortFields:Array |
splice | () | method |
public static function splice(arr:Array, index:int, deleteCount:int, insertions:Array = null):Array
A splice that takes an optional Array of elements to splice in. The function on Array is fairly useless unless you know exactly what you're splicing in at compile time. Fucking varargs.
Parametersarr:Array |
|
index:int |
|
deleteCount:int |
|
insertions:Array (default = null )
|
Array |
stableSort | () | method |
public static function stableSort(arr:Array, comp:Function = null):void
Perform a stable sort on the specified array.
Parametersarr:Array — a function that takes two objects in the array and returns -1 if the first
object should appear before the second in the container, 1 if it should appear after,
and 0 if the order does not matter. If omitted, Comparators.compareComparables is used and
the array elements should be Comparable objects.
|
|
comp:Function (default = null )
|
transpose | () | method |
public static function transpose(x:Array, y:Array, ... arrays):Array
Returns an array whose nth element is an array of the nth elements of each of the passed in arrays. Therefore, the length of the returned array will be the maximum of the lengths of the passed in arrays and will have no undefined entries. Also, the nth element of the returned array will contain undefined entries for each corresponding array whose nth element was undefined.
Parametersx:Array |
|
y:Array |
|
... arrays |
Array |
var trans :Array = transpose([1, 2, 3], ["a", "b", "c"], ["foo", "bar", "baz"]); trace(trans[0]); // [1, "a", "foo"] trace(trans[1]); // [2, "b", "bar"] trace(trans[2]); // [3, "c", "baz"]