AbstractGrid
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Implements: | |
| Known subclasses: | |
| Version: | 1.0 |
| Author: | Francis Bourre |
| Classpath: | com.bourre.structures.AbstractGrid |
| File last modified: | Wednesday, 31 October 2007, 07:35:30 |
AbstractGrid represents base class for all grid operationsAbstractGrid is an abstract class and can be directly use.
Concrete implementations are :
Summary
Instance properties
getVal
getVal:Function
(read,write)
Virtual method for retreiving cell value.
Must be implements in subclass
setVal
setVal:Function
(read,write)
Virtual method for setting cell value.
Must be implements in subclass
Instance methods
checkGridCoords
function checkGridCoords (
) : Void
Indicates if passed-in coordinates can be inside
current grid.
current grid.
Nothing is returned, result is send to logging API if
passed-in coordinates are not available for current grid.
Example
var g : BGrid = new BGrid(10,10); //log message "**Error** invalid grid coordinates.... g.checkGridCoords( new Point(20,20) );
Parameters:
v:
a {link Point} instance defining grid access point.
getArea
function getArea (
) : Number
Returns grid area.
Returns:
Number area valuegetCloneRange
function getCloneRange (
from:Point,
to:Point) : AbstractGrid
getColumn
function getColumn (
n:Number,
startIndex:Number,
endIndex:Number) : Array
Returns all elements contained in a specific grid's column.
Example
var g : BGrid = new BGrid(10,10); var aColumn : Array = g.getColumn(0);
Parameters:
n :
row index in grid.
startIndex:
optional parameter.
endIndex :
optional parameter.
Returns:
a
Array instance with all column's elements (if any) from start index (optional) to end index (optional).getIterator
function getIterator (
) : Iterator
Returns an com.bourre.data.Iterator instance to iterates
over grid elements.
over grid elements.
Use GridIterator class for concrete implementation.
Returns:
an
Iterator instanceSpecified by:
getRandomCoords
function getRandomCoords (
) : Point
Returns a random grid cell.
Example
var g : BGrid = new BGrid(10,10); var p : Point = g.getRandomCoords();
Returns:
Point instance with random cell coordinates
getRow
function getRow (
n:Number,
startIndex:Number,
endIndex:Number) : Array
Returns all elements contained in a specific grid's row.
Example
var g : BGrid = new BGrid(10,10); var aRow : Array = g.getRow(2);
Parameters:
n :
row index in grid.
startIndex:
optional parameter.
endIndex :
optional parameter.
Returns:
a
Array instance with all row's elements (if any) from start index (optional) to end index (optional).initContent
function initContent (
) : Void
Builds (or resets) an empty 2D Array structure.
Automatically call by Constructor
isGridCoords
function isGridCoords (
v:Point) : Boolean
Checks if passed-in coordinates can be inside
current grid.
current grid.
Example
var g : BGrid = new BGrid(10,10); var b : Boolean = g.isGridCoords( new Point(20,20) ); //return false
Parameters:
v:
a {link Point} instance defining grid access point.
Returns:
current grid, either
true is passed-in coordinates are valid for current grid, either
falsesearchForAll
function searchForAll (
) : Array
Returns all positions of passed-in
Object in grid.Parameters:
v:
Element to search
Returns:
in grid.
Array structure representing all element's positionsin grid.
searchForOne
function searchForOne (
) : Point
Returns passed-in
Object position in grid.Parameters:
v:
Element to search
Returns:
in grid.
Point instance representing element's positionin grid.
toString
function toString (
) : String
Returns the string representation of this instance.
Returns:
the string representation of this instance