V - the type of the valuejava.io.Serializable, Grid<V>public final class SparseGrid<V>
extends java.lang.Object
implements java.io.Serializable
Grid data structure based on hashing.| Modifier and Type | Method | Description |
|---|---|---|
Grid.Cell<V> |
cell(int row,
int column) |
Gets the cell at the specified row-column.
|
java.util.SortedSet<Grid.Cell<V>> |
cells() |
Gets the complete set of cells.
|
void |
clear() |
Clears the grid.
|
java.util.List<V> |
column(int column) |
Gets the rows of a single column.
|
int |
columnCount() |
Gets the number of columns in the grid.
|
java.util.List<java.util.List<V>> |
columns() |
Gets the entire grid of values, by column then row.
|
boolean |
contains(int row,
int column) |
Checks if a value is present at the specified row-column.
|
boolean |
containsValue(java.lang.Object valueToFind) |
Checks if the specified value is contained in the grid.
|
static <R> SparseGrid<R> |
create(int rowCount,
int columnCount) |
Creates an empty
SparseGrid of the specified row-column count. |
static <R> SparseGrid<R> |
create(Grid<? extends R> grid) |
Creates a
SparseGrid copying from another grid. |
boolean |
equals(java.lang.Object obj) |
Checks if this grid equals another grid.
|
boolean |
exists(int row,
int column) |
Checks if the specified row-column exists.
|
V |
get(int row,
int column) |
Gets the value at the specified row-column.
|
int |
hashCode() |
Gets a suitable hash code.
|
boolean |
isEmpty() |
Checks if the grid is empty.
|
boolean |
isFull() |
Checks if the grid is full.
|
void |
put(int row,
int column,
V value) |
Puts a value into this grid.
|
void |
putAll(Grid<? extends V> grid) |
Puts all cells from a grid into this grid.
|
boolean |
remove(int row,
int column) |
Removes the value at the specified row-column.
|
java.util.List<V> |
row(int row) |
Gets the columns of a single row.
|
int |
rowCount() |
Gets the number of rows in the grid.
|
java.util.List<java.util.List<V>> |
rows() |
Gets the entire grid of values, by row then column.
|
int |
size() |
Gets the number of cells that are present.
|
java.lang.String |
toString() |
|
com.google.common.collect.ImmutableCollection<V> |
values() |
Gets the values in order through rows, then columns.
|
public static <R> SparseGrid<R> create(int rowCount, int columnCount)
SparseGrid of the specified row-column count.R - the type of the valuerowCount - the number of rows, zero or greatercolumnCount - the number of columns, zero or greaterpublic static <R> SparseGrid<R> create(Grid<? extends R> grid)
SparseGrid copying from another grid.R - the type of the valuegrid - the grid to copy, not nullpublic int rowCount()
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 return false
for indices larger than the row count.
public int columnCount()
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 return false
for indices larger than the column count.
columnCount in interface Grid<V>public int size()
Gridpublic Grid.Cell<V> cell(int row, int column)
GridIf either index does not exist, null is returned.
public java.util.SortedSet<Grid.Cell<V>> cells()
GridIf 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 Cell
implementation that cannot be stored beyond the lifetime of an iteration.
public void clear()
GridThe grid will be empty after calling this method.
public void put(int row,
int column,
V value)
GridThe value at the specified row-column is set. Any previous value at the row-column is replaced.
If either index does not exist, IndexOutOfBoundsException is thrown.
public void putAll(Grid<? extends V> grid)
GridThe value at the specified row-column is set. Any previous value at the row-column is replaced.
public boolean remove(int row,
int column)
GridIf either index does not exist, no action occurs and false is returned.
public boolean exists(int row,
int column)
GridThis simply checks that the row and column indices are between zero and the row and column counts.
public boolean isFull()
GridA full grid has a cell at every combination of row and column.
public boolean isEmpty()
Gridpublic boolean contains(int row,
int column)
GridIf either index does not exist, false is returned.
public boolean containsValue(java.lang.Object valueToFind)
GridcontainsValue in interface Grid<V>valueToFind - the value to find, null returns falsepublic V get(int row,
int column)
GridIf either index does not exist, null is returned.
public com.google.common.collect.ImmutableCollection<V> values()
GridThe returned data structure is an ordered collection. The values are returned in order, looping around rows, then columns.
public java.util.List<V> row(int row)
Grid
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.
public java.util.List<java.util.List<V>> rows()
Grid
The outer list contains all rows from zero to rowCount.
Each inner list contains all columns from zero to columnCount.
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.
public java.util.List<V> column(int column)
Grid
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.
public java.util.List<java.util.List<V>> columns()
Grid
The outer list contains all columns from zero to columnCount.
Each inner list contains all rows from zero to rowCount.
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.
public boolean equals(java.lang.Object obj)
GridTwo grids are equal if they are the same size and contain the same set of cells.
public int hashCode()
Grid
The hash code is rowCount ^ Integer.rotateLeft(columnCount, 16) ^ cells.hashCode().
public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2014–2017 Joda.org. All rights reserved.