Search in sources :

Example 1 with ComparatorMethod

use of org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.ComparatorMethod in project knime-core by knime.

the class ColumnComparatorNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
    final ComparatorMethod method = ComparatorMethod.getMethod(m_operator.getStringValue());
    final int idx1 = spec.findColumnIndex(m_firstColumn.getStringValue());
    final int idx2 = spec.findColumnIndex(m_secondColumn.getStringValue());
    DataColumnSpec leftSpec = spec.getColumnSpec(idx1);
    DataColumnSpec rightSpec = spec.getColumnSpec(idx2);
    ColumnRearranger colRe = new ColumnRearranger(spec);
    colRe.append(new SingleCellFactory(createSpec(leftSpec, rightSpec)) {

        private final StringCell m_matchRepl = new StringCell(m_matchValue.getStringValue());

        private final StringCell m_mismatchRepl = new StringCell(m_mismatchValue.getStringValue());

        @Override
        public DataCell getCell(final DataRow row) {
            DataCell cell1 = row.getCell(idx1);
            DataCell cell2 = row.getCell(idx2);
            if (method.compare(cell1, cell2)) {
                String strMatch = m_matchOption.getStringValue();
                if (strMatch.equals(REPL_OPTIONS[0])) {
                    return covertMatch(cell1);
                } else if (strMatch.equals(REPL_OPTIONS[1])) {
                    return covertMatch(cell2);
                } else if (strMatch.equals(REPL_OPTIONS[2])) {
                    return DataType.getMissingCell();
                } else {
                    return m_matchRepl;
                }
            } else {
                String strMismatch = m_mismatchOption.getStringValue();
                if (strMismatch.equals(REPL_OPTIONS[0])) {
                    return covertMismatch(cell1);
                } else if (strMismatch.equals(REPL_OPTIONS[1])) {
                    return covertMismatch(cell2);
                } else if (strMismatch.equals(REPL_OPTIONS[2])) {
                    return DataType.getMissingCell();
                } else {
                    return m_mismatchRepl;
                }
            }
        }
    });
    return colRe;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ColumnComparatorNodeDialogPane.createComparatorMethod(org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.createComparatorMethod) ComparatorMethod(org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.ComparatorMethod) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow)

Aggregations

ComparatorMethod (org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.ComparatorMethod)1 ColumnComparatorNodeDialogPane.createComparatorMethod (org.knime.base.node.preproc.colcompare.ColumnComparatorNodeDialogPane.createComparatorMethod)1 DataCell (org.knime.core.data.DataCell)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataRow (org.knime.core.data.DataRow)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)1 StringCell (org.knime.core.data.def.StringCell)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1