GODPAPER | All Packages | All Classes | Index | Frames No Frames |
Array2

Package | de.polygonal.ds
Class | public class Array2
Inheritance | Array2 Object
Implements | Collection

A two-dimensional array.

Public Properties

| Property | Defined By
--- | --- | ---
|  | celled : int [read-only] | Array2
|  | height : int Indicates the height (rows). | Array2
|  | size : int [read-only] The total number of items. | Array2
|  | width : int Indicates the width (colums). | Array2

Public Methods

| Method | Defined By
--- | --- | ---
|  | Array2(w:int, h:int) Initializes a two-dimensional array to match a given width and height. | Array2
|  | appendCol(a:Array):void Appends a new column. | Array2
|  | appendRow(a:Array):void Appends a new row. | Array2
|  | clear():void Clears all items. | Array2
|  | contains(obj:*):Boolean Determines if the collection contains a given item. | Array2
|  | dump():String Prints out all elements (for debug/demo purposes). | Array2
|  | fill(obj:*):void Writes a given value into each cell of the two-dimensional array. | Array2
|  | getArray():Array Grants access to the the linear array which is used internally to store the data in the two-dimensional array. | Array2
|  | getCol(x:int):Array Extracts a column from a given index. | Array2
|  | getIterator():Iterator Initializes an iterator object pointing to the first item in the collection. | Array2
|  | getRow(y:int):Array Extracts a row from a given index. | Array2
|  | gett(x:int, y:int):* Reads a value from a given x/y index. | Array2
|  | isEmpty():Boolean Checks if the collection is empty. | Array2
|  | prependCol(a:Array):void Prepends a new column. | Array2
|  | prependRow(a:Array):void Prepends a new row. | Array2
|  | resize(w:int, h:int):void Resizes the array to match the given width and height. | Array2
|  | setCol(x:int, a:Array):void Inserts new values into a complete column of the two-dimensional array. | Array2
|  | setRow(y:uint, a:Array):void Inserts new values into a complete row of the two-dimensional array. | Array2
|  | sett(x:int, y:int, obj:*):void Writes a value into a cell at the given x/y index. | Array2
|  | setXs(y:int, objs:Array):void Writes values horiztontally. | Array2
|  | setYs(x:int, objs:Array):void Writes values vertically. | Array2
|  | shiftDown():void Shifts all rows down by one row. | Array2
|  | shiftLeft():void Shifts all columns by one column to the left. | Array2
|  | shiftRight():void Shifts all columns by one column to the right. | Array2
|  | shiftUp():void Shifts all rows up by one row. | Array2
|  | toArray():Array Converts the collection into an array. | Array2
|  | toString():String Prints out a string representing the current object. | Array2
|  | transpose():void Flips rows with cols and vice versa. | Array2

Property Detail

celled | property

`celled:int` [read-only]

Implementation
`public function get celled():int`

height | property |

`height:int`

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

Implementation
`public function get height():int`
`public function set height(value:int):void`

size | property |

`size:int` [read-only]

The total number of items.

Implementation
`public function get size():int`

width | property |

`width:int`

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

Implementation
`public function get width():int`
`public function set width(value:int):void`
Constructor Detail

Array2 | () | Constructor

`public function Array2(w:int, h:int)`

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

Parameters

| `w:int` — The width (equals number of colums).
| `h:int` — The height (equals number of rows).

Method Detail

appendCol | () | method

`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

| `a:Array` — The column to append.

appendRow | () | method |

`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

| `a:Array` — The row to append.

clear | () | method |

`public function clear():void`

Clears all items.

contains | () | method |

`public function contains(obj:*):Boolean`

Determines if the collection contains a given item.

Parameters

| `obj:*` — The item to search for.

Returns

| `Boolean` — True if the item exists, otherwise false.

dump | () | method |

`public function dump():String`

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

Returns

| `String` — A human-readable representation of the structure.

fill | () | method |

`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

| `obj:*` — The item to be written into each cell.

getArray | () | method |

`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.

Returns

| `Array`

getCol | () | method |

`public function getCol(x:int):Array`

Extracts a column from a given index.

Parameters

| `x:int` — The column index.

Returns

| `Array` — An array storing the values of the column.

getIterator | () | method |

`public function getIterator():Iterator`

Initializes an iterator object pointing to the first item in the collection.

Returns

| `Iterator` — An iterator object.

getRow | () | method |

`public function getRow(y:int):Array`

Extracts a row from a given index.

Parameters

| `y:int` — The row index.

Returns

| `Array` — An array storing the values of the row.

gett | () | method |

`public function gett(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

| `x:int` — The x index (column).
| `y:int` — The y index (row).

Returns

| `*` — The value at the given x/y index.

isEmpty | () | method |

`public function isEmpty():Boolean`

Checks if the collection is empty.

Returns

| `Boolean` — True if empty, otherwise false.

prependCol | () | method |

`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

| `a:Array` — The column to prepend.

prependRow | () | method |

`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

| `a:Array` — The row to prepend.

resize | () | method |

`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 a 1x1 matrix.

Parameters

| `w:int` — The new width (cols).
| `h:int` — The new height (rows).

setCol | () | method |

`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

| `x:int` — The column index.
| `a:Array` — The column's new values.

setRow | () | method |

`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

| `y:uint` — The row index.
| `a:Array` — The row's new values.

sett | () | method |

`public function sett(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

| `x:int` — The x index (column).
| `y:int` — The y index (row).
| `obj:*` — The item to be written into the cell.

setXs | () | method |

`public function setXs(y:int, objs:Array):void`

Writes values horiztontally.

Parameters

| `y:int` — The y index (row).
| `objs:Array` — The items to be writtten into the cell.

setYs | () | method |

`public function setYs(x:int, objs:Array):void`

Writes values vertically.

Parameters

| `x:int` — x index (column).
| `objs:Array` — The items to be writtten into the cell.

shiftDown | () | method |

`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.

shiftLeft | () | method |

`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 | () | method |

`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 | () | method |

`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.

toArray | () | method |

`public function toArray():Array`

Converts the collection into an array.

Returns

| `Array` — An array.

toString | () | method |

`public function toString():String`

Prints out a string representing the current object.

Returns

| `String` — A string representing the current object.

transpose | () | method |

`public function transpose():void`

Flips rows with cols and vice versa.

Thu Jan 16 2014, 01:11 PM +08:00