|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
jas.space.Grid
public abstract class Grid
An abstract class representing bidimensional grid container. The different implementations of this class will manage the type of the storable values. It extends the standard jdk java.util.AbstractCollection to give each grid implementation a collection behaviour. So each grid can be iterated like an ArrayList. The specific GridIterator has been implemented to iterate elements storing their position on the grid.
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 | |
---|---|
Grid(int xSize,
int ySize)
Create a grid of given size. |
Method Summary | |
---|---|
int |
boundX(int x)
Check the given x coordinate. |
int |
boundY(int y)
Check the given y coordinate. |
abstract void |
clear()
Empty the content of the grid. |
abstract int |
countObjectsAt(int x,
int y)
Returns the number of objects allocated in cell (x,y). |
boolean |
equals(java.lang.Object o)
Test if the passed object is equal. |
abstract java.lang.Object |
get(int x,
int y)
Return the object contained at given position. |
java.awt.Point[] |
getMooreNeighborsPositions(int x,
int y)
Gets the extended Moore neighbors of the specified coordinate. |
java.awt.Point[] |
getVonNeumannNeighborsPositions(int x,
int y)
Gets the extended von Neumann neighbors of the specified coordinate. |
int |
getXSize()
Return the width of the grid. |
int |
getYSize()
Return the height of the grid. |
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. |
int |
reflectX(int x)
Check the given x coordinate considering the grid as a walled space. |
int |
reflectY(int y)
Check the given y coordinate considering the grid as a walled space. |
abstract void |
set(int x,
int y,
java.lang.Object obj)
Set the given Object at given position. |
abstract int |
size()
Return the size of the grid. |
abstract void |
swapPositions(int x1,
int y1,
int x2,
int y2)
Swap the content of the (x1, y1) and (x2, y2) cells of the grid. |
int |
torusX(int x)
Check the given x coordinate considering the grid as a toroid. |
int |
torusY(int y)
Check the given y coordinate considering the grid as a toroid. |
java.lang.String |
toString()
Return a string representing the content of the grid. |
Methods inherited from class java.util.AbstractCollection |
---|
add, addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
hashCode |
Constructor Detail |
---|
public Grid(int xSize, int ySize)
xSize
- The width of the grid.ySize
- The height of the grid.Method Detail |
---|
public int boundX(int x)
x
- The x coordinate to be tested.
public int boundY(int y)
y
- The y coordinate to be tested.
public abstract void clear()
clear
in interface java.util.Collection
clear
in class java.util.AbstractCollection
public abstract int countObjectsAt(int x, int y)
x
- The x coordinate.y
- The y coordinate.public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection
equals
in class java.lang.Object
o
- The object to be compared.
public abstract java.lang.Object get(int x, int y)
x
- The x coordinate. WARNING: No bounds checking for fast access.y
- The y coordinate. WARNING: No bounds checking for fast access.
public java.awt.Point[] getMooreNeighborsPositions(int x, int y)
x
- the x coordinate of the objecty
- the y coordinate of the object
public java.awt.Point[] getVonNeumannNeighborsPositions(int x, int y)
x
- the x coordinate of the objecty
- the y coordinate of the object
public int getXSize()
public int getYSize()
public GridIterator gridIterator()
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in class java.util.AbstractCollection
public int reflectX(int x)
x
- The x coordinate to be tested.
public int reflectY(int y)
y
- The y coordinate to be tested.
public abstract void set(int x, int y, java.lang.Object obj)
x
- The x coordinate. WARNING: No bounds checking for fast access.y
- The y coordinate. WARNING: No bounds checking for fast access.obj
- An object to be stored.
The type depends on the specific implementation of the Grid.public abstract int size()
size
in interface java.util.Collection
size
in class java.util.AbstractCollection
public abstract void swapPositions(int x1, int y1, int x2, int y2)
x1
- 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 int torusX(int x)
x
- The x coordinate to be tested.
public int torusY(int y)
y
- The y coordinate to be tested.
public java.lang.String toString()
toString
in class java.util.AbstractCollection
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |