Class org.as2lib.data.holder.array.TypedArray

Implemented Interfaces

BasicInterface

Description

TypedArray acts like a normal array but assures that only objects of a specific type are added to the array.

Note that elements that are added to this array using the dot-syntax do not get type-checked. For example: myArray[0] = "value1"; // or myArray.myProp = "value2"; // myArray["myProp"] = "value2";

Example: var array:Array = new TypedArray(Number); array.push(0); array.push(1); array.push(2); // throws an IllegalArgumentException because the element is not of the expected type array.push("myString");

You can also construct your array the following way: var array:Array = new TypedArray(Number, 0, 1, 2);

See Also

Field Index

Inherited from Array

CASEINSENSITIVE, DESCENDING, length, NUMERIC, RETURNINDEXEDARRAY, UNIQUESORT

Method Index

new TypedArray()
concat(), getType(), push(), toString(), unshift()

Inherited from Array

join(), pop(), reverse(), shift(), slice(), sort(), sortOn(), splice()

Constructor Detail

TypedArray

public function TypedArray(type:Function)

Constructs a new TypedArray instance.

You can optionally pass-in elements to populate this array with after the type parameter. These elements also get type-checked. For example: var array:Array = new TypedArray(Number, 1, 2, 3);

Parameters

typethe type of the elements this array expects
...any number of elements to populate this array with

Method Detail

getType

public function getType(Void):Function

Returns the type all elements of this array have.

This is the type passed-in on construction.

Return

the type all elements of this array have

concat

public function concat():TypedArray

Concatenates the elements specified in the parameter list with the elements of this array and returns a new array containing these elements.

This array itself is left unchanged.

The returned array expects elements of the same type as this array does.

If you do not pass-in any elements a duplicate of this array gets returned.

Parameters

...any number of elements to concatenate the elements of this array with

Return

a new array that contains the elements of this array as well as the passed-in elements

Overrides

concat() in Array

See Also

push

public function push(value):Number

Adds one or more elements to the end of this array and returns the new length of this array.

The passed-in elements get type-checked first. They will only be added if they are all of the correct type.

Parameters

valuethe new element to add to the end of this array
...any number of further elements to add to the end of this array

Return

the new length of this array

Throws

IllegalArgumentExceptionif one of the passed-in elements is of invalid type

Overrides

push() in Array

See Also

unshift

public function unshift(value):Number

Adds one or more elements to the beginning of this array and returns the new length of this array.

The passed-in values get type-checked first. They will only be added if they are all of the correct type.

Parameters

valuethe new element to add to the beginning of this array
...any number of further elements to add to the beginning of this array

Return

the new length of this array

Throws

IllegalArgumentExceptionif one of the passed-in elements is of invalid type

Overrides

unshift() in Array

See Also

toString

public function toString():String

Returns the string representation of this array.

Return

the string representation of this array

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in Array