Class AbstractMerge
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.flow.transformer.spreadsheetmethodmerge.AbstractMerge
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,SizeOfHandler
,Serializable
public abstract class AbstractMerge extends AbstractOptionHandler implements QuickInfoSupporter
Base class for all spreadsheet merge methods.- Author:
- Corey Sterling (csterlin at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractMerge.SourceColumn
Helper class for determining the mapping from input columns in the source spreadsheets to output columns in the merged spreadsheet.
-
Field Summary
Fields Modifier and Type Field Description protected int[][]
m_ClassColumns
The set of class columns for the given spreadsheets.protected ColumnFinder
m_ClassFinder
The column finder for selecting class columns.protected BaseRegExp[]
m_ColumnRenameFindRegexs
The regexs to use to find columns that require renaming.protected BaseString[]
m_ColumnRenameFormatStrings
The format strings specifying how to rename columns.protected boolean
m_EnsureEqualValues
Whether to check columns with multiple sources for equal values among those sources.protected String
m_MergedSpreadsheetName
The name to give the resulting spreadsheet.protected BaseString[]
m_SpreadsheetNames
The name of each spreadsheet to use in column renaming.protected SpreadSheet[]
m_Spreadsheets
The source spreadsheets we are merging.protected static int
ROW_MISSING
The constant value for spreadsheets that do not have an input row for this output row.protected static String
SPREADSHEET_KEYWORD
The keyword to replace with the spreadsheet name in column renaming.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractMerge()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
check(SpreadSheet[] spreadsheets)
Hook method for performing checks before attempting the merge.protected String
checkColumnMapping(Map<String,List<AbstractMerge.SourceColumn>> columnMapping)
Checks the column mapping for correctness.String
classFinderTipText()
Gets the tip-text for the class-matching method option.String
columnRenamesExpTipText()
Gets the tip-text for the column-renaming regexs option.String
columnRenamesFormatTipText()
Gets the tip-text for the column renaming format strings option.protected int
compare(List<AbstractMerge.SourceColumn> sources1, List<AbstractMerge.SourceColumn> sources2)
Compares two ColumnMappingElements to determine the order in which their mapped columns should appear in the merged spreadsheet.protected Map<String,List<AbstractMerge.SourceColumn>>
createColumnMapping()
Creates a mapping from the columns in each input spreadsheet to the corresponding column in the merged spreadsheet.protected SpreadSheet
createEmptyResultantSpreadsheet(Map<String,List<AbstractMerge.SourceColumn>> columnMapping)
Creates the resultant spreadsheet, ready to be filled with data.void
defineOptions()
Adds options to the internal list of options.String
ensureEqualValuesTipText()
Gets the tip-text for the ensure-equal-values option.ColumnFinder
getClassFinder()
Gets the method to use for finding class columns in the source spreadsheets.BaseRegExp[]
getColumnRenamesExp()
Gets the array of column rename expressions.BaseString[]
getColumnRenamesFormat()
Gets the array of format strings used for column renaming.boolean
getEnsureEqualValues()
Gets whether to check all data-sources for a merged column have the same value.protected String
getMappedColumnName(AbstractMerge.SourceColumn source)
Gets the name of the column in the merged spreadsheet that the given source column maps to.String
getOutputName()
Gets the name to use for the merged spreadsheet.String
getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.protected abstract Enumeration<int[]>
getRowSetEnumeration()
Allows specific merge methods to specify the order in which rows are placed into the merged spreadsheet, and which rows from the source spreadsheets are used for the source data.BaseString[]
getSpreadsheetNames()
Gets the list of names to use in column renaming in place of the {SPREADSHEET} keyword.protected Object
getValue(DataRow toGetFrom, int columnIndex)
Gets the value of the specified column from the given row.protected Object
getValueEnsureEqual(int[] rowSet, List<AbstractMerge.SourceColumn> sources)
Gets the value of the mapped column, ensuring that all possible sources either provide a missing value or the same value as each other.protected Object
getValueFirstAvailable(int[] rowSet, List<AbstractMerge.SourceColumn> sourceColumnElements)
Gets the first encountered source value for a merged column.protected boolean
isAnyClassColumn(List<AbstractMerge.SourceColumn> sources)
Checks if any of the source columns in the given list is a class column.protected boolean
isClassColumn(int spreadsheetIndex, int columnIndex)
Whether the given column is the name of a class column.protected boolean
isClassColumn(AbstractMerge.SourceColumn source)
Checks if the given source column is a class column.SpreadSheet
merge(SpreadSheet[] spreadsheets)
Merges the spreadsheets.String
outputNameTipText()
Gets the tip-text for the output name option.protected void
recordClassColumns()
Scans the spreadsheets for columns that should be considered classes, and keeps a record of them.protected void
resetInternalState(SpreadSheet[] spreadsheets)
Resets the internal state of the merge method when new spreadsheets are supplied.void
setClassFinder(ColumnFinder value)
Sets the method to use for finding class columns in the source spreadsheets.void
setColumnRenamesExp(BaseRegExp[] value)
Sets the array of column rename expressions.void
setColumnRenamesFormat(BaseString[] value)
Sets the array of format strings used for column renaming.void
setEnsureEqualValues(boolean value)
Sets whether to check all data-sources for a merged column have the same value.void
setOutputName(String value)
Sets the name to use for the merged spreadsheet.void
setSpreadsheetNames(BaseString[] value)
Sets the list of names to use in column renaming in place of the {SPREADSHEET} keyword.protected void
setValue(DataRow toSet, int columnIndex, Object value)
Sets the value of the given column in the given row to the given value (handles object conversion).String
spreadsheetNamesTipText()
Gets the tip-text for the spreadsheet names option.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
SPREADSHEET_KEYWORD
protected static final String SPREADSHEET_KEYWORD
The keyword to replace with the spreadsheet name in column renaming.- See Also:
- Constant Field Values
-
ROW_MISSING
protected static final int ROW_MISSING
The constant value for spreadsheets that do not have an input row for this output row.- See Also:
- Constant Field Values
-
m_ClassFinder
protected ColumnFinder m_ClassFinder
The column finder for selecting class columns.
-
m_SpreadsheetNames
protected BaseString[] m_SpreadsheetNames
The name of each spreadsheet to use in column renaming.
-
m_ColumnRenameFindRegexs
protected BaseRegExp[] m_ColumnRenameFindRegexs
The regexs to use to find columns that require renaming.
-
m_ColumnRenameFormatStrings
protected BaseString[] m_ColumnRenameFormatStrings
The format strings specifying how to rename columns.
-
m_MergedSpreadsheetName
protected String m_MergedSpreadsheetName
The name to give the resulting spreadsheet.
-
m_EnsureEqualValues
protected boolean m_EnsureEqualValues
Whether to check columns with multiple sources for equal values among those sources.
-
m_Spreadsheets
protected SpreadSheet[] m_Spreadsheets
The source spreadsheets we are merging.
-
m_ClassColumns
protected int[][] m_ClassColumns
The set of class columns for the given spreadsheets.
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
getClassFinder
public ColumnFinder getClassFinder()
Gets the method to use for finding class columns in the source spreadsheets.- Returns:
- The class-matching method to use.
-
setClassFinder
public void setClassFinder(ColumnFinder value)
Sets the method to use for finding class columns in the source spreadsheets.- Parameters:
value
- The method to use.
-
classFinderTipText
public String classFinderTipText()
Gets the tip-text for the class-matching method option.- Returns:
- The tip-text as a String.
-
getSpreadsheetNames
public BaseString[] getSpreadsheetNames()
Gets the list of names to use in column renaming in place of the {SPREADSHEET} keyword.- Returns:
- The list of spreadsheet names.
-
setSpreadsheetNames
public void setSpreadsheetNames(BaseString[] value)
Sets the list of names to use in column renaming in place of the {SPREADSHEET} keyword.- Parameters:
value
- The list of spreadsheet names.
-
spreadsheetNamesTipText
public String spreadsheetNamesTipText()
Gets the tip-text for the spreadsheet names option.- Returns:
- The tip-text as a String.
-
getColumnRenamesExp
public BaseRegExp[] getColumnRenamesExp()
Gets the array of column rename expressions.- Returns:
- The array of regexs.
-
setColumnRenamesExp
public void setColumnRenamesExp(BaseRegExp[] value)
Sets the array of column rename expressions.- Parameters:
value
- The array of regexs.
-
columnRenamesExpTipText
public String columnRenamesExpTipText()
Gets the tip-text for the column-renaming regexs option.- Returns:
- The tip-text as a String.
-
getColumnRenamesFormat
public BaseString[] getColumnRenamesFormat()
Gets the array of format strings used for column renaming.- Returns:
- The array of format strings.
-
setColumnRenamesFormat
public void setColumnRenamesFormat(BaseString[] value)
Sets the array of format strings used for column renaming.- Parameters:
value
- The array of format strings.
-
columnRenamesFormatTipText
public String columnRenamesFormatTipText()
Gets the tip-text for the column renaming format strings option.- Returns:
- The tip-text as a String.
-
getOutputName
public String getOutputName()
Gets the name to use for the merged spreadsheet.- Returns:
- The name to use.
-
setOutputName
public void setOutputName(String value)
Sets the name to use for the merged spreadsheet.- Parameters:
value
- The name to use.
-
outputNameTipText
public String outputNameTipText()
Gets the tip-text for the output name option.- Returns:
- The tip-text as a String.
-
getEnsureEqualValues
public boolean getEnsureEqualValues()
Gets whether to check all data-sources for a merged column have the same value.- Returns:
- True if value equality should be checked, false if not.
-
setEnsureEqualValues
public void setEnsureEqualValues(boolean value)
Sets whether to check all data-sources for a merged column have the same value.- Parameters:
value
- True if value equality should be checked, false if not.
-
ensureEqualValuesTipText
public String ensureEqualValuesTipText()
Gets the tip-text for the ensure-equal-values option.- Returns:
- The tip-text as a String.
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the object, which can be displayed in the GUI.
Default implementation returns just null.- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Returns:
- null if no info available, otherwise short string
-
setValue
protected void setValue(DataRow toSet, int columnIndex, Object value)
Sets the value of the given column in the given row to the given value (handles object conversion).- Parameters:
toSet
- The row against which the value should be set.columnIndex
- The index of the column against which to set the value.value
- The value to set the column to.
-
getValue
protected Object getValue(DataRow toGetFrom, int columnIndex)
Gets the value of the specified column from the given row.- Parameters:
toGetFrom
- The row to get a value from.columnIndex
- The index of the value's column.- Returns:
- The value of the row at the given index.
-
check
protected String check(SpreadSheet[] spreadsheets)
Hook method for performing checks before attempting the merge.- Parameters:
spreadsheets
- The spreadsheets to merge.- Returns:
- null if successfully checked, otherwise error message.
-
checkColumnMapping
protected String checkColumnMapping(Map<String,List<AbstractMerge.SourceColumn>> columnMapping)
Checks the column mapping for correctness.- Parameters:
columnMapping
- The column mapping.- Returns:
- Null if all mappings are okay, or an error message if not.
-
merge
public SpreadSheet merge(SpreadSheet[] spreadsheets)
Merges the spreadsheets.- Parameters:
spreadsheets
- The spreadsheets to merge.- Returns:
- The merged spreadsheet.
-
getValueFirstAvailable
protected Object getValueFirstAvailable(int[] rowSet, List<AbstractMerge.SourceColumn> sourceColumnElements)
Gets the first encountered source value for a merged column.- Parameters:
rowSet
- The row-set of source data.sourceColumnElements
- The source column mapping elements.- Returns:
- The value of the merged column.
-
getValueEnsureEqual
protected Object getValueEnsureEqual(int[] rowSet, List<AbstractMerge.SourceColumn> sources)
Gets the value of the mapped column, ensuring that all possible sources either provide a missing value or the same value as each other.- Parameters:
rowSet
- The row-set of source data.sources
- The source columns.- Returns:
- The value of the merged column.
-
createColumnMapping
protected Map<String,List<AbstractMerge.SourceColumn>> createColumnMapping()
Creates a mapping from the columns in each input spreadsheet to the corresponding column in the merged spreadsheet.- Returns:
- The mapping from input column names to output column names.
-
isAnyClassColumn
protected boolean isAnyClassColumn(List<AbstractMerge.SourceColumn> sources)
Checks if any of the source columns in the given list is a class column.- Parameters:
sources
- The source columns to check.- Returns:
- True if a source column is a class, false if none are.
-
isClassColumn
protected boolean isClassColumn(AbstractMerge.SourceColumn source)
Checks if the given source column is a class column.- Parameters:
source
- The source column to check.- Returns:
- True if the source is a class column, false if not.
-
isClassColumn
protected boolean isClassColumn(int spreadsheetIndex, int columnIndex)
Whether the given column is the name of a class column.- Parameters:
spreadsheetIndex
- The spreadsheet the column is in.columnIndex
- The index of the column in the spreadsheet.- Returns:
- True if the given column name is the name of a class column, false otherwise.
-
recordClassColumns
protected void recordClassColumns()
Scans the spreadsheets for columns that should be considered classes, and keeps a record of them.
-
createEmptyResultantSpreadsheet
protected SpreadSheet createEmptyResultantSpreadsheet(Map<String,List<AbstractMerge.SourceColumn>> columnMapping)
Creates the resultant spreadsheet, ready to be filled with data.- Parameters:
columnMapping
- The mapping from merged column names to their original names.- Returns:
- The empty Spreadsheet object for the merged spreadsheet.
-
compare
protected int compare(List<AbstractMerge.SourceColumn> sources1, List<AbstractMerge.SourceColumn> sources2)
Compares two ColumnMappingElements to determine the order in which their mapped columns should appear in the merged spreadsheet.- Parameters:
sources1
- The first element to compare.sources2
- The second element to compare.- Returns:
- sources1 < sources2 => -1, sources1 > sources2 => 1, otherwise 0;
-
getMappedColumnName
protected String getMappedColumnName(AbstractMerge.SourceColumn source)
Gets the name of the column in the merged spreadsheet that the given source column maps to.- Parameters:
source
- The source column.- Returns:
- The name of the mapped column in the merged spreadsheet.
-
resetInternalState
protected void resetInternalState(SpreadSheet[] spreadsheets)
Resets the internal state of the merge method when new spreadsheets are supplied.- Parameters:
spreadsheets
- The spreadsheets being merged.
-
getRowSetEnumeration
protected abstract Enumeration<int[]> getRowSetEnumeration()
Allows specific merge methods to specify the order in which rows are placed into the merged spreadsheet, and which rows from the source spreadsheets are used for the source data.- Returns:
- An enumeration of the source rows, one row for each spreadsheet.
-
-