Search in sources :

Example 26 with IntCell

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataContainer(org.knime.core.data.container.DataContainer) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Color(java.awt.Color) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 27 with IntCell

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);
}
Also used : JavaToDataCellConverterFactory(org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Example 28 with IntCell

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)));
}
Also used : DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Example 29 with IntCell

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;
        }
    };
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) RowIterator(org.knime.core.data.RowIterator) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 30 with IntCell

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);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) DuplicateKeyException(org.knime.core.util.DuplicateKeyException) IntCell(org.knime.core.data.def.IntCell) StringCell(org.knime.core.data.def.StringCell) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

IntCell (org.knime.core.data.def.IntCell)109 DataCell (org.knime.core.data.DataCell)79 DoubleCell (org.knime.core.data.def.DoubleCell)67 StringCell (org.knime.core.data.def.StringCell)55 DefaultRow (org.knime.core.data.def.DefaultRow)46 DataRow (org.knime.core.data.DataRow)33 DataTableSpec (org.knime.core.data.DataTableSpec)21 RowKey (org.knime.core.data.RowKey)21 ArrayList (java.util.ArrayList)20 DataType (org.knime.core.data.DataType)20 LongCell (org.knime.core.data.def.LongCell)14 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)14 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 Test (org.junit.Test)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 DataContainer (org.knime.core.data.container.DataContainer)8 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)8