|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.util.AbstractCollection
jas.space.Grid
jas.space.ObjVirtualGrid
public class ObjVirtualGrid
A sparse bidimensional grid containing one object per cell. This object must be used when the ratio between the size of the grid and its average fullness is high. For instance, if you have a grid of 1000 x 1000, with 1000000 of cells and it has to contain 1000 objects, the better solution for memory occupation is to use an ObjVirtualGrid. Obviuosly the ObjVirtualGrid is slower than ObjGrid, but it is much cheaper in memory occupation.
Title: JAS
Description: Java Agent-based Simulation library
Copyright (C) 2002 Michele Sonnessa
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
| Constructor Summary | |
|---|---|
ObjVirtualGrid(Grid grid)
Create a copy of the given grid. |
|
ObjVirtualGrid(int xSize,
int ySize)
Create a grid with given size. |
|
| Method Summary | |
|---|---|
boolean |
add(java.lang.Object o)
Add an object implementing IGridPosition interface to the grid. |
boolean |
addGridPosition(IGridPosition object)
Add an object implementing IGridPosition interface to the grid. |
void |
clear()
Set all cells to the null value. |
boolean |
contains(java.lang.Object o)
Test if given object is contained into the grid. |
int |
countObjectsAt(int x,
int y)
Returns the number of objects allocated in cell (x,y). |
boolean |
equals(java.lang.Object o)
Test if o is the same of this. |
java.lang.Object |
get(int x,
int y)
Return the object stored at the given position. |
GridIterator |
gridIterator()
Return a GridIterator storing the position of the read value. |
java.util.Iterator |
iterator()
Return a java standard interator for elements in the grid. |
boolean |
moveGridPosition(IGridPosition object,
int destinationX,
int destinationY)
Move a IGridPosition object from its current position to the specified destination, only if the destination cell is empty. |
boolean |
remove(java.lang.Object o)
Remove the given object from the grid. |
boolean |
removeGridPosition(IGridPosition object)
Remove the IGridPosition object from the grid. |
void |
set(int x,
int y,
java.lang.Object obj)
Put the given object at the given position. |
int |
size()
Return the number of objects stored into the grid. |
void |
swapPositions(int x1,
int y1,
int x2,
int y2)
Swap the content of the (x1, y1) and (x2, y2) cells of the grid. |
java.lang.Object[] |
toArray()
Return an array of objects stored into the grid. |
| Methods inherited from class jas.space.Grid |
|---|
boundX, boundY, getMooreNeighborsPositions, getVonNeumannNeighborsPositions, getXSize, getYSize, reflectX, reflectY, torusX, torusY, toString |
| Methods inherited from class java.util.AbstractCollection |
|---|
addAll, containsAll, isEmpty, removeAll, retainAll, toArray |
| Methods inherited from class java.lang.Object |
|---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface jas.space.IObjGrid |
|---|
boundX, boundY, getXSize, getYSize, reflectX, reflectY, torusX, torusY |
| Methods inherited from interface java.util.Collection |
|---|
hashCode |
| Constructor Detail |
|---|
public ObjVirtualGrid(Grid grid)
grid - The source grid.
public ObjVirtualGrid(int xSize,
int ySize)
xSize - The width of the grid.ySize - The height of the grid.| Method Detail |
|---|
public boolean add(java.lang.Object o)
add in interface java.util.Collectionadd in class java.util.AbstractCollectiono - The IGridPosition object to be added.
public boolean addGridPosition(IGridPosition object)
addGridPosition in interface IObjGridobject - The IGridPosition object to be added.
public void clear()
clear in interface java.util.Collectionclear in class Gridpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in class java.util.AbstractCollectiono - The object to be tested.
public int countObjectsAt(int x,
int y)
Grid
countObjectsAt in interface IObjGridcountObjectsAt in class Gridx - The x coordinate.y - The y coordinate.public boolean equals(java.lang.Object o)
equals in interface java.util.Collectionequals in class Grido - The object to be compared.
public java.lang.Object get(int x,
int y)
get in class Gridx - The x coordinate.y - The y coordinate.
public GridIterator gridIterator()
gridIterator in class Gridpublic java.util.Iterator iterator()
Grid
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in class Grid
public boolean moveGridPosition(IGridPosition object,
int destinationX,
int destinationY)
moveGridPosition in interface IObjGriddestinationX - The x destination coordinate.destinationY - The y destination coordinate.object - An object implementing IGridPosition interface.
public boolean remove(java.lang.Object o)
remove in interface java.util.Collectionremove in class java.util.AbstractCollectiono - The object to be removed.
java.lang.ClassCastException - If o does not implement IGridPosition interface.public boolean removeGridPosition(IGridPosition object)
removeGridPosition in interface IObjGridobject - The IGridPosition object to be removed.
public void set(int x,
int y,
java.lang.Object obj)
set in class Gridx - The x coordinate.y - The y coordinate.obj - The object to be stored at the (x, y) cell.public int size()
size in interface java.util.Collectionsize in class Grid
public void swapPositions(int x1,
int y1,
int x2,
int y2)
swapPositions in class Gridx1 - The x coordinate for the first cell.y1 - The y coordinate for the first cell.x2 - The x coordinate for the second cell.y2 - The y coordinate for the second cell.public java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in class java.util.AbstractCollection
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||