Package uk.co.rafilevy.utils.ValueGrid
Class ValueGrid<A,B,V>
- java.lang.Object
 - 
- uk.co.rafilevy.utils.ValueGrid.ValueGrid<A,B,V>
 
 
- 
- Type Parameters:
 A- The row label typeB- The column label typeV- The value type
- Direct Known Subclasses:
 MutableIntGrid
public class ValueGrid<A,B,V> extends java.lang.ObjectValueGrid is a container where rows and columns index a value Is essentially a wrapper around aMap<A, Map<B, V>All possible values default to a specified null value if not set. 
- 
- 
Method Summary
Modifier and Type Method Description java.lang.BooleancontainsColumn(B b)Returns whether or not the grid contains a column labeledbjava.lang.BooleancontainsRow(A a)Returns whether or not the grid contains a row labeledaVget(A a, B b)Returns the value in the specified row or columnjava.util.Map<A,V>getColumn(B b)Returns a copy of a specified column as aMapjava.util.Set<B>getColumns()Returns a set of all the column which have been addedjava.util.Map<B,V>getRow(A a)Returns a copy of a specified row as aMapjava.util.Set<A>getRows()Returns a set of all the rows which have been addedbooleanisEmpty()Returns a boolean indicating whether or not the grid is emptyvoidset(A a, B b, V v)Sets the value in rowacolumnband creates the rows and columns if not previously seenintsize()Returns the size of the grid - rows * colsjava.lang.StringtoString() 
 - 
 
- 
- 
Constructor Detail
- 
ValueGrid
public ValueGrid()
Constructs a new, empty ValueGrid, null value is set tonull 
- 
ValueGrid
public ValueGrid(V nullValue)
Constructs a new, empty ValueGrid,- Parameters:
 nullValue- the default value of unset entries
 
 - 
 
- 
Method Detail
- 
get
public V get(A a, B b) throws UnknownKeyException
Returns the value in the specified row or column- Parameters:
 a- the row being indexedb- the column being indexed- Returns:
 - The value in row 
acolumnbornullValueif not set - Throws:
 UnknownKeyException- indicates that either the row or column have never been added
 
- 
getColumn
public java.util.Map<A,V> getColumn(B b)
Returns a copy of a specified column as aMap- Parameters:
 b- the column to be returned- Returns:
 - A 
Map<A, V>object representing a copy of the column - Throws:
 UnknownKeyException- indicates that either the row or column have never been added
 
- 
getRow
public java.util.Map<B,V> getRow(A a)
Returns a copy of a specified row as aMap- Parameters:
 a- the row to be returned- Returns:
 - a copy of row 
a - Throws:
 UnknownKeyException- indicates that either the row or column have never been added
 
- 
set
public void set(A a, B b, V v)
Sets the value in rowacolumnband creates the rows and columns if not previously seen- Parameters:
 a- the row to be setb- the column to be setv- the value to set
 
- 
getRows
public java.util.Set<A> getRows()
Returns a set of all the rows which have been added- Returns:
 - a set containing all the row labels
 
 
- 
getColumns
public java.util.Set<B> getColumns()
Returns a set of all the column which have been added- Returns:
 - a set containing all the column labels
 
 
- 
size
public int size()
Returns the size of the grid - rows * cols- Returns:
 - the size of the grid
 
 
- 
containsRow
public java.lang.Boolean containsRow(A a)
Returns whether or not the grid contains a row labeleda- Parameters:
 a- the row in question- Returns:
 - if the grid contains row 
a 
 
- 
containsColumn
public java.lang.Boolean containsColumn(B b)
Returns whether or not the grid contains a column labeledb- Parameters:
 b- the column in question- Returns:
 - if the grid contains column 
b 
 
- 
isEmpty
public boolean isEmpty()
Returns a boolean indicating whether or not the grid is empty- Returns:
 - if the grid is empty
 
 
- 
toString
public java.lang.String toString()
- Overrides:
 toStringin classjava.lang.Object
 
 - 
 
 -