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.

public class Grid<E> extends Object
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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int x, int y)
    Returns the value of the grid cell located at the specified coordinates.
    void
    set(int x, int y, E value)
    Adds or changed the value of the grid cell located at the specified coordinates.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Grid

      public Grid()
  • Method Details

    • set

      public void set(int x, int y, E value)
      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

      public E get(int x, int y)
      Returns the value of the grid cell located at the specified coordinates. This will return null 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

      public Stream<E> stream()
      Returns a stream containing all elements in this grid. null elements will not be included in the stream.
    • stream

      public Stream<E> stream(int x0, int y0, int x1, int y1)
      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.