use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ColorExtractNodeModel method extractColorTable.
/**
* @param nom
* @return
* @throws InvalidSettingsException
*/
private DataTable extractColorTable(final ColorModelNominal nom) throws InvalidSettingsException {
DataType superType = null;
for (DataCell c : nom) {
if (superType == null) {
superType = c.getType();
} else {
superType = DataType.getCommonSuperType(superType, c.getType());
}
}
if (superType == null) {
throw new InvalidSettingsException("No nominal values in model");
}
DataTableSpec spec = createSpec(superType);
DataContainer cnt = new DataContainer(spec);
int counter = 0;
for (DataCell c : nom) {
Color clr = nom.getColorAttr(c).getColor();
DataRow row = new DefaultRow(RowKey.createRowKey(counter++), c, new IntCell(clr.getRed()), new IntCell(clr.getGreen()), new IntCell(clr.getBlue()), new IntCell(clr.getAlpha()), new IntCell(clr.getRGB()));
cnt.addRowToTable(row);
}
cnt.close();
return cnt.getTable();
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class ExtensionPointTest method testJavaToDataCell.
/**
* Test whether {@link StringToIntCellTestConverterFactory} was correctly registered at the
* "org.knime.core.JavaToDataCellConverter" extension point and can be used for conversion.
*
* @throws Exception When something went wrong
*/
@Test
public void testJavaToDataCell() throws Exception {
final Optional<JavaToDataCellConverterFactory<String>> factory = JavaToDataCellConverterRegistry.getInstance().getConverterFactories(String.class, IntCell.TYPE).stream().findFirst();
assertTrue(factory.isPresent());
final JavaToDataCellConverter<String> converter = factory.get().create(null);
assertNotNull(converter);
final IntCell convert = (IntCell) converter.convert("Answer to Life, the Universe, and Everything");
assertEquals(convert.getIntValue(), 42);
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class DataTableDomainCreatorTest method testInitBounds.
/**
* Checks whether bounds are initialized correctly if requested.
*/
@Test
public void testInitBounds() {
DataColumnSpecCreator colSpecCrea = new DataColumnSpecCreator("Int col", IntCell.TYPE);
DataColumnDomainCreator domainCrea = new DataColumnDomainCreator();
domainCrea.setLowerBound(new IntCell(-2));
domainCrea.setUpperBound(new IntCell(2));
colSpecCrea.setDomain(domainCrea.createDomain());
DataColumnSpec intColSpec = colSpecCrea.createSpec();
DataTableSpec tableSpec = new DataTableSpec(intColSpec);
RowKey rowKey = new RowKey("Row0");
DataTableDomainCreator domainCreator = new DataTableDomainCreator(tableSpec, true);
// check initialized bounds
DataColumnDomain colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new IntCell(-2)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new IntCell(2)));
domainCreator.updateDomain(new DefaultRow(rowKey, new IntCell(1)));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new IntCell(-2)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new IntCell(2)));
domainCreator.updateDomain(new DefaultRow(rowKey, new IntCell(3)));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new IntCell(-2)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new IntCell(3)));
domainCreator.updateDomain(new DefaultRow(rowKey, new IntCell(-3)));
colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
assertThat("Unexpected lower bound", colDomain.getLowerBound(), is((DataCell) new IntCell(-3)));
assertThat("Unexpected upper bound", colDomain.getUpperBound(), is((DataCell) new IntCell(3)));
}
use of org.knime.core.data.def.IntCell 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.IntCell 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);
}
}
Aggregations