Package microsim.space
Class IntSpace
- java.lang.Object
-
- microsim.space.AbstractSpace<java.lang.Integer>
-
- microsim.space.IntSpace
-
public class IntSpace extends AbstractSpace<java.lang.Integer>
A bidimensional grid containing integer values.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.- Author:
- Michele Sonnessa
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int arg)
Sum the given value to the value of each cell.void
clear()
Set all cells to 0 value.void
copyGridTo(int[] dm)
Copies the int[] matrix content in this grid.void
copyGridTo(IntSpace dm)
Copies the given IntGrid content in this grid.int
countObjectsAt(int x, int y)
Returns the number of objects allocated in cell (x,y).java.lang.Integer
get(int x, int y)
Return an Integer object containing the value at given position.int
getInt(int x, int y)
Return the value at given position.int[]
getMatrix()
Return the matrix of values representing the grid.int
max()
Get the maximum value stored into the grid.double
mean()
Compute the sample mean value of the values stored in the grid.int
min()
Get the minimum value stored into the grid.void
multiply(int arg)
Multiply the given value to the value of each cell.void
randomPopulate(double splitProbability, int probableValue, int defaultValue)
void
resetTo(int initValue)
Set all cells to the given value.void
set(int x, int y, java.lang.Object obj)
Set the given value at given position.void
setInt(int x, int y, int value)
Set the given value at given position.int
size()
Return the size of the grid.int
sum()
Sum the value of each cell.void
swapPositions(int x1, int y1, int x2, int y2)
Swap the content of the (x1, y1) and (x2, y2) cells of the grid.double
variance()
Compute the sample variance value of the values stored in the grid.-
Methods inherited from class microsim.space.AbstractSpace
boundX, boundY, equals, getMooreNeighborsPositions, getVonNeumannNeighborsPositions, getXSize, getYSize, reflectX, reflectY, torusX, torusY, toString
-
-
-
-
Constructor Detail
-
IntSpace
public IntSpace(int xSize, int ySize)
Create a grid of given size.- Parameters:
xSize
- The width of the grid.ySize
- The height of the grid.
-
IntSpace
public IntSpace(IntSpace grid)
Create a copy of the given grid.- Parameters:
grid
- The source grid.
-
-
Method Detail
-
randomPopulate
public void randomPopulate(double splitProbability, int probableValue, int defaultValue)
-
get
public java.lang.Integer get(int x, int y)
Return an Integer object containing the value at given position.- Specified by:
get
in classAbstractSpace<java.lang.Integer>
- Parameters:
x
- The x coordinate. WARNING: No bounds checking for fast access.y
- The y coordinate. WARNING: No bounds checking for fast access.- Returns:
- The Integer wrapper for value stored at x,y position of the grid.
-
getInt
public int getInt(int x, int y)
Return the value at given position.- Parameters:
x
- The x coordinate. WARNING: No bounds checking for fast access.y
- The y coordinate. WARNING: No bounds checking for fast access.- Returns:
- The value stored at x,y position of the grid.
-
set
public void set(int x, int y, java.lang.Object obj)
Set the given value at given position.- Specified by:
set
in classAbstractSpace<java.lang.Integer>
- Parameters:
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 wrapper for a number class. It is possible to pass Interger, Double, Float or Long values.
-
swapPositions
public void swapPositions(int x1, int y1, int x2, int y2)
Swap the content of the (x1, y1) and (x2, y2) cells of the grid.- Specified by:
swapPositions
in classAbstractSpace<java.lang.Integer>
- Parameters:
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.
-
setInt
public void setInt(int x, int y, int value)
Set the given value at given position.- Parameters:
x
- The x coordinate. WARNING: No bounds checking for fast access.y
- The y coordinate. WARNING: No bounds checking for fast access.value
- An integer value to put at x,y position.
-
size
public int size()
Return the size of the grid. It is width * height.- Specified by:
size
in classAbstractSpace<java.lang.Integer>
- Returns:
- The number of cells in the grid.
-
clear
public void clear()
Set all cells to 0 value.- Specified by:
clear
in classAbstractSpace<java.lang.Integer>
-
resetTo
public void resetTo(int initValue)
Set all cells to the given value.- Parameters:
initValue
- The value to put into each cell.
-
add
public void add(int arg)
Sum the given value to the value of each cell.- Parameters:
arg
- The value to be added.
-
multiply
public void multiply(int arg)
Multiply the given value to the value of each cell.- Parameters:
arg
- The value to be multiplyed.
-
min
public int min()
Get the minimum value stored into the grid.- Returns:
- The minimum value of the grid.
-
max
public int max()
Get the maximum value stored into the grid.- Returns:
- The maximum value of the grid.
-
sum
public int sum()
Sum the value of each cell.- Returns:
- The sum the value of each cell.
-
mean
public double mean()
Compute the sample mean value of the values stored in the grid.- Returns:
- The mean value.
-
variance
public double variance()
Compute the sample variance value of the values stored in the grid.- Returns:
- The variance value.
-
getMatrix
public int[] getMatrix()
Return the matrix of values representing the grid.- Returns:
- A matrix of integer with the same dimensions of the grid.
-
copyGridTo
public void copyGridTo(IntSpace dm)
Copies the given IntGrid content in this grid.- Parameters:
dm
- The source IntGrid to be copied.
-
copyGridTo
public void copyGridTo(int[] dm)
Copies the int[] matrix content in this grid.- Parameters:
dm
- The source matrix to be copied.
-
countObjectsAt
public int countObjectsAt(int x, int y)
Description copied from class:AbstractSpace
Returns the number of objects allocated in cell (x,y).- Specified by:
countObjectsAt
in classAbstractSpace<java.lang.Integer>
- Parameters:
x
- The x coordinate.y
- The y coordinate.
-
-