use of org.knime.core.data.collection.ListCell in project knime-core by knime.
the class BlobsInSetCellWorkflowTest method createBDT.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable createBDT(final ExecutionContext exec) {
DataType t = ListCell.getCollectionType(DataType.getType(DataCell.class));
BufferedDataContainer c = exec.createDataContainer(new DataTableSpec(new DataColumnSpecCreator("Sequence", t).createSpec()));
for (int i = 0; i < ROW_COUNT; i++) {
String s = "someName_" + i;
// every other a ordinary string cell
Collection<DataCell> cells = new ArrayList<DataCell>();
for (int j = 0; j < LIST_SIZE * 2; j++) {
String val = "Row_" + i + "; Cell index " + j;
if (j % 2 == 0) {
cells.add(new LargeBlobCell(val, LargeBlobCell.SIZE_OF_CELL));
} else {
cells.add(new StringCell(val));
}
}
ListCell cell = CollectionCellFactory.createListCell(cells);
c.addRowToTable(new DefaultRow(s, cell));
}
c.close();
return c.getTable();
}
use of org.knime.core.data.collection.ListCell in project knime-core by knime.
the class DataCellToJavaConversionTest method testCollectionTypes.
/**
* Test ListCell(IntCell) -> Integer[] conversion.
*
* @throws Exception When something went wrong
*/
@Test
public void testCollectionTypes() 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(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[i]);
}
assertNull(array[5]);
}
use of org.knime.core.data.collection.ListCell in project knime-core by knime.
the class JavaToDataCellConversionTest method testCollectionTypes.
/**
* Test Integer[] -> ListCell(IntCell) conversion.
*
* @throws Exception When something went wrong
*/
@Test
public void testCollectionTypes() throws Exception {
final Integer[] coll = { 0, 1, 4, 9, 16, 25, null };
final Optional<JavaToDataCellConverterFactory<Integer[]>> factory = JavaToDataCellConverterRegistry.getInstance().getConverterFactories(Integer[].class, ListCell.getCollectionType(IntCell.TYPE)).stream().findFirst();
assertTrue(factory.isPresent());
final JavaToDataCellConverter<Integer[]> converter = factory.get().create(null);
assertNotNull(converter);
final DataCell cell = converter.convert(coll);
assertTrue(cell instanceof ListCell);
final ListCell listCell = (ListCell) converter.convert(coll);
for (int i = 0; i < 6; ++i) {
assertEquals(i * i, ((IntCell) listCell.get(i)).getIntValue());
}
assertTrue(listCell.get(6).isMissing());
}
use of org.knime.core.data.collection.ListCell in project knime-core by knime.
the class ExpressionFactoryTest method testList.
/**
* Test method for {@link ExpressionFactory#list(java.util.List)} .
*/
@Test
public void testList() {
final BooleanCell trueCell = BooleanCell.TRUE;
final BooleanCell falseCell = BooleanCell.FALSE;
final ListCell trueList = CollectionCellFactory.createListCell(Arrays.asList(trueCell));
final ListCell falseList = CollectionCellFactory.createListCell(Arrays.asList(falseCell));
final ListCell missingCellList = CollectionCellFactory.createListCell(Arrays.asList(DataType.getMissingCell()));
testForValues(m_factory.list(Arrays.asList(m_mockBoolExpression)), trueList, falseList, trueList, falseList, missingCellList);
testForValues(m_factory.list(Arrays.asList(m_mockBoolExpression, m_mockBoolExpressionOther)), CollectionCellFactory.createListCell(Arrays.asList(trueCell, trueCell)), CollectionCellFactory.createListCell(Arrays.asList(falseCell, trueCell)), CollectionCellFactory.createListCell(Arrays.asList(trueCell, falseCell)), CollectionCellFactory.createListCell(Arrays.asList(falseCell, falseCell)), CollectionCellFactory.createListCell(Arrays.asList(DataType.getMissingCell(), trueCell)));
}
use of org.knime.core.data.collection.ListCell in project knime-core by knime.
the class BlobsInSetCellPartiallySingletonsWorkflowTest method createBDT.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable createBDT(final ExecutionContext exec) {
DataType t = ListCell.getCollectionType(DataType.getType(DataCell.class));
BufferedDataContainer c = exec.createDataContainer(new DataTableSpec(new DataColumnSpecCreator("Sequence", t).createSpec()));
LargeBlobCell singleton = new LargeBlobCell("singleton", LargeBlobCell.SIZE_OF_CELL);
for (int i = 0; i < ROW_COUNT; i++) {
String s = "someName_" + i;
// every other a ordinary string cell
Collection<DataCell> cells = new ArrayList<DataCell>();
for (int j = 0; j < 4; j++) {
String val = "Row_" + i + "; Cell index " + j;
switch(j) {
case 0:
cells.add(singleton);
break;
case 1:
case 3:
cells.add(new StringCell(val));
break;
case 2:
cells.add(new LargeBlobCell(val, LargeBlobCell.SIZE_OF_CELL));
break;
default:
fail("invalid index");
}
}
ListCell cell = CollectionCellFactory.createListCell(cells);
c.addRowToTable(new DefaultRow(s, cell));
}
c.close();
return c.getTable();
}
Aggregations