Search in sources :

Example 1 with RoundOutputType

use of org.knime.base.node.preproc.rounddouble.RoundDoubleConfigKeys.RoundOutputType in project knime-core by knime.

the class RoundDoubleNodeModel method createColumnRearranger.

/**
 * {@inheritDoc}
 */
@Override
public ColumnRearranger createColumnRearranger(final DataTableSpec dataSpec) throws InvalidSettingsException {
    // 
    // / SPEC CHECKS
    // 
    FilterResult filteredCols = m_filterDoubleColModel.applyTo(dataSpec);
    // check for at least one double column in input data table spec
    if (filteredCols.getIncludes().length == 0) {
        throw new InvalidSettingsException("There are no columns containing double values in the input table!");
    }
    // check if all included columns are available in the spec
    String[] unknownCols = filteredCols.getRemovedFromIncludes();
    if (unknownCols.length == 1) {
        setWarningMessage("Column \"" + unknownCols[0] + "\" is not available.");
    } else if (unknownCols.length > 1) {
        setWarningMessage("" + unknownCols.length + " selected columns are not available anymore.");
    }
    // 
    // / CREATE COLUMN REARRANGER
    // 
    // parameters
    int precision = m_numberPrecisionModel.getIntValue();
    boolean append = m_appendColumnsModel.getBooleanValue();
    RoundingMode roundingMode = RoundingMode.valueOf(m_roundingModeModel.getStringValue());
    NumberMode numberMode = NumberMode.valueByDescription(m_numberModeModel.getStringValue());
    final RoundOutputType outputType = RoundOutputType.valueByTextLabel(m_outputTypeModel.getStringValue());
    String colSuffix = m_columnSuffixModel.getStringValue();
    // get array of indices of included columns
    int[] includedColIndices = getIncludedColIndices(dataSpec, filteredCols.getIncludes());
    ColumnRearranger cR = new ColumnRearranger(dataSpec);
    // create spec of new output columns
    DataColumnSpec[] newColsSpecs = getNewColSpecs(append, colSuffix, outputType, filteredCols.getIncludes(), dataSpec);
    // Pass all necessary parameters to the cell factory, which rounds
    // the values and creates new cells to replace or append.
    RoundDoubleCellFactory cellFac = new RoundDoubleCellFactory(precision, numberMode, roundingMode, outputType, includedColIndices, newColsSpecs);
    // replace or append columns
    if (append) {
        cR.append(cellFac);
    } else {
        cR.replace(cellFac, includedColIndices);
    }
    return cR;
}
Also used : RoundingMode(java.math.RoundingMode) RoundOutputType(org.knime.base.node.preproc.rounddouble.RoundDoubleConfigKeys.RoundOutputType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)

Aggregations

RoundingMode (java.math.RoundingMode)1 RoundOutputType (org.knime.base.node.preproc.rounddouble.RoundDoubleConfigKeys.RoundOutputType)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1 FilterResult (org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult)1