use of org.knime.core.data.def.StringCell 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.StringCell in project knime-core by knime.
the class AbstractMany2OneCellFactory method getCells.
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
// find matching values
int matchingValue = findColumnIndex(row);
DataCell newCell;
if (matchingValue == -1) {
newCell = DataType.getMissingCell();
} else {
newCell = new StringCell(m_inputSpec.getColumnSpec(matchingValue).getName());
}
return new DataCell[] { newCell };
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class DomainDialog method addStringPosValue.
/**
* Called when the user pressed the "Add" button to add a string value to the list of possible values.
*/
protected void addStringPosValue() {
if (m_editField.getText().length() > 0) {
addDataCellPossValue(new StringCell(m_editField.getText()));
m_editField.setText("");
}
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class AppendVariableToTable2NodeModel method createColumnRearranger.
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) throws InvalidSettingsException {
ColumnRearranger arranger = new ColumnRearranger(spec);
Set<String> nameHash = new HashSet<String>();
for (DataColumnSpec c : spec) {
nameHash.add(c.getName());
}
List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
if (vars.isEmpty()) {
throw new InvalidSettingsException("No variables selected");
}
DataColumnSpec[] specs = new DataColumnSpec[vars.size()];
final DataCell[] values = new DataCell[vars.size()];
for (int i = 0; i < vars.size(); i++) {
Pair<String, FlowVariable.Type> c = vars.get(i);
String name = c.getFirst();
final DataType type;
switch(c.getSecond()) {
case DOUBLE:
type = DoubleCell.TYPE;
try {
double dValue = peekFlowVariableDouble(name);
values[i] = new DoubleCell(dValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type double): " + name);
}
break;
case INTEGER:
type = IntCell.TYPE;
try {
int iValue = peekFlowVariableInt(name);
values[i] = new IntCell(iValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type int): " + name);
}
break;
case STRING:
type = StringCell.TYPE;
try {
String sValue = peekFlowVariableString(name);
sValue = sValue == null ? "" : sValue;
values[i] = new StringCell(sValue);
} catch (NoSuchElementException e) {
throw new InvalidSettingsException("No such flow variable (of type String): " + name);
}
break;
default:
throw new InvalidSettingsException("Unsupported variable type: " + c.getSecond());
}
if (nameHash.contains(name) && !name.toLowerCase().endsWith("(variable)")) {
name = name.concat(" (variable)");
}
String newName = name;
int uniquifier = 1;
while (!nameHash.add(newName)) {
newName = name + " (#" + (uniquifier++) + ")";
}
specs[i] = new DataColumnSpecCreator(newName, type).createSpec();
}
arranger.append(new AbstractCellFactory(specs) {
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
return values;
}
});
return arranger;
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class UniqueConcatenateOperator method getResultInternal.
/**
* {@inheritDoc}
*/
@Override
protected DataCell getResultInternal() {
final Set<DataCell> groupMembers = getGroupMembers();
if (groupMembers.isEmpty()) {
return DataType.getMissingCell();
}
final StringBuilder buf = new StringBuilder();
boolean first = true;
for (final DataCell val : groupMembers) {
if (first) {
first = false;
} else {
buf.append(getValueDelimiter());
}
buf.append(val.toString());
}
return new StringCell(buf.toString());
}
Aggregations