- Type Parameters:
V- the type of the value
- All Implemented Interfaces:
Serializable,Grid<V>
Grid data structure based on an array.
This uses one item of memory for each possible combination of row and column.
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptioncell(int row, int column) Gets the cell at the specified row-column.cells()Gets the complete set of cells.voidclear()Clears the grid.column(int column) Gets the rows of a single column.intGets the number of columns in the grid.columns()Gets the entire grid of values, by column then row.booleancontains(int row, int column) Checks if a value is present at the specified row-column.booleancontainsValue(Object valueToFind) Checks if the specified value is contained in the grid.static <V> DenseGrid<V> create(int rowCount, int columnCount) Creates an emptyDenseGridof the specified size.static <V> DenseGrid<V> Creates aDenseGridcopying from another grid.static <V> DenseGrid<V> create(V[][] array) Creates aDenseGridcopying from an array.booleanChecks if this grid equals another grid.booleanexists(int row, int column) Checks if the specified row-column exists.get(int row, int column) Gets the value at the specified row-column.inthashCode()Gets a suitable hash code.booleanisEmpty()Checks if the grid is empty.booleanisFull()Checks if the grid is full.voidPuts a value into this grid.voidPuts all cells from a grid into this grid.booleanremove(int row, int column) Removes the value at the specified row-column.row(int row) Gets the columns of a single row.introwCount()Gets the number of rows in the grid.rows()Gets the entire grid of values, by row then column.intsize()Gets the number of cells that are present.toString()com.google.common.collect.ImmutableCollection<V> values()Gets the values in order through rows, then columns.
-
Method Details
-
create
Creates an emptyDenseGridof the specified size.- Type Parameters:
V- the type of the value- Parameters:
rowCount- the number of rows, zero or greatercolumnCount- the number of rows, zero or greater- Returns:
- the mutable grid, not null
-
create
Creates aDenseGridcopying from another grid.- Type Parameters:
V- the type of the value- Parameters:
grid- the grid to copy, not null- Returns:
- the mutable grid, not null
-
create
Creates aDenseGridcopying from an array.The row count and column count are derived from the maximum size of the array. The grid is initialized from the non-null values.
- Type Parameters:
V- the type of the value- Parameters:
array- the array, first by row, then by column- Returns:
- the mutable grid, not null
-
rowCount
public int rowCount()Description copied from interface:GridGets the number of rows in the grid.A grid has a fixed number of rows and columns, but not all cells must be occupied. This returns the row capacity, not the number of occupied rows. It is guaranteed that
Grid.contains(int, int)will returnfalsefor indices larger than the row count. -
columnCount
public int columnCount()Description copied from interface:GridGets the number of columns in the grid.A grid has a fixed number of rows and columns, but not all cells must be occupied. This returns the column capacity, not the number of occupied columns. It is guaranteed that
Grid.contains(int, int)will returnfalsefor indices larger than the column count.- Specified by:
columnCountin interfaceGrid<V>- Returns:
- the number of columns, zero or greater
-
size
public int size()Description copied from interface:GridGets the number of cells that are present. -
contains
public boolean contains(int row, int column) Description copied from interface:GridChecks if a value is present at the specified row-column.If either index does not exist, false is returned.
-
containsValue
Description copied from interface:GridChecks if the specified value is contained in the grid.- Specified by:
containsValuein interfaceGrid<V>- Parameters:
valueToFind- the value to find, null returns false- Returns:
- true if the grid contains the value
-
get
Description copied from interface:GridGets the value at the specified row-column.If either index does not exist, null is returned.
-
cell
Description copied from interface:GridGets the cell at the specified row-column.If either index does not exist, null is returned.
-
cells
Description copied from interface:GridGets the complete set of cells.If the grid is mutable then cells may be added or removed from the set. The cells are returned in order, looping around rows, then columns.
The cell returned from the set iterator may be a mutable
Cellimplementation that cannot be stored beyond the lifetime of an iteration. -
values
Description copied from interface:GridGets the values in order through rows, then columns.The returned data structure is an ordered collection. The values are returned in order, looping around rows, then columns.
-
row
Description copied from interface:GridGets the columns of a single row.The list will contain all columns from zero to
columnCount. Where there is no value for a cell, the list will contain null.The returned list is immutable, except for
List.set(int, Object), which adds, updates or deletes from the underlying grid. -
rows
Description copied from interface:GridGets the entire grid of values, by row then column.The outer list contains all rows from zero to
rowCount. Each inner list contains all columns from zero tocolumnCount. Where there is no value for a cell, the value is null.The returned list is immutable, except for the
List.set(int, Object)method on the inner list, which adds, updates or deletes from the underlying grid. -
column
Description copied from interface:GridGets the rows of a single column.The list will contain all rows from zero to
rowCount. Where data is not present, the list will contain null.The returned list is immutable, except for
List.set(int, Object), which adds, updates or deletes from the underlying grid. -
columns
Description copied from interface:GridGets the entire grid of values, by column then row.The outer list contains all columns from zero to
columnCount. Each inner list contains all rows from zero torowCount. Where there is no value for a cell, the value is null.The returned list is immutable, except for the
List.set(int, Object)method on the inner list, which adds, updates or deletes from the underlying grid. -
clear
public void clear()Description copied from interface:GridClears the grid.The grid will be empty after calling this method.
-
put
Description copied from interface:GridPuts a value into this grid.The value at the specified row-column is set. Any previous value at the row-column is replaced.
If either index does not exist,
IndexOutOfBoundsExceptionis thrown. -
putAll
Description copied from interface:GridPuts all cells from a grid into this grid.The value at the specified row-column is set. Any previous value at the row-column is replaced.
-
remove
public boolean remove(int row, int column) Description copied from interface:GridRemoves the value at the specified row-column.If either index does not exist, no action occurs and false is returned.
-
equals
Description copied from interface:GridChecks if this grid equals another grid.Two grids are equal if they are the same size and contain the same set of cells.
-
hashCode
public int hashCode()Description copied from interface:GridGets a suitable hash code.The hash code is
rowCount ^ Integer.rotateLeft(columnCount, 16) ^ cells.hashCode(). -
exists
public boolean exists(int row, int column) Description copied from interface:GridChecks if the specified row-column exists.This simply checks that the row and column indices are between zero and the row and column counts.
-
isFull
public boolean isFull()Description copied from interface:GridChecks if the grid is full.A full grid has a cell at every combination of row and column.
-
isEmpty
public boolean isEmpty()Description copied from interface:GridChecks if the grid is empty. -
toString
-