Class DefaultKeyedValues2D

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, PublicCloneable, KeyedValues2D, Values2D

    public class DefaultKeyedValues2D
    extends java.lang.Object
    implements KeyedValues2D, PublicCloneable, java.lang.Cloneable, java.io.Serializable
    A data structure that stores zero, one or many values, where each value is associated with two keys (a 'row' key and a 'column' key). The keys should be (a) instances of Comparable and (b) immutable.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List columnKeys
      The column keys.
      private java.util.List rowKeys
      The row keys.
      private java.util.List rows
      The row data.
      private static long serialVersionUID
      For serialization.
      private boolean sortRowKeys
      If the row keys should be sorted by their comparable order.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultKeyedValues2D()
      Creates a new instance (initially empty).
      DefaultKeyedValues2D​(boolean sortRowKeys)
      Creates a new instance (initially empty).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addValue​(java.lang.Number value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)
      Adds a value to the table.
      void clear()
      Clears all the data and associated keys.
      java.lang.Object clone()
      Returns a clone.
      boolean equals​(java.lang.Object o)
      Tests if this object is equal to another.
      int getColumnCount()
      Returns the column count.
      int getColumnIndex​(java.lang.Comparable key)
      Returns the column index for a given key.
      java.lang.Comparable getColumnKey​(int column)
      Returns the key for a given column.
      java.util.List getColumnKeys()
      Returns the column keys in an unmodifiable list.
      int getRowCount()
      Returns the row count.
      int getRowIndex​(java.lang.Comparable key)
      Returns the row index for a given key.
      java.lang.Comparable getRowKey​(int row)
      Returns the key for a given row.
      java.util.List getRowKeys()
      Returns the row keys in an unmodifiable list.
      java.lang.Number getValue​(int row, int column)
      Returns the value for a given row and column.
      java.lang.Number getValue​(java.lang.Comparable rowKey, java.lang.Comparable columnKey)
      Returns the value for the given row and column keys.
      int hashCode()
      Returns a hash code.
      void removeColumn​(int columnIndex)
      Removes a column.
      void removeColumn​(java.lang.Comparable columnKey)
      Removes a column from the table.
      void removeRow​(int rowIndex)
      Removes a row.
      void removeRow​(java.lang.Comparable rowKey)
      Removes a row from the table.
      void removeValue​(java.lang.Comparable rowKey, java.lang.Comparable columnKey)
      Removes a value from the table by setting it to null.
      void setValue​(java.lang.Number value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)
      Adds or updates a value.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • rowKeys

        private java.util.List rowKeys
        The row keys.
      • columnKeys

        private java.util.List columnKeys
        The column keys.
      • rows

        private java.util.List rows
        The row data.
      • sortRowKeys

        private final boolean sortRowKeys
        If the row keys should be sorted by their comparable order.
    • Constructor Detail

      • DefaultKeyedValues2D

        public DefaultKeyedValues2D()
        Creates a new instance (initially empty).
      • DefaultKeyedValues2D

        public DefaultKeyedValues2D​(boolean sortRowKeys)
        Creates a new instance (initially empty).
        Parameters:
        sortRowKeys - if the row keys should be sorted.
    • Method Detail

      • getColumnCount

        public int getColumnCount()
        Returns the column count.
        Specified by:
        getColumnCount in interface Values2D
        Returns:
        The column count.
        See Also:
        getRowCount()
      • getValue

        public java.lang.Number getValue​(int row,
                                         int column)
        Returns the value for a given row and column.
        Specified by:
        getValue in interface Values2D
        Parameters:
        row - the row index.
        column - the column index.
        Returns:
        The value.
        See Also:
        getValue(Comparable, Comparable)
      • getRowKeys

        public java.util.List getRowKeys()
        Returns the row keys in an unmodifiable list.
        Specified by:
        getRowKeys in interface KeyedValues2D
        Returns:
        The row keys.
        See Also:
        getColumnKeys()
      • getColumnKeys

        public java.util.List getColumnKeys()
        Returns the column keys in an unmodifiable list.
        Specified by:
        getColumnKeys in interface KeyedValues2D
        Returns:
        The column keys.
        See Also:
        getRowKeys()
      • addValue

        public void addValue​(java.lang.Number value,
                             java.lang.Comparable rowKey,
                             java.lang.Comparable columnKey)
        Adds a value to the table. Performs the same function as #setValue(Number, Comparable, Comparable).
        Parameters:
        value - the value (null permitted).
        rowKey - the row key (null not permitted).
        columnKey - the column key (null not permitted).
        See Also:
        setValue(Number, Comparable, Comparable), removeValue(Comparable, Comparable)
      • setValue

        public void setValue​(java.lang.Number value,
                             java.lang.Comparable rowKey,
                             java.lang.Comparable columnKey)
        Adds or updates a value.
        Parameters:
        value - the value (null permitted).
        rowKey - the row key (null not permitted).
        columnKey - the column key (null not permitted).
        See Also:
        addValue(Number, Comparable, Comparable), removeValue(Comparable, Comparable)
      • removeValue

        public void removeValue​(java.lang.Comparable rowKey,
                                java.lang.Comparable columnKey)
        Removes a value from the table by setting it to null. If all the values in the specified row and/or column are now null, the row and/or column is removed from the table.
        Parameters:
        rowKey - the row key (null not permitted).
        columnKey - the column key (null not permitted).
        See Also:
        addValue(Number, Comparable, Comparable)
      • removeColumn

        public void removeColumn​(java.lang.Comparable columnKey)
        Removes a column from the table.
        Parameters:
        columnKey - the column key (null not permitted).
        Throws:
        UnknownKeyException - if the table does not contain a column with the specified key.
        java.lang.IllegalArgumentException - if columnKey is null.
        See Also:
        removeColumn(int), removeRow(Comparable)
      • clear

        public void clear()
        Clears all the data and associated keys.
      • equals

        public boolean equals​(java.lang.Object o)
        Tests if this object is equal to another.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the other object (null permitted).
        Returns:
        A boolean.
      • hashCode

        public int hashCode()
        Returns a hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone.
        Specified by:
        clone in interface PublicCloneable
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - this class will not throw this exception, but subclasses (if any) might.