Search in sources :

Example 16 with LongCell

use of org.knime.core.data.def.LongCell in project knime-core by knime.

the class AverageInterpolationStatisticMB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(m_colIdx);
    if (cell.isMissing()) {
        m_numMissing++;
    } else {
        DataCell res;
        if (m_previous.isMissing()) {
            res = cell;
        } else {
            if (m_isDateColumn) {
                DateAndTimeValue val = (DateAndTimeValue) cell;
                DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
                boolean hasDate = val.hasDate() | prevVal.hasDate();
                boolean hasTime = val.hasTime() | prevVal.hasTime();
                boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                long prev = prevVal.getUTCTimeInMillis();
                long next = val.getUTCTimeInMillis();
                long lin = Math.round((prev + next) / 2);
                res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
            } else {
                DoubleValue val = (DoubleValue) cell;
                double prev = ((DoubleValue) m_previous).getDoubleValue();
                double next = val.getDoubleValue();
                double lin = (prev + next) / 2;
                if (m_previous instanceof IntValue) {
                    // get an int, create an int
                    res = new IntCell((int) Math.round(lin));
                } else if (m_previous instanceof LongValue) {
                    // get an long, create an long
                    res = new LongCell(Math.round(lin));
                } else {
                    res = new DoubleCell(lin);
                }
            }
        }
        for (int i = 0; i < m_numMissing; i++) {
            m_values.add(res);
        }
        m_previous = cell;
        m_numMissing = 0;
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 17 with LongCell

use of org.knime.core.data.def.LongCell in project knime-core by knime.

the class OutputRow method createDataRow.

/**
 * Create a {@link DataRow} that stores information of a inner or
 * outer joins.
 *
 * @param index The index of this row.
 * @param leftIndex The index of the left row.
 * @param rightIndex The index of the right row.
 * @param rightDataRow The right row.
 * @param settings The common settings object.
 * @return New instance of {@link DataRow} populated with the given
 * information.
 */
static DataRow createDataRow(final long index, final long leftIndex, final long rightIndex, final DataRow rightDataRow, final OutputRow.Settings settings) {
    int[] survivors = settings.getSurvivors();
    DataCell[] cells = new DataCell[survivors.length + 3];
    int c = 0;
    for (int i = 0; i < survivors.length; i++) {
        cells[c] = rightDataRow.getCell(survivors[i]);
        c++;
    }
    cells[c] = new StringCell(rightDataRow.getKey().getString());
    c++;
    cells[c] = new LongCell(leftIndex);
    c++;
    cells[c] = new LongCell(rightIndex);
    RowKey rowID = new RowKey(Long.toString(index));
    return new DefaultRow(rowID, cells);
}
Also used : LongCell(org.knime.core.data.def.LongCell) StringCell(org.knime.core.data.def.StringCell) RowKey(org.knime.core.data.RowKey) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 18 with LongCell

use of org.knime.core.data.def.LongCell in project knime-core by knime.

the class ExpressionFactoryTest method testTableRef.

/**
 * Test method for {@link ExpressionFactory#tableRef(Rule.TableReference)} .
 */
@Test
public void testTableRef() {
    assertEquals(new LongCell(2), m_factory.tableRef(TableReference.RowCount).evaluate(null, new VariableProvider() {

        @Override
        public Object readVariable(final String name, final Class<?> type) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getRowCountLong() {
            return 2L;
        }

        @Override
        public long getRowIndexLong() {
            return 0L;
        }

        @Deprecated
        @Override
        public int getRowCount() {
            return 0;
        }

        @Deprecated
        @Override
        public int getRowIndex() {
            return 0;
        }
    }).getValue());
    assertEquals(new LongCell(3), m_factory.tableRef(TableReference.RowIndex).evaluate(null, new VariableProvider() {

        @Override
        public Object readVariable(final String name, final Class<?> type) {
            return null;
        }

        @Override
        public long getRowCountLong() {
            return 0L;
        }

        @Override
        public long getRowIndexLong() {
            return 3L;
        }

        @Deprecated
        @Override
        public int getRowCount() {
            return 0;
        }

        @Deprecated
        @Override
        public int getRowIndex() {
            return 0;
        }
    }).getValue());
    assertEquals(new StringCell("Row0"), m_factory.tableRef(TableReference.RowId).evaluate(new DefaultRow(new RowKey("Row0"), new IntCell(3)), new VariableProvider() {

        @Override
        public Object readVariable(final String name, final Class<?> type) {
            // TODO Auto-generated method stub
            return null;
        }

        @Deprecated
        @Override
        public int getRowCount() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Deprecated
        @Override
        public int getRowIndex() {
            // TODO Auto-generated method stub
            return 0;
        }
    }).getValue());
}
Also used : LongCell(org.knime.core.data.def.LongCell) StringCell(org.knime.core.data.def.StringCell) RowKey(org.knime.core.data.RowKey) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Aggregations

LongCell (org.knime.core.data.def.LongCell)18 IntCell (org.knime.core.data.def.IntCell)14 DataCell (org.knime.core.data.DataCell)10 DoubleCell (org.knime.core.data.def.DoubleCell)10 LongValue (org.knime.core.data.LongValue)8 StringCell (org.knime.core.data.def.StringCell)7 DoubleValue (org.knime.core.data.DoubleValue)6 IntValue (org.knime.core.data.IntValue)6 DateAndTimeCell (org.knime.core.data.date.DateAndTimeCell)6 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)6 RowKey (org.knime.core.data.RowKey)4 DefaultRow (org.knime.core.data.def.DefaultRow)4 DataRow (org.knime.core.data.DataRow)3 Test (org.junit.Test)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)2 DataType (org.knime.core.data.DataType)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ArrayList (java.util.ArrayList)1