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

io.deephaven.engine.table.impl.sources.UngroupedObjectVectorColumnSource 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.base.verify.Assert;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.MutableColumnSourceGetDefaults;
import io.deephaven.vector.ObjectVector;

public class UngroupedObjectVectorColumnSource extends UngroupedColumnSource
        implements MutableColumnSourceGetDefaults.ForObject {
    private final ColumnSource> innerSource;
    private final boolean isUngroupable;

    @Override
    public Class getComponentType() {
        return innerSource.getComponentType().getComponentType();
    }

    public UngroupedObjectVectorColumnSource(ColumnSource> innerSource) {
        // noinspection unchecked
        super((Class) innerSource.getComponentType());
        this.innerSource = innerSource;
        this.isUngroupable = innerSource instanceof UngroupableColumnSource
                && ((UngroupableColumnSource) innerSource).isUngroupable();
    }

    @Override
    public T get(long rowKey) {
        if (rowKey < 0) {
            return null;
        }
        long segment = rowKey >> base;
        long offset = rowKey & ((1 << base) - 1);
        if (isUngroupable) {
            // noinspection unchecked
            return (T) ((UngroupableColumnSource) innerSource).getUngrouped(segment, (int) offset);
        } else {
            return (innerSource.get(segment)).get((int) offset);
        }
    }

    @Override
    public T getPrev(long rowKey) {
        if (rowKey < 0) {
            return null;
        }
        long segment = rowKey >> getPrevBase();
        long offset = rowKey & ((1 << getPrevBase()) - 1);

        if (isUngroupable) {
            // noinspection unchecked
            return (T) ((UngroupableColumnSource) innerSource).getUngroupedPrev(segment, (int) offset);
        } else {
            Assert.neqNull(innerSource, "innerSource");
            ObjectVector prevArray = innerSource.getPrev(segment);
            Assert.neqNull(prevArray, "prevArray");
            return prevArray.get((int) offset);
        }
    }

    @Override
    public Boolean getBoolean(long rowKey) {
        return (Boolean) get(rowKey);
    }

    @Override
    public Boolean getPrevBoolean(long rowKey) {
        return (Boolean) getPrev(rowKey);
    }

    @Override
    public boolean isImmutable() {
        return innerSource.isImmutable();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy