use of org.knime.core.data.DataCellTypeConverter in project knime-core by knime.
the class RearrangeColumnsTable method applyDataTypeConverters.
/**
* Used when {@link ColumnRearranger#ensureColumnIsConverted(DataCellTypeConverter, int)} is called. It
* preproccesses the row and replaces the column to be converted by the the result of the given converter.
*
* @param row The original input row.
* @param producerMap The object having the converter list (or not)
* @param newCells
* @return The input row if no converter applied or a modified copy of the input row.
*/
private static DataRow applyDataTypeConverters(final DataRow row, final NewColumnsProducerMapping producerMap, final DataCell[] newCells) {
List<Pair<SpecAndFactoryObject, Integer>> converterToIndexMap = producerMap.getConverterToIndexMap();
if (!converterToIndexMap.isEmpty()) {
DataCell[] inputRowCells = new DataCell[row.getNumCells()];
for (int i = 0; i < inputRowCells.length; i++) {
inputRowCells[i] = row instanceof BlobSupportDataRow ? ((BlobSupportDataRow) row).getRawCell(i) : row.getCell(i);
}
for (Pair<SpecAndFactoryObject, Integer> entry : converterToIndexMap) {
SpecAndFactoryObject specAndObject = entry.getFirst();
DataCellTypeConverter converter = specAndObject.getConverter();
int converterIndex = specAndObject.getConverterIndex();
Integer index = entry.getSecond();
DataCell convertedCell = converter.callConvert(row.getCell(converterIndex));
newCells[index] = convertedCell;
inputRowCells[converterIndex] = convertedCell;
}
return new BlobSupportDataRow(row.getKey(), inputRowCells);
}
return row;
}
Aggregations