Search in sources :

Example 1 with ListCell

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ListCell(org.knime.core.data.collection.ListCell) ArrayList(java.util.ArrayList) LargeBlobCell(org.knime.testing.data.blob.LargeBlobCell) 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)

Example 2 with ListCell

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

Example 3 with ListCell

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());
}
Also used : ListCell(org.knime.core.data.collection.ListCell) DataCell(org.knime.core.data.DataCell) BinaryObjectDataCell(org.knime.core.data.blob.BinaryObjectDataCell) JavaToDataCellConverterFactory(org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory) Test(org.junit.Test)

Example 4 with ListCell

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

Example 5 with ListCell

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ListCell(org.knime.core.data.collection.ListCell) ArrayList(java.util.ArrayList) LargeBlobCell(org.knime.testing.data.blob.LargeBlobCell) 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

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