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;
}
Aggregations