Package nl.colorize.multimedialib.math
Class Grid<E>
java.lang.Object
nl.colorize.multimedialib.math.Grid<E>
- Type Parameters:
E
- The type element which acts as a cell within this grid.
Two-dimensional data structure with linear access time to each cell. The
grid is dynamically resized when adding new cells, meaning it is relatively
slow to mutate the grid but fast to access it. Each cell is represented by
X and Y coordinates. The grid does not necessarily have to start at (0, 0),
it can start at any coordinate, including negative coordinates. Coordinates
can contain
null
, so not every cell needs to be occupied.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionget
(int x, int y) Returns the value of the grid cell located at the specified coordinates.void
Adds or changed the value of the grid cell located at the specified coordinates.stream()
Returns a stream containing all elements in this grid.stream
(int x0, int y0, int x1, int y1) Returns a stream containing all elements in the specified rectangular sub-grid.
-
Constructor Details
-
Grid
public Grid()
-
-
Method Details
-
set
Adds or changed the value of the grid cell located at the specified coordinates. If this is located outside the current grid, the grid will be resized in order to accomodate the new cell. -
get
Returns the value of the grid cell located at the specified coordinates. This will returnnull
if the coordinates are located outside the grid, or if the coordinates are located within the grid but that cell does not have a value. -
stream
Returns a stream containing all elements in this grid.null
elements will not be included in the stream. -
stream
Returns a stream containing all elements in the specified rectangular sub-grid. The coordinates are exclusive.null
elements will not be included in the stream.
-