All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.sources.DoubleNullToZeroColumnSource Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.sources;

import io.deephaven.engine.table.impl.AbstractColumnSource;
import io.deephaven.engine.table.impl.MutableColumnSourceGetDefaults;
import io.deephaven.util.QueryConstants;

/**
 * If you want to expose the internal state of an aggregation and compare it, then the new tables might have nulls where
 * the old tables have zero.  This wrapper prevents that spurious comparison failure.
 */
@SuppressWarnings("unused")
public class DoubleNullToZeroColumnSource extends AbstractColumnSource implements MutableColumnSourceGetDefaults.ForDouble {
    private final DoubleArraySource column;

    private DoubleNullToZeroColumnSource(DoubleArraySource column) {
        super(double.class);
        this.column = column;
    }

    @Override
    public void startTrackingPrevValues() {
        // Nothing to do.
    }

    @Override
    public double getDouble(long rowKey) {
        final double value = column.getDouble(rowKey);
        return nullToZero(value);
    }

    @Override
    public double getPrevDouble(long rowKey) {
        final double value = column.getPrevDouble(rowKey);
        return nullToZero(value);
    }

    private static double nullToZero(double value) {
        return value == QueryConstants.NULL_DOUBLE ? 0 : value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy