| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
A
Grid is basically a two dimensions data structure
based on the
Collection interface.
By default a Grid object is an untyped collection that
allow duplicate and null elements. You can set your own
default value instead of null by passing it to the grid
constructor.
Its also possible to restrict the type of grid elements in the constructor
as defined by the TypedContainer interface.
The Grid class don't support all the methods of the Collection
interface. Here the list of the unsupported methods :
Instead of using the methods above there are several specific methods to insert data in the
grid :
setVal : Use it to insert value in the grid at specified coordinates
setContent : Use it to set the grid with the passed-in array.
fill : Use it to fill the grid with the same value in all cells.
public function Grid(size:Dimension, a:Array = null, dV:Object = null, t:Class = null)
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Create a new grid of passed-in size.
If a is set, and if it have the same size that the grid,
it's used to fill the collection at creation.
If dV is set, all null elements in the grid
will be replaced by dV value.
Parameters
| size:Dimension — Size of the grid.
|
| |
| a:Array (default = null) — An array to fill the grid with.
|
| |
| dV:Object (default = null) — dV The default value for null elements.
|
| |
| t:Class (default = null) |
Throws
| — ArgumentError — Invalid size passed in Grid constructor.
|
| |
| — ClassCastException — If objects type contained in the
passed-in array prevents them to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in array length
doesn't match this grid size
|
public function add(o:Object):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
The add method is unsupported by the Grid class.
Parameters
Returns
Throws
| — UnsupportedOperationException — The add method of the Collection interface is unsupported by the Grid Class
|
public function addAll(c:Collection):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
The addAll method is unsupported by the Grid class.
Parameters
Returns
Throws
| — UnsupportedOperationException — The addAll method of the Collection interface is unsupported by the Grid Class
|
public function addAllAt(p:Point, c:Grid):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Copy the content of the passed-in grid at the specified coordinates.
The passed-in grid is paste into this grid such the top-left coordinates
will start at the specified Point argument.
Parameters
| p:Point — coordinates at which copy the grid
|
| |
| c:Grid — grid to copy in this grid object
|
Returns
| Boolean — true if the passed-in grid have been successfully added
at the specified coordinates in this grid
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in collection
type is not the same that the current one.
|
| |
| — IndexOutOfBoundsException — If the passed-in point
is not valid coordinates for this grid.
|
| |
| — IndexOutOfBoundsException — If the passed-in grid
will overlap this grid when copying.
|
See also
public function clear():void
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Removes all of the elements from this collection.
This collection will not be empty after this method.
If a default value have been defined for the grid
then all cells of the grid contains that value.
public function contains(o:Object):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns true if this grid contains at least
one occurence of the specified element. Moreformally,
returns true if and only if this grid contains
at least an element e such that o === e.
Parameters
| o:Object — Object whose presence in this grid
is to be tested.
|
Returns
| Boolean — true if this grid contains the specified
element.
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
public function containsAll(c:Collection):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns true if this grid contains
all of the elements of the specified collection. If the specified
collection is also a Grid, this method returns true
if it is a subliset of this queue.
If the passed-in Collection is null the method throw a
NullPointerException error.
If the passed-in Collection type is different than the current
one the function will throw an IllegalArgumentException.
However, if the type of this grid is null,
the passed-in Collection can have any type.
The rules which govern collaboration between typed and untyped Collection
are described in the isValidCollection descrition, all rules described
there are supported by the containsAll method.
Parameters
| c:Collection — c collection to be checked for containment in this collection.
|
Returns
| Boolean — true if this collection contains all of the elements
in the specified collection
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in collection
type is not the same that the current one.
|
See also
public function fill(o:Object):void
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Fill the current grid with the passed-in value.
If the passed-in value is a "real" object (not a primitive) then
all cells contains a reference to the same object.
Parameters
| o:Object — Value used to fill the grid
|
public function getCoordinates(id:uint):Point
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns a Point witch is the corresponding
position of the passed-in value.
Parameters
| id:uint — id uint to convert in a two dimension location
|
Returns
| Point — Point corresponding location
|
Throws
| — IndexOutOfBoundsException — the passed-in index
is not a valid coordinates for this grid
|
public function getDefaulValue():Object
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns the current default value of this grid used
to replace value when removing an element.
Returns
| Object — element used as default value for the grid's cells
|
public function getSize():Dimension
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns the size of the grid as Dimension.
The returned Dimension is a clone of the
internal one.
Returns
| Dimension —
the dimensions of the grid as Dimension
|
public function getType():Class
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Return the current type allowed in the Grid
Returns
| Class — Class used to type checking.
|
public function getVal(p:Point):Object
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns the element stored at the passed-in coordinate of the
grid.
Parameters
| p:Point — p Coordinates Point in the grid
|
Returns
| Object — Value stored at the coorespoding location or null
if the passed-in coordinates is not a valid coordinates
for this grid
|
Throws
| — IndexOutOfBoundsException — the passed-in point
is not a valid coordinates for this grid
|
protected function initContent():void
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Creates the internal two dimensional array used to store
data of the grid.
public function isEmpty():Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
A Grid object is considered as empty if and only if all its cells
contains null or the default value for the current Grid.
Returns
| Boolean — true if the grid is empty, either false.
|
public function isGridCoords(p:Point):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Check if a Point object is a valid coordinate
in the current grid.
Parameters
| p:Point — Point object to check
|
Returns
| Boolean — true if passed-in Point is a valid
coordinate for the current grid
|
Throws
| — IndexOutOfBoundsException — the passed-in point
is not a valid coordinates for this grid
|
public function isTyped():Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns true if this grid perform a verification
of the type of elements.
Returns
| Boolean — true if this grid perform a verification
of the type of elements.
|
public function isValidCollection(c:Collection):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Verify that the passed-in Collection is a valid
collection for use with the addAll, removeAll,
retainAll and containsAll methods.
When dealing with typed and untyped collection, the following rules apply :
- Two typed collection, which have the same type, can collaborate each other.
- Two untyped collection can collaborate each other.
- An untyped collection can add, remove, retain or contains any typed collection
of any type without throwing errors.
- A typed collection will always fail when attempting to add, remove, retain
or contains an untyped collection.
If the passed-in Collection is null the method throw a
NullPointerException error.
Parameters
Returns
| Boolean — boolean true if the collection is valid,
either false
|
Throws
| — NullPointerException — If the passed-in collection
is null
|
| |
| — IllegalArgumentException — If the passed-in collection
type is not the same that the current one
|
See also
public function isValidType(o:Object):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Verify that the passed-in object type match the current
Grid element's type.
In the case that the grid is untyped the function
will always returns true.
In the case that the object's type prevents it to be added
as element for this grid the method will throw
a ClassCastException.
Parameters
| o:Object — Object to verify
|
Returns
| Boolean — true if the object is elligible for this
grid object, either false
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
public function iterator():Iterator
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns an iterator over the elements in this collection. Iterations
are performed in the following order : columns first, rows after.
Result for a 2x2 grid :
- Cell 0, 0
- Cell 1, 0
- Cell 0, 1
- Cell 1, 1
Returns
| Iterator —
an Iterator over the elements in this collection.
|
public function matchType(o:*):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Verify if the passed-in object can be inserted in the
current Grid.
Parameters
Returns
| Boolean — true if the object can be inserted in
the Grid, either false.
|
public function remove(o:Object):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Removes a single instance of the specified element from this
grid, if this grid contains one or more such elements.
Returns true if this grid contained the specified
element (or equivalently, if this collection changed as a result
of the call).
In order to remove all occurences of an element you have to call
the remove method as long as the grid contains an
occurrence of the passed-in element. Typically, the construct to
remove all occurrences of an element should look like that :
while( grid.contains( element ) ) grid.remove( element );
If the current grid object is typed and if the passed-in object's
type prevents it to be added (and then removed) in this grid,
the function throws a ClassCastException.
The Grid introduce a specific behavior for its default
value, if the passed-in element is the default value for this grid
the function return null and isnt't modified as result
of the call.
Parameters
| o:Object — object to be removed from this grid,
if present.
|
Returns
| Boolean — true if the grid contained the
specified element.
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
public function removeAll(c:Collection):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Removes from this grid all of its elements that are contained
in the specified collection (optional operation). At the end
of the call there's no occurences of any elements contained
in the passed-in collection.
The only values which cannot be removed by a call to removeAll
is the default value for this grid. It result that all cells which contained
a value also contained in the passed-in collection are filled with the grid's
default value.
The rules which govern collaboration between typed and untyped Collection
are described in the isValidCollection descrition, all rules described
there are supported by the removeAll method.
Parameters
| c:Collection — Collection that defines which elements will be
removed from this grid.
|
Returns
| Boolean — true if this grid changed as a result
of the call.
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in collection
type is not the same that the current one.
|
See also
public function removeAllAt(p:Point, c:Grid):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Removes the content of the passed-in grid at the specified coordinates.
The passed-in grid is removed from this grid such the top-left coordinates
will start at the specified Point argument.
The content of the passed-in grid is only removed in the bounds of the grid
in this grid space coordinates. Values which are also stored in the passed-in
grid but whose coordinates aren't in the bounds of the operation aren't remove.
Parameters
| p:Point — coordinates at which remove the grid
|
| |
| c:Grid — grid to remove from this grid object
|
Returns
| Boolean — true if the passed-in grid have been successfully removed
at the specified coordinates in this grid
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in collection
type is not the same that the current one.
|
| |
| — IndexOutOfBoundsException — If the passed-in point
is not valid coordinates for this grid.
|
| |
| — IndexOutOfBoundsException — If the passed-in grid
will overlap this grid when removing.
|
See also
public function removeAt(p:Point):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Removes the value located at the passed-in coordinate.
If the grid changed after the call the function returns
true. If the passed-in Point isn't
a valid coordinate for this grid the function failed and return
false.
If a default value is set, the cell contains that value instead
of null after the call.
Parameters
| p:Point — Point position of the value to remove
|
Returns
| Boolean — true if the grid changed as result of the call
|
Throws
| — IndexOutOfBoundsException — the passed-in point
is not a valid coordinates for this grid
|
public function retainAll(c:Collection):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Retains only the elements in this queue that are contained
in the specified collection (optional operation). In other words,
removes from this queue all of its elements that are not
contained in the specified collection.
The only values which cannot be removed by a call to retainAll
is the default value for this grid. It result that all cells which contained
a value that are not contained in the passed-in collection are filled with
the grid's default value.
The rules which govern collaboration between typed and untyped Collection
are described in the isValidCollection descrition, all rules described
there are supported by the retainAll method.
Parameters
| c:Collection — c elements to be retained in this collection.
|
Returns
| Boolean — true if this collection changed as a result of the
call
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in collection
type is not the same that the current one.
|
See also
public function setContent(a:Array):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Fill the content with an array of witch length is equal to
the grid size().
The call return true only if the Grid
changed as results of the call.
Parameters
| a:Array — a Array to fill the Grid
|
Returns
| Boolean — true if the Grid changed as results of the call
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
| |
| — IllegalArgumentException — If the passed-in array length
doesn't match this grid size
|
public function setDefaultValue(o:Object):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Defines the default value for this grid's cells content.
When changing the default value of a grid, the cells which
previously contains the old default value will contains the
new one at the end of the call.
Parameters
| o:Object — new default value for this grid's cells
|
Returns
| Boolean — true if the grid have change as result
of the call
|
Throws
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
public function setVal(p:Point, o:Object):Boolean
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Defines value of grid cell defining by passed-in Point
coordinate.
The call return true only if the Grid
changed as results of the call.
Parameters
| p:Point — p Point position of the cell
|
| |
| o:Object — o value to store in the grid
|
Returns
| Boolean — true if the Grid changed as results of the call
|
Throws
| — IndexOutOfBoundsException — the passed-in point
is not a valid coordinates for this grid
|
| |
| — ClassCastException — If the object's type
prevents it to be added into this grid
|
public function size():uint
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns the number of elements this collection can contains.
Returns
| uint — the number of elements this collection can contains.
|
public function toArray():Array
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns an array containing all the elements in this grid.
Obeys the general contract of the Collection.toArray
method.
Returns
| Array — Array containing all of the elements
in this grid.
|
See also
Collection.toArray()
public function toString():String
| Player version: | Flash Player 9.0 |
| Language version: | ActionScript 3.0 |
Returns the String representation of
this object.
The function return a string like
com.bourre.structures::Grid<String>
for a typed collection. The string between the <
and > is the name of the type of the collection's
elements. If the collection is an untyped collection
the function will simply return the result of the
PixlibStringifier.stringify call.
Returns
| String — String representation of
this object.
|
LowRA API documentation 2008- 2009
Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1
mer. févr. 25 2009, 9:22 AM GMT+01:00