Search in sources :

Example 6 with ListCell

use of org.knime.core.data.collection.ListCell in project knime-core by knime.

the class DataCellToJavaConversionTest method testNestedCollectionTypes.

/**
 * Test ListCell(ListCell(IntCell)) -> Integer[][] conversion.
 *
 * @throws Exception When something went wrong
 */
@Test
public void testNestedCollectionTypes() throws Exception {
    ArrayList<DataCell> coll = new ArrayList<>();
    for (int i = 0; i < 5; ++i) {
        coll.add(new IntCell(i * i));
    }
    // collection cells can always contain missing cells.
    coll.add(new MissingCell("42"));
    final ListCell listCell = CollectionCellFactory.createListCell(Arrays.asList(CollectionCellFactory.createListCell(coll)));
    final Optional<? extends DataCellToJavaConverterFactory<? extends DataValue, Integer[][]>> factory = DataCellToJavaConverterRegistry.getInstance().getConverterFactories(listCell.getType(), Integer[][].class).stream().findFirst();
    assertTrue(factory.isPresent());
    final DataCellToJavaConverter<DataCell, Integer[][]> converter = (DataCellToJavaConverter<DataCell, Integer[][]>) factory.get().create();
    assertNotNull(converter);
    final Integer[][] array = converter.convert(listCell);
    for (int i = 0; i < 5; ++i) {
        assertEquals(new Integer(i * i), array[0][i]);
    }
    assertNull(array[0][5]);
}
Also used : DataCellToJavaConverter(org.knime.core.data.convert.java.DataCellToJavaConverter) MissingCell(org.knime.core.data.MissingCell) ListCell(org.knime.core.data.collection.ListCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) BinaryObjectDataCell(org.knime.core.data.blob.BinaryObjectDataCell) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Aggregations

ListCell (org.knime.core.data.collection.ListCell)6 DataCell (org.knime.core.data.DataCell)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 BinaryObjectDataCell (org.knime.core.data.blob.BinaryObjectDataCell)3 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 DataType (org.knime.core.data.DataType)2 MissingCell (org.knime.core.data.MissingCell)2 DataCellToJavaConverter (org.knime.core.data.convert.java.DataCellToJavaConverter)2 DefaultRow (org.knime.core.data.def.DefaultRow)2 IntCell (org.knime.core.data.def.IntCell)2 StringCell (org.knime.core.data.def.StringCell)2 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)2 LargeBlobCell (org.knime.testing.data.blob.LargeBlobCell)2 JavaToDataCellConverterFactory (org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory)1 BooleanCell (org.knime.core.data.def.BooleanCell)1