Class ValueGrid<A,​B,​V>

  • Type Parameters:
    A - The row label type
    B - The column label type
    V - The value type
    Direct Known Subclasses:
    MutableIntGrid

    public class ValueGrid<A,​B,​V>
    extends java.lang.Object
    ValueGrid is a container where rows and columns index a value Is essentially a wrapper around a Map<A, Map<B, V> All possible values default to a specified null value if not set.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Set<B> cols  
      protected java.util.Map<A,​java.util.Map<B,​V>> matrix  
      protected java.util.Set<A> rows  
    • Constructor Summary

      Constructors 
      Constructor Description
      ValueGrid()
      Constructs a new, empty ValueGrid, null value is set to null
      ValueGrid​(V nullValue)
      Constructs a new, empty ValueGrid,
    • Method Summary

      Modifier and Type Method Description
      java.lang.Boolean containsColumn​(B b)
      Returns whether or not the grid contains a column labeled b
      java.lang.Boolean containsRow​(A a)
      Returns whether or not the grid contains a row labeled a
      V get​(A a, B b)
      Returns the value in the specified row or column
      java.util.Map<A,​V> getColumn​(B b)
      Returns a copy of a specified column as a Map
      java.util.Set<B> getColumns()
      Returns a set of all the column which have been added
      java.util.Map<B,​V> getRow​(A a)
      Returns a copy of a specified row as a Map
      java.util.Set<A> getRows()
      Returns a set of all the rows which have been added
      boolean isEmpty()
      Returns a boolean indicating whether or not the grid is empty
      void set​(A a, B b, V v)
      Sets the value in row a column b and creates the rows and columns if not previously seen
      int size()
      Returns the size of the grid - rows * cols
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • matrix

        protected java.util.Map<A,​java.util.Map<B,​V>> matrix
      • rows

        protected java.util.Set<A> rows
      • cols

        protected java.util.Set<B> cols
    • Constructor Detail

      • ValueGrid

        public ValueGrid()
        Constructs a new, empty ValueGrid, null value is set to null
      • 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 indexed
        b - the column being indexed
        Returns:
        The value in row a column b or nullValue if 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 a Map
        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 a Map
        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 row a column b and creates the rows and columns if not previously seen
        Parameters:
        a - the row to be set
        b - the column to be set
        v - 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 labeled a
        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 labeled b
        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:
        toString in class java.lang.Object