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

io.deephaven.engine.table.impl.sources.regioned.RegionedColumnSourceReferencing 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.regioned;

import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.impl.locations.ColumnLocation;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.SharedContext;
import org.jetbrains.annotations.NotNull;

import javax.annotation.OverridingMethodsMustInvokeSuper;

/**
 * Base class for a column of {@code DATA_TYPE} which is a wrapped {@code NATIVE_DATA_TYPE}. The column owns the
 * underlying native column and its resources.
 */
abstract class RegionedColumnSourceReferencing>
        extends RegionedColumnSourceBase>
        implements ColumnRegionReferencingImpl.Converter {

    @NotNull
    private final ColumnRegionReferencing.Null nullRegion;

    @NotNull
    private final RegionedColumnSourceBase nativeSource;

    RegionedColumnSourceReferencing(@NotNull final NATIVE_REGION_TYPE nullRegion,
            @NotNull Class type,
            @NotNull RegionedColumnSourceBase nativeSource) {
        super(type);
        this.nullRegion = new ColumnRegionReferencing.Null<>(nullRegion);
        this.nativeSource = nativeSource;
    }

    @Override
    @OverridingMethodsMustInvokeSuper
    public  boolean allowsReinterpret(
            @NotNull final Class alternateDataType) {
        return nativeSource.getType() == alternateDataType || nativeSource.allowsReinterpret(alternateDataType);
    }

    @Override
    @OverridingMethodsMustInvokeSuper
    protected  ColumnSource doReinterpret(
            @NotNull final Class alternateDataType) {
        // noinspection unchecked
        return nativeSource.getType() == alternateDataType ? (ColumnSource) nativeSource
                : nativeSource.reinterpret(alternateDataType);
    }

    @Override
    public ColumnRegionReferencing getRegion(int regionIndex) {
        final NATIVE_REGION_TYPE nativeRegion = nativeSource.getRegion(regionIndex);
        if (nativeRegion == nativeSource.getNullRegion()) {
            return nullRegion;
        }

        return new ColumnRegionReferencingImpl<>(nativeRegion);
    }

    @Override
    public int getRegionCount() {
        return nativeSource.getRegionCount();
    }

    @Override
    public int addRegion(@NotNull ColumnDefinition columnDefinition, @NotNull ColumnLocation columnLocation) {
        return nativeSource.addRegion(columnDefinition, columnLocation);
    }

    @Override
     int addRegionForUnitTests(OTHER_REGION_TYPE region) {
        return nativeSource.addRegionForUnitTests(region);
    }

    @Override
    public FillContext makeFillContext(int chunkCapacity, SharedContext sharedContext) {
        return new ColumnRegionReferencingImpl.FillContext<>(nativeSource, this, chunkCapacity, sharedContext);
    }

    @NotNull
    @Override
    public ColumnRegionReferencing.Null getNullRegion() {
        return nullRegion;
    }

    @NotNull
    public RegionedColumnSourceBase getNativeSource() {
        return nativeSource;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy