Package microsim.space
Class MultiObjectSpace
java.lang.Object
microsim.space.AbstractSpace<Object>
microsim.space.DenseObjectSpace
microsim.space.MultiObjectSpace
- All Implemented Interfaces:
ObjectSpace
A bi-dimensional grid capable of containing many objects into each cell.
-
Field Summary
Fields inherited from class microsim.space.DenseObjectSpace
m, objectsFields inherited from class microsim.space.AbstractSpace
modCount, xSize, ySize -
Constructor Summary
ConstructorsConstructorDescriptionMultiObjectSpace(int xSize, int ySize) Create a grid with given size and a default initial capacity.MultiObjectSpace(int xSize, int ySize, int cellCapacity) Create a grid with given size and a given initial capacity.MultiObjectSpace(@NonNull AbstractSpace<Object> grid) Create a copy of the given grid with a default initial capacity.MultiObjectSpace(@NonNull AbstractSpace<Object> grid, int cellCapacity) Create a copy of the given grid with a given initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd an object implementingSpacePositioninterface to the grid.booleanaddGridPosition(@Nullable SpacePosition position) Add an object implementingSpacePositioninterface to the grid.intcountObjectsAt(int x, int y) Return the number of objects stored at the given position.get(int x, int y, int z) Return the object stored at the given tri-dimensional position.booleanmoveGridPosition(@Nullable SpacePosition position, int destinationX, int destinationY) Move aSpacePositionobject from its current position to the specified destination.booleanRemove the given object from the grid.booleanRemove the given object from the grid at given position.booleanremoveGridPosition(@Nullable SpacePosition position) Remove theSpacePositionobject from the grid.voidPut the given object at the given tri-dimensional position.voidEnqueue the given object at the given position.Methods inherited from class microsim.space.DenseObjectSpace
clear, get, getMatrix, getMooreNeighbors, getMooreNeighbors, getVonNeumannNeighbors, getVonNeumannNeighbors, size, swapPositionsMethods inherited from class microsim.space.AbstractSpace
boundX, boundY, equals, getMooreNeighborsPositions, getVonNeumannNeighborsPositions, reflectX, reflectY, torusX, torusY, toString
-
Constructor Details
-
MultiObjectSpace
Create a copy of the given grid with a given initial capacity.- Parameters:
grid- The source grid.cellCapacity- The initial vector size allocated for each cell. It grows automatically.
-
MultiObjectSpace
public MultiObjectSpace(int xSize, int ySize, int cellCapacity) Create a grid with given size and a given initial capacity.- Parameters:
xSize- The width of the grid.ySize- The height of the grid.cellCapacity- The initial vector size allocated for each cell. It grows automatically.
-
MultiObjectSpace
Create a copy of the given grid with a default initial capacity.- Parameters:
grid- The source grid.
-
MultiObjectSpace
public MultiObjectSpace(int xSize, int ySize) Create a grid with given size and a default initial capacity.- Parameters:
xSize- The width of the grid.ySize- The height of the grid.
-
-
Method Details
-
countObjectsAt
public int countObjectsAt(int x, int y) Return the number of objects stored at the given position.- Specified by:
countObjectsAtin interfaceObjectSpace- Overrides:
countObjectsAtin classDenseObjectSpace- Parameters:
x- Thexcoordinate.y- Theycoordinate.- Returns:
- The number of objects at
(x, y).
-
get
Return the object stored at the given tri-dimensional position.- Parameters:
x- Thexcoordinate.y- Theycoordinate.z- The index of the vector of object stored at the(x, y)cell.- Returns:
- The requested object.
-
set
Enqueue the given object at the given position.- Specified by:
setin interfaceObjectSpace- Overrides:
setin classDenseObjectSpace- Parameters:
x- Thexcoordinate.y- Theycoordinate.obj- The object to be stored into the vector at the(x, y)cell.
-
moveGridPosition
public boolean moveGridPosition(@Nullable @Nullable SpacePosition position, int destinationX, int destinationY) Move aSpacePositionobject from its current position to the specified destination.- Specified by:
moveGridPositionin interfaceObjectSpace- Overrides:
moveGridPositionin classDenseObjectSpace- Parameters:
destinationX- Thexdestination coordinate.destinationY- Theydestination coordinate.position- An object implementingSpacePositioninterface.- Returns:
- true. Only if the argument object is null the return value will be false.
-
set
Put the given object at the given tri-dimensional position.- Parameters:
x- Thexcoordinate.y- Theycoordinate.z- The index of the vector of object stored at the(x, y)cell. Ifzis out of vector bounds this will be automatically grown.obj- The object to be stored into the vector at the(x, y)cell.
-
add
Add an object implementingSpacePositioninterface to the grid. If object implementsSpacePositionit stored in the right position of the grid.- Overrides:
addin classDenseObjectSpace- Parameters:
o- TheSpacePositionobject to be added.- Returns:
- True if object was added. If o does not implement
SpacePositioninterface it will not be added and method will return false.
-
addGridPosition
Add an object implementingSpacePositioninterface to the grid. If the destination cell is already occupied the method return false and the object is not added.- Specified by:
addGridPositionin interfaceObjectSpace- Overrides:
addGridPositionin classDenseObjectSpace- Parameters:
position- TheSpacePositionobject to be added.- Returns:
- True if object has been added. False if destination cell is already occupied or if argument object is null.
-
remove
Remove the given object from the grid.- Parameters:
o- The object to be removed.- Returns:
- True if object was found and removed, false otherwise.
-
removeGridPosition
Remove theSpacePositionobject from the grid.- Specified by:
removeGridPositionin interfaceObjectSpace- Overrides:
removeGridPositionin classDenseObjectSpace- Parameters:
position- TheSpacePositionobject to be removed.- Returns:
- true if object has been removed. False if object is null or is not present on the grid.
-
removeAt
Remove the given object from the grid at given position. If the object position is known this method is better thanremove(Object)because it works much faster.- Parameters:
x- Thexcoordinate.y- Theycoordinate.o- The object to be removed.- Returns:
- True if object was found and removed, false otherwise.
-