Package microsim.space
Class DoubleSpace
- Direct Known Subclasses:
DoubleDiffuseSpace
A bi-dimensional grid containing double values.
-
Field Summary
FieldsFields inherited from class microsim.space.AbstractSpace
modCount, xSize, ySize -
Constructor Summary
ConstructorsConstructorDescriptionDoubleSpace(int xSize, int ySize) Creates a grid of given size.DoubleSpace(@NonNull DoubleSpace grid) Creates a copy of the given grid. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double arg) Sum the given value to the value of each cell.protected intat(int x, int y) voidclear()Set all cells to 0.0 value.voidcopyGridTo(double @NonNull [] dm) Copies thedouble[]matrix content in this grid.voidcopyGridTo(@NonNull DoubleSpace dm) Copies the givenDoubleSpacecontent in this grid.intcountObjectsAt(int x, int y) Return the value contained by the given cell cast to int.@NonNull Doubleget(int x, int y) Return a Double object containing the value at given position.doublegetDbl(int x, int y) Return the value at given position.double @NonNull []Return the matrix of values representing the grid.doublemax()Get the maximum value stored into the grid.doublemean()Compute the sample mean value of the values stored in the grid.doublemin()Get the minimum value stored into the grid.voidmultiply(double arg) Multiply the given value to the value of each cell.voidresetTo(double initValue) Set all cells to the given value.voidSet the given value at given position.voidsetDbl(int x, int y, double value) Set the given value at given position.intsize()Return the size of the grid that iswidth * height.doublesum()Sum the value of each cell.voidswapPositions(int x1, int y1, int x2, int y2) Swap the content of the(x1,y1)and(x2,y2)cells of the grid.doublevariance()Compute the sample variance value of the values stored in the grid.Methods inherited from class microsim.space.AbstractSpace
boundX, boundY, equals, getMooreNeighborsPositions, getVonNeumannNeighborsPositions, reflectX, reflectY, torusX, torusY, toString
-
Field Details
-
m
protected double[] m
-
-
Constructor Details
-
DoubleSpace
public DoubleSpace(int xSize, int ySize) Creates a grid of given size.- Parameters:
xSize- The width of the grid.ySize- The height of the grid.
-
DoubleSpace
Creates a copy of the given grid.- Parameters:
grid- The source grid.
-
-
Method Details
-
at
protected int at(int x, int y) -
get
Return a Double object containing the value at given position.- Specified by:
getin classAbstractSpace<Double>- Parameters:
x- Thexcoordinate.y- Theycoordinate.- Returns:
- The Double wrapper for value stored at
x,yposition of the grid.
-
getDbl
public double getDbl(int x, int y) Return the value at given position.- Parameters:
x- Thexcoordinate.y- Theycoordinate.- Returns:
- The value stored at
x,yposition of the grid.
-
set
Set the given value at given position.- Specified by:
setin classAbstractSpace<Double>- Parameters:
x- Thexcoordinate.y- Theycoordinate.obj- An object wrapper for a number class. It is possible to pass Integer, Double, 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:
swapPositionsin classAbstractSpace<Double>- Parameters:
x1- Thexcoordinate for the first cell.y1- Theycoordinate for the first cell.x2- Thexcoordinate for the second cell.y2- Theycoordinate for the second cell.
-
setDbl
public void setDbl(int x, int y, double value) Set the given value at given position.- Parameters:
x- Thexcoordinate.y- Theycoordinate.value- A double value to put atx,yposition.
-
size
public int size()Return the size of the grid that iswidth * height.- Specified by:
sizein classAbstractSpace<Double>- Returns:
- The number of cells in the grid.
-
clear
public void clear()Set all cells to 0.0 value.- Specified by:
clearin classAbstractSpace<Double>
-
resetTo
public void resetTo(double initValue) Set all cells to the given value.- Parameters:
initValue- The value to put into each cell.
-
add
public void add(double arg) Sum the given value to the value of each cell.- Parameters:
arg- The value to be added.
-
multiply
public void multiply(double arg) Multiply the given value to the value of each cell.- Parameters:
arg- The value to be multiplied.
-
min
public double min()Get the minimum value stored into the grid.- Returns:
- The minimum value of the grid.
-
max
public double max()Get the maximum value stored into the grid.- Returns:
- The maximum value of the grid.
-
sum
public double 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 double @NonNull [] getMatrix()Return the matrix of values representing the grid.- Returns:
- A matrix of double with the same dimensions of the grid.
-
copyGridTo
Copies the givenDoubleSpacecontent in this grid.- Parameters:
dm- The sourceDoubleSpaceto be copied.
-
copyGridTo
public void copyGridTo(double @NonNull [] dm) Copies thedouble[]matrix content in this grid.- Parameters:
dm- The source matrix to be copied.
-
countObjectsAt
public int countObjectsAt(int x, int y) Return the value contained by the given cell cast to int.- Specified by:
countObjectsAtin classAbstractSpace<Double>- Parameters:
x- Thexcoordinate.y- Theycoordinate.- Returns:
- The int value contained by the
(x,y)cell.
-