Interface DynamicGrid<E>

Type Parameters:
E - The type of element this grid should hold
All Superinterfaces:
BaseGrid<E>, Grid<E>, Iterable<E>, Serializable
All Known Implementing Classes:
HashGrid

public interface DynamicGrid<E> extends Grid<E>
A grid whose size can be changed without requiring re-instantiation. Dynamic grids use composite data structures as opposed to primitive arrays, and thus have more overhead in terms of memory consumption.
See Also:
  • Method Details

    • of

      @Nonnull static <E> DynamicGrid<E> of(@Nonnull E[][] values)
      Creates a new dynamic grid from a two-dimensional array of values.
      Type Parameters:
      E - The type of element to contain
      Parameters:
      values - The values of which to contain in the grid
      Returns:
      The constructed grid instance
    • clear

      void clear()
      Clears all entries within this grid, removing them from memory. This differs from filling the grid with null in that it reduces the footprint of this grid. This is the equivalent of setting this grid's size to {0, 0}, then resizing it back to its original size.
    • remove

      boolean remove(int r, int c)
      Removes the element from the specified position. This differs from setting the value to null in that it physically removes the entry corresponding to the specified index, as opposed to simply setting the value to null.
      Parameters:
      r - The index of the row to remove
      c - The index of the column to remove
      Returns:
      true if there was a value (including null) at the specified position, and thus the state of this grid has changed as a result of this operation
    • clean

      void clean()
      Cleans this grid, removing all instance of null. This does not trim the grid to its minimum possible size.
      See Also:
    • trim

      void trim()
      Trims this grid, reducing its size to the minimum possible size required to hold all elements. This does not clean null values.
      See Also:
    • cleanAndTrim

      void cleanAndTrim()
      Cleans this grid, then trims it to its minimum possible size. In other words, this performs clean(), then trims the grid.
      See Also:
    • setSize

      void setSize(int rows, int columns)
      Forcefully sets the size of this grid, without regard to the data's integrity. If this operation results in the reduction of this grid's size, all elements which are now outside the bounds of this grid will be removed.
      Parameters:
      rows - The number rows to resize to
      columns - The number of columns to resize to