Array2

A two-dimensonal array.

Summary
Array2A two-dimensonal array.
Functions
Array2Initializes a two-dimensional array to match a given width and height.
Properties
widthIndicates the width (colums).
width@private
heightIndicates the height (rows).
height@private
Functions
fillWrites a given value into each cell of the two-dimensional array.
getReads a value from a given x/y index.
setWrites a value into a cell at the given x/y index.
resizeResizes the array to match the given width and height.
getRowExtracts a row from a given index.
setRowInserts new values into a complete row of the two-dimensional array.
getColExtracts a column from a given index.
setColInserts new values into a complete column of the two-dimensional array.
shiftLeftShifts all columns by one column to the left.
shiftRightShifts all columns by one column to the right.
shiftUpShifts all rows up by one row.
shiftDownShifts all rows down by one row.
appendRowAppends a new row.
prependRowPrepends a new row.
appendColAppends a new column.
prependColPrepends a new column.
transposeFlips rows with cols and vice versa.
getArrayGrants access to the the linear array which is used internally to store the data in the two-dimensional array.
contains@inheritDoc
clear@inheritDoc
getIterator@inheritDoc
Properties
size@inheritDoc
Functions
isEmpty@inheritDoc
toArray@inheritDoc
toStringPrints out a string representing the current object.
dumpPrints out all elements (for debug/demo purposes).

Functions

Array2

public function Array2(width: int,
height: int)

Initializes a two-dimensional array to match a given width and height.  The smallest possible size is a 2x2 matrix.  The initial value of all elements is null.

Parameters

wThe width (equals number of colums).
hThe height (equals number of rows). 

Properties

width

public function get width():int

Indicates the width (colums).  If a new width is set, the two-dimensional array is resized accordingly.  The minimum value is 2.

width

public function set width(w: int):void

@private

height

public function get height():int

Indicates the height (rows).  If a new height is set, the two-dimensional array is resized accordingly.  The minimum value is 2.

height

public function set height(h: int):void

@private

Functions

fill

public function fill(obj: *):void

Writes a given value into each cell of the two-dimensional array.  If the obj parameter if of type Class, the method creates individual instances of this class for all array cells.

Parameters

itemThe item to be written into each cell. 

get

public function get(x: int,
y: int):*

Reads a value from a given x/y index.  No boundary check is done, so you have to make sure that the input coordinates do not exceed the width or height of the two-dimensional array.

Parameters

xThe x index (column).
yThe y index (row). 

Returns

The value at the given x/y index. 

set

public function set(x: int,
y: int,
obj: *):void

Writes a value into a cell at the given x/y index.  Because of performance reasons no boundary check is done, so you have to make sure that the input coordinates do not exceed the width or height of the two-dimensional array.

Parameters

xThe x index (column).
yThe y index (row).
objThe item to be written into the cell. 

resize

public function resize(w: int,
h: int):void

Resizes the array to match the given width and height.  If the new size is smaller than the existing size, values are lost because of truncation, otherwise all values are preserved.  The minimum size is 2x2 matrix.

Parameters

wThe new width (cols).
hThe new height (rows). 

getRow

public function getRow(y: int):Array

Extracts a row from a given index.

Parameters

yThe row index. 

Returns

An array storing the values of the row. 

setRow

public function setRow(y: uint,
a: Array):void

Inserts new values into a complete row of the two-dimensional array.  The new row is truncated if it exceeds the existing width.

Parameters

yThe row index.
aThe row’s new values. 

getCol

public function getCol(x: int):Array

Extracts a column from a given index.

Parameters

xThe column index. 

Returns

An array storing the values of the column. 

setCol

public function setCol(x: int,
a: Array):void

Inserts new values into a complete column of the two-dimensional array.  The new column is truncated if it exceeds the existing height.

Parameters

xThe column index.
aThe column’s new values. 

shiftLeft

public function shiftLeft():void

Shifts all columns by one column to the left.  Columns are wrapped, so the column at index 0 is not lost but appended to the rightmost column.

shiftRight

public function shiftRight():void

Shifts all columns by one column to the right.  Columns are wrapped, so the column at the last index is not lost but appended to the leftmost column.

shiftUp

public function shiftUp():void

Shifts all rows up by one row.  Rows are wrapped, so the first row is not lost but appended to bottommost row.

shiftDown

public function shiftDown():void

Shifts all rows down by one row.  Rows are wrapped, so the last row is not lost but appended to the topmost row.

appendRow

public function appendRow(a: Array):void

Appends a new row.  If the new row doesn’t match the current width, the inserted row gets truncated or widened to match the existing width.

Parameters

aThe row to append. 

prependRow

public function prependRow(a: Array):void

Prepends a new row.  If the new row doesn’t match the current width, the inserted row gets truncated or widened to match the existing width.

Parameters

aThe row to prepend. 

appendCol

public function appendCol(a: Array):void

Appends a new column.  If the new column doesn’t match the current height, the inserted column gets truncated or widened to match the existing height.

Parameters

aThe column to append. 

prependCol

public function prependCol(a: Array):void

Prepends a new column.  If the new column doesn’t match the current height, the inserted column gets truncated or widened to match the existing height.

Parameters

aThe column to prepend. 

transpose

public function transpose():void

Flips rows with cols and vice versa.

getArray

public function getArray():Array

Grants access to the the linear array which is used internally to store the data in the two-dimensional array.  Use with care for advanced operations.

contains

public function contains(obj: *):Boolean

@inheritDoc

clear

public function clear():void

@inheritDoc

getIterator

public function getIterator():Iterator

@inheritDoc

Properties

size

public function get size():int

@inheritDoc

Functions

isEmpty

public function isEmpty():Boolean

@inheritDoc

toArray

public function toArray():Array

@inheritDoc

toString

public function toString():String

Prints out a string representing the current object.

Returns

A string representing the current object. 

dump

public function dump():String

Prints out all elements (for debug/demo purposes).

Returns

A human-readable representation of the structure. 

A ‘java-style’ collection interface.
public function Array2(width: int,
height: int)
Initializes a two-dimensional array to match a given width and height.
public function get width():int
Indicates the width (colums).
public function get height():int
Indicates the height (rows).
public function fill(obj: *):void
Writes a given value into each cell of the two-dimensional array.
public function get(x: int,
y: int):*
Reads a value from a given x/y index.
public function set(x: int,
y: int,
obj: *):void
Writes a value into a cell at the given x/y index.
public function resize(w: int,
h: int):void
Resizes the array to match the given width and height.
public function getRow(y: int):Array
Extracts a row from a given index.
public function setRow(y: uint,
a: Array):void
Inserts new values into a complete row of the two-dimensional array.
public function getCol(x: int):Array
Extracts a column from a given index.
public function setCol(x: int,
a: Array):void
Inserts new values into a complete column of the two-dimensional array.
public function shiftLeft():void
Shifts all columns by one column to the left.
public function shiftRight():void
Shifts all columns by one column to the right.
public function shiftUp():void
Shifts all rows up by one row.
public function shiftDown():void
Shifts all rows down by one row.
public function appendRow(a: Array):void
Appends a new row.
public function prependRow(a: Array):void
Prepends a new row.
public function appendCol(a: Array):void
Appends a new column.
public function prependCol(a: Array):void
Prepends a new column.
public function transpose():void
Flips rows with cols and vice versa.
public function getArray():Array
Grants access to the the linear array which is used internally to store the data in the two-dimensional array.
public function contains(obj: *):Boolean
@inheritDoc
public function clear():void
@inheritDoc
public function getIterator():Iterator
@inheritDoc
public function get size():int
@inheritDoc
public function isEmpty():Boolean
@inheritDoc
public function toArray():Array
@inheritDoc
public function toString():String
Prints out a string representing the current object.
public function dump():String
Prints out all elements (for debug/demo purposes).
Close