use of org.knime.core.data.vector.bytevector.DenseByteVectorCellFactory in project knime-core by knime.
the class CreateByteVectorNodeModel method createRearranger.
private ColumnRearranger createRearranger(final DataTableSpec inSpec) {
final ColumnRearranger ret = new ColumnRearranger(inSpec);
final String[] includes = m_inputColumns.applyTo(inSpec).getIncludes();
if (m_removeInput.getBooleanValue()) {
ret.remove(includes);
}
final DataColumnSpecCreator newCol = new DataColumnSpecCreator(DataTableSpec.getUniqueColumnName(inSpec, m_outputColumn.getStringValue()), DenseByteVectorCell.TYPE);
newCol.setElementNames(includes);
final int[] sourceColumnIndices = SourceColumnsAsProperties.indices(m_inputColumns.applyTo(inSpec), inSpec);
for (int i = sourceColumnIndices.length; i-- > 0; ) {
if (sourceColumnIndices[i] < 0) {
throw new IllegalStateException("Unknown column: " + includes[i]);
}
}
ret.append(new SingleCellFactory(newCol.createSpec()) {
@Override
public DataCell getCell(final DataRow row) {
final DenseByteVectorCellFactory fac = new DenseByteVectorCellFactory(sourceColumnIndices.length);
for (int i = sourceColumnIndices.length; i-- > 0; ) {
DataCell cell = row.getCell(sourceColumnIndices[i]);
if (cell.isMissing()) {
if (m_failOnMissing.getBooleanValue()) {
throw new IllegalArgumentException("Missing value in the row: " + row.getKey() + "\nin the column: " + includes[i]);
} else {
// return DataType.getMissingCell();
fac.setValue(i, 0);
}
} else if (cell instanceof IntValue) {
int intValue = ((IntValue) cell).getIntValue();
if (intValue < 0 || intValue > 255) {
if (m_failOnOutOfInterval.getBooleanValue()) {
throw new IllegalArgumentException("Invalid value: " + intValue + "\nin row: " + row.getKey() + "\nin the column: " + includes[i]);
} else {
fac.setValue(i, 0);
}
} else {
fac.setValue(i, intValue);
}
} else {
throw new IllegalStateException("Not an int value: " + cell + " (" + cell.getType() + ")");
}
}
return fac.createDataCell();
}
});
return ret;
}
Aggregations