use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class DBUpdateNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final int[] updateStatus) {
final String updateColumn = DataTableSpec.getUniqueColumnName(inSpec, UPDATE_COLUMN);
final DataColumnSpec cspec = new DataColumnSpecCreator(updateColumn, IntCell.TYPE).createSpec();
final ColumnRearranger rearr = new ColumnRearranger(inSpec);
rearr.append(new SingleCellFactory(cspec) {
private int m_rowCount = 0;
@Override
public DataCell getCell(final DataRow row) {
return new IntCell(updateStatus[m_rowCount++]);
}
});
return rearr;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class MissingValueHandling2Panel method getSettings.
/**
* Get the settings currently entered in the dialog.
*
* @return the current settings
*/
public MissingValueHandling2ColSetting getSettings() {
int method;
if (m_nothingButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
} else if (m_removeButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS;
} else if (m_fixButton != null && m_fixButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_FIX_VAL;
DataCell cell;
switch(m_setting.getType()) {
case MissingValueHandling2ColSetting.TYPE_INT:
Object value = ((JFormattedTextField) m_fixText).getValue();
cell = new IntCell(((Number) value).intValue());
break;
case MissingValueHandling2ColSetting.TYPE_DOUBLE:
value = ((JFormattedTextField) m_fixText).getValue();
cell = new DoubleCell(((Number) value).doubleValue());
break;
case MissingValueHandling2ColSetting.TYPE_STRING:
value = ((JComboBox) m_fixText).getEditor().getItem();
cell = new StringCell(value.toString());
break;
default:
throw new RuntimeException("You shouldn't have come here.");
}
m_setting.setFixCell(cell);
} else if (m_maxButton != null && m_maxButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MAX;
} else if (m_minButton != null && m_minButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MIN;
} else if (m_meanButton != null && m_meanButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MEAN;
} else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT;
} else {
assert false : "One button must be selected.";
method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
}
m_setting.setMethod(method);
return m_setting;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class MissingValueHandling2TableIterator method handleMissing.
/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
DataCell[] cells = new DataCell[row.getNumCells()];
for (int i = 0; i < row.getNumCells(); i++) {
MissingValueHandling2ColSetting colset = m_table.getColSetting(i);
DataCell oldCell = row.getCell(i);
DataCell newCell;
if (oldCell.isMissing()) {
switch(colset.getMethod()) {
case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
newCell = oldCell;
break;
case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
newCell = m_table.getColSetting(i).getFixCell();
assert (newCell != null);
break;
case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
newCell = m_table.getMostFrequent(i);
break;
case MissingValueHandling2ColSetting.METHOD_MAX:
newCell = m_table.getMax(i);
break;
case MissingValueHandling2ColSetting.METHOD_MIN:
newCell = m_table.getMin(i);
break;
case MissingValueHandling2ColSetting.METHOD_MEAN:
// in contrast to the above, it will return
// a newly generate value, thus, only a double
double mean = m_table.getMean(i);
if (colset.getType() == MissingValueHandling2ColSetting.TYPE_DOUBLE) {
newCell = new DoubleCell(mean);
} else {
assert colset.getType() == MissingValueHandling2ColSetting.TYPE_INT;
newCell = new IntCell((int) Math.round(mean));
}
break;
case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
assert false : "That should have been filtered.";
newCell = oldCell;
default:
throw new RuntimeException("Invalid method!");
}
} else {
newCell = oldCell;
}
cells[i] = newCell;
}
RowKey key = row.getKey();
return new DefaultRow(key, cells);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class MissingValueHandling3TableIterator method handleMissing.
/* Does the missing value handling on a row. */
private DataRow handleMissing(final DataRow row) {
DataCell[] cells = new DataCell[row.getNumCells()];
for (int i = 0; i < row.getNumCells(); i++) {
MissingValueHandling2ColSetting colset = m_table.getColSetting(i);
DataCell oldCell = row.getCell(i);
DataCell newCell;
if (oldCell.isMissing()) {
switch(colset.getMethod()) {
case MissingValueHandling2ColSetting.METHOD_NO_HANDLING:
newCell = oldCell;
break;
case MissingValueHandling2ColSetting.METHOD_FIX_VAL:
newCell = m_table.getColSetting(i).getFixCell();
assert (newCell != null);
break;
case MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT:
newCell = m_table.getMostFrequent(i);
break;
case MissingValueHandling2ColSetting.METHOD_MAX:
newCell = m_table.getMax(i);
break;
case MissingValueHandling2ColSetting.METHOD_MIN:
newCell = m_table.getMin(i);
break;
case MissingValueHandling2ColSetting.METHOD_MEAN:
// in contrast to the above, it will return
// a newly generate value, thus, only a double
double mean = m_table.getMean(i);
if (colset.getType() == MissingValueHandling2ColSetting.TYPE_DOUBLE) {
if (Double.isNaN(mean) && m_table.getNumberNaNValues(i) == 0) {
newCell = new MissingCell("Calculated mean is not a number");
} else {
newCell = new DoubleCell(mean);
}
} else {
assert colset.getType() == MissingValueHandling2ColSetting.TYPE_INT;
if (Double.isNaN(mean)) {
newCell = new MissingCell("Calculated mean is not a number");
} else {
newCell = new IntCell((int) Math.round(mean));
}
}
break;
case MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS:
assert false : "That should have been filtered.";
newCell = oldCell;
break;
default:
throw new RuntimeException("Invalid method!");
}
} else {
newCell = oldCell;
}
cells[i] = newCell;
}
RowKey key = row.getKey();
return new DefaultRow(key, cells);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class CategoryToNumberCellFactory method getCells.
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
DataCell key = row.getCell(m_index);
if (key.isMissing()) {
return m_mapMissingTo;
}
DataCell[] value = m_categories.get(key);
if (value == null) {
if (m_categories.size() >= m_settings.getMaxCategories()) {
// maximum reached give error
throw new IllegalStateException("Maximum number of categories reached for column: " + m_columnSpecs[0].getName());
}
int number = m_settings.getStartIndex() + m_categories.size() * m_settings.getIncrement();
IntCell cell = new IntCell(number);
// Keep information in two maps for performance reasons
// This avoids creating an array every time when the category
// already exists.
value = new DataCell[] { cell };
m_categories.put(key, value);
m_map.put(key, cell);
}
return value;
}
Aggregations