Class ColumnModel

  • All Implemented Interfaces:
    Serializable

    public class ColumnModel
    extends Object
    implements Serializable
    The list of columns in a project. For each column, this holds the associated ColumnMetadata.

    This class has only immutable members are is meant to be modified by creating copies of it, for instance using the "with" methods provided.

    See Also:
    Serialized Form
    • Method Detail

      • getKeyColumnIndex

        public int getKeyColumnIndex()
        Returns:
        the index of the column used as key to group rows into records
      • withKeyColumnIndex

        public ColumnModel withKeyColumnIndex​(int keyColumnIndex)
        Returns a copy of this column model with a different key column.
        Parameters:
        keyColumnIndex - the index of the column to use as a key
      • replaceColumn

        public ColumnModel replaceColumn​(int index,
                                         ColumnMetadata column)
                                  throws ModelException
        Replace a column metadata at the given index. This instance is left as is and a modified copy is returned.
        Parameters:
        index - the index of the column
        column - the new metadata
        Throws:
        ModelException - if the new column name conflicts with another column
      • withReconConfig

        public ColumnModel withReconConfig​(int index,
                                           ReconConfig config)
        Replaces the recon config at the given column index. It returns a modified copy of this column model.
      • insertColumn

        public ColumnModel insertColumn​(int index,
                                        ColumnMetadata column)
                                 throws ModelException
        Inserts a column at the given index. It returns a modified copy of this column model.
        Parameters:
        index - the index where to insert the column
        column - the column metadata
        Throws:
        ModelException - if the name conflicts with another column
      • insertUnduplicatedColumn

        public ColumnModel insertUnduplicatedColumn​(int index,
                                                    ColumnMetadata column)
        Inserts a column at the given index, possibly changing the name to ensure that it does not conflict with any other column. It returns a modified copy of this column model.
        Parameters:
        index - the place where to insert the column
        column - the column metadata
      • renameColumn

        public ColumnModel renameColumn​(int index,
                                        String newName)
                                 throws ModelException
        Change the name of a column.
        Parameters:
        index - the index of the column
        newName - the new name to give to the column
        Throws:
        ModelException - if the new name conflicts with any other column
      • removeColumn

        public ColumnModel removeColumn​(int index)
        Removes a column at the given index. It returns a modified copy of this column model.
        Parameters:
        index - the index of the column to remove
      • merge

        public ColumnModel merge​(ColumnModel other)
        Given another column model with the same number of columns, merge the recon configuration and other metadata in each n-th column.
        Throws:
        IllegalArgumentException - if the number of columns is different or columns have incompatible reconciliation configurations.
      • getUnduplicatedColumnName

        public String getUnduplicatedColumnName​(String baseName)
      • getColumnByIndex

        public ColumnMetadata getColumnByIndex​(int cellIndex)
      • getColumnIndexByName

        public int getColumnIndexByName​(String name)
        Return the index of the column with the given name.
        Parameters:
        name - column name to look up
        Returns:
        index of column with given name or -1 if not found.
      • getColumnNames

        public List<String> getColumnNames()
      • getJsonKeyCellIndex

        public Integer getJsonKeyCellIndex()
      • getKeyColumnName

        public String getKeyColumnName()
      • hasRecords

        public boolean hasRecords()
        Returns whether the associated grid has an intentional records structure. This happens when the grid is produced by an importer or operation which introduces a record structure, which can be preserved by following operations.
      • withHasRecords

        public ColumnModel withHasRecords​(boolean newHasRecords)
        Returns a copy of this column model with a different value for the hasRecords() field.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object