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

tech.ydb.table.query.ParamsMutableMap Maven / Gradle / Ivy

package tech.ydb.table.query;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.ParametersAreNonnullByDefault;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

import tech.ydb.proto.ValueProtos;
import tech.ydb.table.values.Type;
import tech.ydb.table.values.Value;
import tech.ydb.table.values.proto.ProtoValue;


/**
 * Mutable implementation of {@link Params} interface.
 *
 * @author Sergey Polovko
 */
@ParametersAreNonnullByDefault
final class ParamsMutableMap implements Params {

    private final HashMap> params;

    ParamsMutableMap() {
        this.params = new HashMap<>();
    }

    ParamsMutableMap(int expectedSize) {
        this.params = Maps.newHashMapWithExpectedSize(expectedSize);
    }

    ParamsMutableMap(Map> params) {
        this.params = new HashMap<>(params);
    }

    @Override
    public boolean isEmpty() {
        return params.isEmpty();
    }

    @Override
    public  Params put(String name, Value value) {
        Value prev = params.putIfAbsent(name, value);
        Preconditions.checkArgument(prev == null, "duplicate parameter: %s", name);
        return this;
    }

    @Override
    public Map toPb() {
        Map result = Maps.newHashMapWithExpectedSize(params.size());
        for (Map.Entry> entry : params.entrySet()) {
            Value value = entry.getValue();
            String name = entry.getKey();

            ValueProtos.TypedValue valuePb = ProtoValue.toTypedValue(value);
            result.put(name, valuePb);
        }
        return Collections.unmodifiableMap(result);
    }

    @Override
    public Map> values() {
        return Collections.unmodifiableMap(params);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy