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]);
}
Aggregations