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

io.deephaven.engine.table.impl.sources.AbstractDeferredGroupingColumnSource 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.Pair;
import io.deephaven.engine.table.impl.AbstractColumnSource;
import io.deephaven.engine.table.impl.locations.GroupingProvider;
import io.deephaven.engine.rowset.RowSet;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

/**
 * Adds deferred grouping support to {@link AbstractColumnSource}.
 */
public abstract class AbstractDeferredGroupingColumnSource extends AbstractColumnSource
        implements DeferredGroupingColumnSource {

    private transient volatile GroupingProvider groupingProvider;

    protected AbstractDeferredGroupingColumnSource(Class type) {
        super(type, null);
    }

    protected AbstractDeferredGroupingColumnSource(Class type, Class componentType) {
        super(type, componentType);
    }

    @Override
    public GroupingProvider getGroupingProvider() {
        return groupingProvider;
    }

    /**
     * Set a grouping provider for use in lazily-constructing groupings.
     *
     * @param groupingProvider The {@link GroupingProvider} to use
     */
    @Override
    public final void setGroupingProvider(@Nullable GroupingProvider groupingProvider) {
        this.groupingProvider = groupingProvider;
    }

    @Override
    public final Map getGroupToRange() {
        if (groupToRange == null && groupingProvider != null) {
            groupToRange = groupingProvider.getGroupToRange();
            groupingProvider = null;
        }
        return groupToRange;
    }

    @Override
    public final Map getGroupToRange(RowSet rowSet) {
        if (groupToRange == null && groupingProvider != null) {
            Pair, Boolean> result = groupingProvider.getGroupToRange(rowSet);
            if (result == null) {
                return null;
            }
            if (result.second) {
                groupToRange = result.first;
                groupingProvider = null;
            }
            return result.first;
        }
        return groupToRange;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy