Grid
| Kind of class: | public class |
|---|---|
| Package: | com.bourre.structures |
| Inherits from: | none |
| Implements: | |
| Author: | Cédric Néhémie |
| Classpath: | com.bourre.structures.Grid |
| File last modified: | Monday, 24 November 2008, 11:36:47 |
Grid is basically a two dimensions data structurebased 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 Collectioninterface. Here the list of the unsupported methods :
addaddAllisEmpty
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 coordinatessetContent: 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.
- com.bourre.collection.Collection
- com.bourre.collection.TypedContainer
Summary
- toString : String
- Returns the String representation of
- contains (o:Object) : Boolean
- Returns true if this grid contains at least
- toArray : Array
- Returns an array containing all the elements in this grid.
- isEmpty : Boolean
- A Grid object is considered as empty if and only if all its cells
- remove (o:Object) : Boolean
- Removes a single instance of the specified element from this
- clear : void
- Removes all of the elements from this collection.
- iterator : Iterator
- Returns an iterator over the elements in this collection.
- removeAll (c:Collection) : Boolean
- Removes from this grid all of its elements that are contained
- containsAll (c:Collection) : Boolean
- Returns true if this grid contains
- addAll (c:Collection) : Boolean
- The addAll method is unsupported by the Grid class.
- addAllAt (p:Point, c:Grid) : Boolean
- Copy the content of the passed-in grid at the specified coordinates.
- removeAllAt (p:Point, c:Grid) : Boolean
- Removes the content of the passed-in grid at the specified coordinates.
- retainAll (c:Collection) : Boolean
- Retains only the elements in this queue that are contained
- add (o:Object) : Boolean
- The add method is unsupported by the Grid class.
- size : uint
- Returns the number of elements this collection can contains.
- matchType (o:*) : Boolean
- Verify if the passed-in object can be inserted in the
- isTyped : Boolean
- Returns true if this grid perform a verification
- getType : Class
- Return the current type allowed in the Grid
- isValidCollection (c:Collection) : Boolean
- Verify that the passed-in Collection is a valid
- isValidType (o:Object) : Boolean
- Verify that the passed-in object type match the current
- fill (o:Object) : void
- Fill the current grid with the passed-in value.
- removeAt (p:Point) : Boolean
- Removes the value located at the passed-in coordinate.
- isGridCoords (p:Point) : Boolean
- Check if a Point object is a valid coordinate
- getSize : Dimension
- Returns the size of the grid as Dimension.
- getCoordinates (id:uint) : Point
- Returns a Point witch is the corresponding
- getDefaulValue : Object
- Returns the current default value of this grid used
- setDefaultValue (o:Object) : Boolean
- Defines the default value for this grid's cells content.
- getVal (p:Point) : Object
- Returns the element stored at the passed-in coordinate of the
- setVal (p:Point, o:Object) : Boolean
- Defines value of grid cell defining by passed-in Point
- setContent (a:Array) : Boolean
- Fill the content with an array of witch length is equal to
Constructor
Grid
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.
- {VISDOC_LINK_0}
ArgumentError— Invalid size passed in Grid constructor. - {VISDOC_LINK_1}
ClassCastException— If objects type contained in the
passed-in array prevents them to be added into this grid - {VISDOC_LINK_2}
IllegalArgumentException— If the passed-in array length
doesn't match this grid size
Instance methods
add
add method is unsupported by the Grid class. addAll
addAll method is unsupported by the Grid class. addAllAt
The passed-in grid is paste into this grid such the top-left coordinates
will start at the specified
Point argument. -
trueif the passed-in grid have been successfully added
at the specified coordinates in this grid
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in collection
type is not the same that the current one. - {VISDOC_LINK_2}
IndexOutOfBoundsException— If the passed-in point
is not valid coordinates for this grid. - {VISDOC_LINK_3}
IndexOutOfBoundsException— If the passed-in grid
will overlap this grid when copying.
clear
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.
- {VISDOC_LINK_0}#
Collection— if thetruemethod is
not supported by this collection.
contains
true if this grid contains at leastone occurence of the specified element. Moreformally,
returns
true if and only if this grid containsat least an element
e such that o === e. Object whose presence in this gridis to be tested.
-
trueif this grid contains the specified
element.
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid
containsAll
true if this grid containsall of the elements of the specified collection. If the specified
collection is also a
Grid, this method returns trueif it is a subliset of this queue.If the passed-in Collection is null the method throw aNullPointerException 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 Collectionare described in the isValidCollection descrition, all rules described
there are supported by the containsAll method.
-
trueif this collection contains all of the elements
in the specified collection
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in collection
type is not the same that the current one.
fill
If the passed-in value is a "real" object (not a primitive) then
all cells contains a reference to the same object.
getCoordinates
Point witch is the correspondingposition of the passed-in value.
uint to convert in a two dimension location-
Pointcorresponding location
- {VISDOC_LINK_0}
IndexOutOfBoundsException— the passed-in index
is not a valid coordinates for this grid
getDefaulValue
to replace value when removing an element.
- element used as default value for the grid's cells
getSize
Dimension.The returned Dimension is a clone of the
internal one.
- the dimensions of the grid as
Dimension
getType
Grid -
Classused to type checking.
getVal
grid.
Point in the grid- Value stored at the coorespoding location or
nullif the passed-in coordinates is not a valid coordinates
for this grid
- {VISDOC_LINK_0}
IndexOutOfBoundsException— the passed-in point
is not a valid coordinates for this grid
isEmpty
Grid object is considered as empty if and only if all its cellscontains
null or the default value for the current Grid. -
trueif the grid is empty, eitherfalse.
isGridCoords
Point object is a valid coordinatein the current grid.
Point object to check-
trueif passed-inPointis a valid
coordinate for the current grid
- {VISDOC_LINK_0}
IndexOutOfBoundsException— the passed-in point
is not a valid coordinates for this grid
isTyped
true if this grid perform a verificationof the type of elements.
-
trueif this grid perform a verification
of the type of elements.
isValidCollection
Collection is a validcollection 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 aNullPointerException error.
Collection to verify- boolean
trueif the collection is valid,
eitherfalse
- {VISDOC_LINK_0}
NullPointerException— If the passed-in collection
isnull - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in collection
type is not the same that the current one
isValidType
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.
Object to verify-
trueif the object is elligible for this
grid object, eitherfalse
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid
iterator
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
- an
Iteratorover the elements in this collection.
matchType
current
Grid. -
trueif the object can be inserted in
theGrid, eitherfalse.
remove
grid, if this grid contains one or more such elements.
Returns
true if this grid contained the specifiedelement (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.
object to be removed from this grid,if present.
-
trueif the grid contained the
specified element.
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid
removeAll
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 removeAllis 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 Collectionare described in the isValidCollection descrition, all rules described
there are supported by the removeAll method.
Collection that defines which elements will beremoved from this grid.
-
trueif this grid changed as a result
of the call.
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in collection
type is not the same that the current one.
removeAllAt
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.
-
trueif the passed-in grid have been successfully removed
at the specified coordinates in this grid
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in collection
type is not the same that the current one. - {VISDOC_LINK_2}
IndexOutOfBoundsException— If the passed-in point
is not valid coordinates for this grid. - {VISDOC_LINK_3}
IndexOutOfBoundsException— If the passed-in grid
will overlap this grid when removing.
removeAt
If the grid changed after the call the function returnstrue. If the passed-in Point isn't
a valid coordinate for this grid the function failed and returnfalse.
If a default value is set, the cell contains that value instead
of null after the call.
Point position of the value to remove-
trueif the grid changed as result of the call
- {VISDOC_LINK_0}
IndexOutOfBoundsException— the passed-in point
is not a valid coordinates for this grid
retainAll
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 retainAllis 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 Collectionare described in the isValidCollection descrition, all rules described
there are supported by the retainAll method.
-
trueif this collection changed as a result of the
call
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in collection
type is not the same that the current one.
setContent
the grid
size().The call return true only if the Gridchanged as results of the call.
Array to fill the Grid-
trueif theGridchanged as results of the call
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid - {VISDOC_LINK_1}
IllegalArgumentException— If the passed-in array length
doesn't match this grid size
setDefaultValue
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.
-
trueif the grid have change as result
of the call
- {VISDOC_LINK_0}
ClassCastException— If the object's type
prevents it to be added into this grid
setVal
Point coordinate.
The call return true only if the Gridchanged as results of the call.
Point position of the cell-
trueif theGridchanged as results of the call
- {VISDOC_LINK_0}
IndexOutOfBoundsException— the passed-in point
is not a valid coordinates for this grid - {VISDOC_LINK_1}
ClassCastException— If the object's type
prevents it to be added into this grid
size
- the number of elements this collection can contains.
toArray
Obeys the general contract of the
Collection.toArraymethod. -
Arraycontaining all of the elements
in this grid.
toString
String representation ofthis object.
The function return a string likecom.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 thePixlibStringifier.stringify call.
-
Stringrepresentation of
this object.