Package org.openrefine.model
Class ColumnModel
- java.lang.Object
-
- org.openrefine.model.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 associatedColumnMetadata
.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
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>
_columnNames
protected Map<String,Integer>
_nameToPosition
-
Constructor Summary
Constructors Constructor Description ColumnModel(List<ColumnMetadata> columns)
ColumnModel(List<ColumnMetadata> columns, int keyColumnIndex, boolean hasRecords)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ColumnModel
appendUnduplicatedColumn(ColumnMetadata columnMetadata)
Shortcut forinsertUnduplicatedColumn(int, ColumnMetadata)
, for inserting at the last position.boolean
equals(Object o)
ColumnMetadata
getColumnByIndex(int cellIndex)
ColumnMetadata
getColumnByName(String name)
int
getColumnIndexByName(String name)
Return the index of the column with the given name.List<String>
getColumnNames()
List<ColumnMetadata>
getColumns()
Integer
getJsonKeyCellIndex()
int
getKeyColumnIndex()
String
getKeyColumnName()
int
getRequiredColumnIndex(String columnName)
Utility method to get a column index by name and throw an exception if this column does not exist.String
getUnduplicatedColumnName(String baseName)
int
hashCode()
boolean
hasRecords()
Returns whether the associated grid has an intentional records structure.ColumnModel
insertColumn(int index, ColumnMetadata column)
Inserts a column at the given index.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.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.ColumnModel
removeColumn(int index)
Removes a column at the given index.ColumnModel
renameColumn(int index, String newName)
Change the name of a column.ColumnModel
replaceColumn(int index, ColumnMetadata column)
Replace a column metadata at the given index.String
toString()
ColumnModel
withHasRecords(boolean newHasRecords)
Returns a copy of this column model with a different value for thehasRecords()
field.ColumnModel
withKeyColumnIndex(int keyColumnIndex)
Returns a copy of this column model with a different key column.ColumnModel
withReconConfig(int index, ReconConfig config)
Replaces the recon config at the given column index.
-
-
-
Constructor Detail
-
ColumnModel
public ColumnModel(List<ColumnMetadata> columns, int keyColumnIndex, boolean hasRecords)
-
ColumnModel
public ColumnModel(List<ColumnMetadata> columns)
-
-
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 columncolumn
- 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 columncolumn
- 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 columncolumn
- the column metadata
-
appendUnduplicatedColumn
public ColumnModel appendUnduplicatedColumn(ColumnMetadata columnMetadata)
Shortcut forinsertUnduplicatedColumn(int, ColumnMetadata)
, for inserting at the last position.
-
renameColumn
public ColumnModel renameColumn(int index, String newName) throws ModelException
Change the name of a column.- Parameters:
index
- the index of the columnnewName
- 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.
-
getColumnByName
public ColumnMetadata getColumnByName(String name)
-
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.
-
getRequiredColumnIndex
public int getRequiredColumnIndex(String columnName) throws MissingColumnException
Utility method to get a column index by name and throw an exception if this column does not exist.- Throws:
MissingColumnException
-
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 thehasRecords()
field.
-
getColumns
public List<ColumnMetadata> getColumns()
-
-