use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class DataTableDomainCreatorTest method testPossibleValues.
/**
* Checks whether possible values are computed correctly.
*/
@Test
public void testPossibleValues() {
DataColumnSpecCreator colSpecCrea = new DataColumnSpecCreator("String col", StringCell.TYPE);
DataTableSpec tableSpec = new DataTableSpec(colSpecCrea.createSpec());
RowKey rowKey = new RowKey("Row0");
DataTableDomainCreator domainCreator = new DataTableDomainCreator(tableSpec, false);
domainCreator.setMaxPossibleValues(2);
// initially no values
Set<DataCell> expectedValues = new LinkedHashSet<>();
DataColumnDomain colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected possible values", colDomain.getValues(), is(expectedValues));
// add two values
expectedValues.add(new StringCell("v1"));
domainCreator.updateDomain(new DefaultRow(rowKey, "v1"));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected possible values", colDomain.getValues(), is(expectedValues));
expectedValues.add(new StringCell("v2"));
domainCreator.updateDomain(new DefaultRow(rowKey, "v2"));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected possible values", colDomain.getValues(), is(expectedValues));
// add more than the maximum number removes all values
domainCreator.updateDomain(new DefaultRow(rowKey, "v3"));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected possible values", colDomain.getValues(), is(nullValue()));
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class DataContainerTest method generateRows.
private static RowIterator generateRows(final int count) {
return new RowIterator() {
private int m_index = 0;
@Override
public DataRow next() {
DefaultRow r = new DefaultRow(RowKey.createRowKey(m_index), new StringCell("String " + m_index), new IntCell(m_index), new DoubleCell(m_index));
m_index++;
return r;
}
@Override
public boolean hasNext() {
return m_index < count;
}
};
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class DataContainerTest method testDuplicateKey.
/**
* method being tested: addRowToTable().
*/
public final void testDuplicateKey() {
String[] colNames = new String[] { "Column 1", "Column 2" };
DataType[] colTypes = new DataType[] { StringCell.TYPE, IntCell.TYPE };
DataTableSpec spec1 = new DataTableSpec(colNames, colTypes);
DataContainer c = new DataContainer(spec1);
RowKey r1Key = new RowKey("row 1");
DataCell r1Cell1 = new StringCell("Row 1, Cell 1");
DataCell r1Cell2 = new IntCell(12);
DataRow r1 = new DefaultRow(r1Key, new DataCell[] { r1Cell1, r1Cell2 });
RowKey r2Key = new RowKey("row 2");
DataCell r2Cell1 = new StringCell("Row 2, Cell 1");
DataCell r2Cell2 = new IntCell(22);
DataRow r2 = new DefaultRow(r2Key, new DataCell[] { r2Cell1, r2Cell2 });
c.addRowToTable(r1);
c.addRowToTable(r2);
// add row 1 twice
try {
c.addRowToTable(r1);
c.close();
// ... eh eh, you don't do this
fail("Expected " + DuplicateKeyException.class + " not thrown");
} catch (DuplicateKeyException e) {
NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass(), e);
}
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class DataContainerTest method testIncompatibleTypes.
/**
* method being tested: addRowToTable().
*/
public final void testIncompatibleTypes() {
String[] colNames = new String[] { "Column 1", "Column 2" };
DataType[] colTypes = new DataType[] { StringCell.TYPE, IntCell.TYPE };
DataTableSpec spec1 = new DataTableSpec(colNames, colTypes);
DataContainer c = new DataContainer(spec1);
RowKey r1Key = new RowKey("row 1");
DataCell r1Cell1 = new StringCell("Row 1, Cell 1");
DataCell r1Cell2 = new IntCell(12);
DataRow r1 = new DefaultRow(r1Key, new DataCell[] { r1Cell1, r1Cell2 });
RowKey r2Key = new RowKey("row 2");
DataCell r2Cell1 = new StringCell("Row 2, Cell 1");
DataCell r2Cell2 = new IntCell(22);
DataRow r2 = new DefaultRow(r2Key, new DataCell[] { r2Cell1, r2Cell2 });
RowKey r3Key = new RowKey("row 3");
DataCell r3Cell1 = new StringCell("Row 3, Cell 1");
DataCell r3Cell2 = new IntCell(32);
DataRow r3 = new DefaultRow(r3Key, new DataCell[] { r3Cell1, r3Cell2 });
c.addRowToTable(r1);
c.addRowToTable(r2);
c.addRowToTable(r3);
// add incompatible types
RowKey r4Key = new RowKey("row 4");
DataCell r4Cell1 = new StringCell("Row 4, Cell 1");
// not allowed
DataCell r4Cell2 = new DoubleCell(42.0);
DataRow r4 = new DefaultRow(r4Key, new DataCell[] { r4Cell1, r4Cell2 });
try {
c.addRowToTable(r4);
c.close();
fail("Expected " + DataContainerException.class + " not thrown");
} catch (DataContainerException e) {
if (!(e.getCause() instanceof IllegalArgumentException)) {
throw e;
} else {
NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getCause().getClass(), e.getCause());
}
} catch (IllegalArgumentException e) {
NodeLogger.getLogger(getClass()).debug("Got expected exception: " + e.getClass(), e);
}
}
use of org.knime.core.data.def.StringCell in project knime-core by knime.
the class JavaToDataCellConversionTest method testToStringCell.
/**
* Test String -> StringCell and Object -> StringCell conversions.
*
* @throws Exception When something went wrong
*/
@Test
public void testToStringCell() throws Exception {
final StringCell cell = testSimpleConversion(String.class, StringCell.TYPE, StringCell.class, new String("KNIME"));
assertEquals("KNIME", cell.getStringValue());
}
Aggregations