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

io.deephaven.engine.table.impl.select.python.ArgumentsSingular 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.select.python;

import io.deephaven.chunk.attributes.Any;
import io.deephaven.chunk.*;
import io.deephaven.chunk.Chunk.Visitor;
import io.deephaven.util.PrimitiveArrayType;

import java.util.Objects;
import java.util.stream.Stream;

class ArgumentsSingular {

    static Class[] buildParamTypes(Chunk[] __sources) {
        return Stream.of(__sources)
                .map(c -> c.walk(new ChunkToSingularType<>()))
                .map(ChunkToSingularType::getOut)
                .toArray(Class[]::new);
    }

    static Object[] buildArguments(Chunk[] __sources, int index) {
        return Stream.of(__sources)
                .map(c -> c.walk(new ChunkIndexToObject<>(index)))
                .map(ChunkIndexToObject::getOut)
                .toArray();
    }

    private static class ChunkIndexToObject implements Visitor {

        private final int index;

        private Object out;

        ChunkIndexToObject(int index) {
            this.index = index;
        }

        Object getOut() {
            return out;
        }

        @Override
        public void visit(ByteChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(BooleanChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(CharChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(ShortChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(IntChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(LongChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(FloatChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public void visit(DoubleChunk chunk) {
            out = chunk.get(index);
        }

        @Override
        public  void visit(ObjectChunk chunk) {
            out = chunk.get(index);
        }
    }

    private static class ChunkToSingularType implements Visitor {
        private Class out;

        Class getOut() {
            return Objects.requireNonNull(out);
        }

        @Override
        public void visit(ByteChunk chunk) {
            out = PrimitiveArrayType.bytes().getPrimitiveType();
        }

        @Override
        public void visit(BooleanChunk chunk) {
            out = PrimitiveArrayType.booleans().getPrimitiveType();
        }

        @Override
        public void visit(CharChunk chunk) {
            out = PrimitiveArrayType.chars().getPrimitiveType();
        }

        @Override
        public void visit(ShortChunk chunk) {
            out = PrimitiveArrayType.shorts().getPrimitiveType();
        }

        @Override
        public void visit(IntChunk chunk) {
            out = PrimitiveArrayType.ints().getPrimitiveType();
        }

        @Override
        public void visit(LongChunk chunk) {
            out = PrimitiveArrayType.longs().getPrimitiveType();
        }

        @Override
        public void visit(FloatChunk chunk) {
            out = PrimitiveArrayType.floats().getPrimitiveType();
        }

        @Override
        public void visit(DoubleChunk chunk) {
            out = PrimitiveArrayType.doubles().getPrimitiveType();
        }

        @Override
        public  void visit(ObjectChunk chunk) {
            // this is LESS THAN IDEAL - it would be much better if ObjectChunk would be able to return
            // the item type
            out = Object.class;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy