use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class ExpressionFactoryTest method testConstantStringDataType.
/**
* Test method for {@link ExpressionFactory#constant(String, DataType)} .
*/
@Test
public void testConstantStringDataType() {
final Expression hello = m_factory.constant("Hello", StringCell.TYPE);
assertTrue(hello.isConstant());
final ExpressionValue mockResult = hello.evaluate(m_rows[0], null);
assertEquals(new StringCell("Hello"), mockResult.getValue());
assertEquals(new StringCell("Hello"), hello.evaluate(m_rows[0], null).getValue());
assertEquals(Collections.emptyMap(), mockResult.getMatchedObjects());
final ExpressionValue nullResult = hello.evaluate(null, null);
assertEquals(new StringCell("Hello"), nullResult.getValue());
assertEquals(Collections.emptyMap(), nullResult.getMatchedObjects());
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class ExpressionFactoryTest method testColumnRef.
/**
* Test method for {@link ExpressionFactory#columnRef(DataTableSpec, java.lang.String)} .
*/
@Test
public void testColumnRef() {
final DefaultRow row0 = new DefaultRow(new RowKey("0"), new IntCell(3));
final DefaultRow row1 = new DefaultRow(new RowKey("1"), new IntCell(3), new DoubleCell(3.14159));
final DefaultRow row2 = new DefaultRow(new RowKey("1"), new DoubleCell(3.14159), new StringCell("Hi"));
final ExpressionValue firstVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num" }, new DataType[] { IntCell.TYPE }), "Num").evaluate(row0, null);
assertEquals(row0.getCell(0), firstVal.getValue());
assertEquals(row1.getCell(0), m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Num").evaluate(row0, null).getValue());
final ExpressionValue secondVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Pi").evaluate(row1, null);
assertEquals(row1.getCell(1), secondVal.getValue());
final ExpressionValue thirdVal = m_factory.columnRef(new DataTableSpec(new String[] { "Pi", "Greeting" }, new DataType[] { DoubleCell.TYPE, StringCell.TYPE }), "Greeting").evaluate(row2, null);
assertEquals(row2.getCell(1), thirdVal.getValue());
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class MissingValuePanel method getSettings.
/**
* Get the settings currently entered in the dialog.
*
* @return the current settings
*/
public ColSetting getSettings() {
int method;
if (m_nothingButton.isSelected()) {
method = ColSetting.METHOD_NO_HANDLING;
} else if (m_removeButton.isSelected()) {
method = ColSetting.METHOD_IGNORE_ROWS;
} else if (m_fixButton != null && m_fixButton.isSelected()) {
method = ColSetting.METHOD_FIX_VAL;
DataCell cell;
switch(m_setting.getType()) {
case ColSetting.TYPE_INT:
Object value = ((JFormattedTextField) m_fixText).getValue();
cell = new IntCell(((Number) value).intValue());
break;
case ColSetting.TYPE_DOUBLE:
value = ((JFormattedTextField) m_fixText).getValue();
cell = new DoubleCell(((Number) value).doubleValue());
break;
case ColSetting.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 = ColSetting.METHOD_MAX;
} else if (m_minButton != null && m_minButton.isSelected()) {
method = ColSetting.METHOD_MIN;
} else if (m_meanButton != null && m_meanButton.isSelected()) {
method = ColSetting.METHOD_MEAN;
} else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
method = ColSetting.METHOD_MOST_FREQUENT;
} else {
assert false : "One button must be selected.";
method = ColSetting.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 HiLiteCollectorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
if (m_annotationMap.isEmpty()) {
return inData;
}
DataTableSpec inSpec = (DataTableSpec) inData[0].getSpec();
final DataColumnSpec[] cspecs = createSpecs(inSpec);
ColumnRearranger cr = new ColumnRearranger(inSpec);
cr.append(new CellFactory() {
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
if (m_annotationMap.isEmpty()) {
return new DataCell[0];
}
DataCell[] cells = new DataCell[m_lastIndex + 1];
for (int i = 0; i < cells.length; i++) {
Map<Integer, String> map = m_annotationMap.get(row.getKey());
if (map == null) {
cells[i] = DataType.getMissingCell();
} else {
String str = map.get(i);
if (str == null) {
cells[i] = DataType.getMissingCell();
} else {
cells[i] = new StringCell(str);
}
}
}
return cells;
}
@Override
public DataColumnSpec[] getColumnSpecs() {
return cspecs;
}
/**
* {@inheritDoc}
*/
@Override
public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor em) {
em.setProgress((double) curRowNr / rowCount);
}
});
return new BufferedDataTable[] { exec.createColumnRearrangeTable((BufferedDataTable) inData[0], cr, exec) };
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class BatchExecutor method setNodeOptions.
private static void setNodeOptions(final Collection<Option> options, final WorkflowManager wfm) throws InvalidSettingsException, IllegalOptionException {
for (Option o : options) {
int[] idPath = o.m_nodeIDs;
NodeID subID = new NodeID(wfm.getID(), idPath[0]);
NodeContainer cont = null;
try {
cont = wfm.getNodeContainer(subID);
for (int i = 1; i < idPath.length; i++) {
if (cont instanceof WorkflowManager) {
WorkflowManager subWM = (WorkflowManager) cont;
subID = new NodeID(subID, idPath[i]);
cont = subWM.getNodeContainer(subID);
} else {
cont = null;
}
}
} catch (IllegalArgumentException ex) {
// throw by getNodeContainer if no node with the id exists
cont = null;
}
if (cont == null) {
LOGGER.warn("No node with id " + Arrays.toString(idPath) + " found.");
} else {
WorkflowManager parent = cont.getParent();
NodeSettings settings = new NodeSettings("something");
parent.saveNodeSettings(cont.getID(), settings);
NodeSettings model = settings.getNodeSettings(Node.CFG_MODEL);
String[] splitName = o.m_name.split("/");
String name = splitName[splitName.length - 1];
String[] pathElements = new String[splitName.length - 1];
System.arraycopy(splitName, 0, pathElements, 0, pathElements.length);
for (String s : pathElements) {
model = model.getNodeSettings(s);
}
if ("int".equals(o.m_type)) {
model.addInt(name, Integer.parseInt(o.m_value));
} else if ("long".equals(o.m_type)) {
model.addLong(name, Long.parseLong(o.m_value));
} else if ("short".equals(o.m_type)) {
model.addShort(name, Short.parseShort(o.m_value));
} else if ("byte".equals(o.m_type)) {
model.addByte(name, Byte.parseByte(o.m_value));
} else if ("boolean".equals(o.m_type)) {
model.addBoolean(name, Boolean.parseBoolean(o.m_value));
} else if ("char".equals(o.m_type)) {
model.addChar(name, o.m_value.charAt(0));
} else if ("float".equals(o.m_type) || ("double".equals(o.m_type))) {
model.addDouble(name, Double.parseDouble(o.m_value));
} else if ("String".equals(o.m_type)) {
model.addString(name, o.m_value);
} else if ("StringCell".equals(o.m_type)) {
model.addDataCell(name, new StringCell(o.m_value));
} else if ("DoubleCell".equals(o.m_type)) {
double d = Double.parseDouble(o.m_value);
model.addDataCell(name, new DoubleCell(d));
} else if ("IntCell".equals(o.m_type)) {
int i = Integer.parseInt(o.m_value);
model.addDataCell(name, new IntCell(i));
} else if ("LongCell".equals(o.m_type)) {
long i = Long.parseLong(o.m_value);
model.addDataCell(name, new LongCell(i));
} else {
throw new IllegalOptionException("Unknown option type for " + o.m_name + ": " + o.m_type);
}
parent.loadNodeSettings(cont.getID(), settings);
}
}
}
Aggregations