Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.yandex.ydb.table.query.ParamsImmutableMap Maven / Gradle / Ivy
package com.yandex.ydb.table.query;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.ParametersAreNonnullByDefault;
import com.google.common.collect.Maps;
import com.yandex.ydb.ValueProtos.TypedValue;
import com.yandex.ydb.table.values.Type;
import com.yandex.ydb.table.values.Value;
import static com.google.common.base.Preconditions.checkArgument;
import static com.yandex.ydb.table.values.proto.ProtoValue.toTypedValue;
/**
* Immutable implementation of the {@link Params} interface.
*
* @author Sergey Polovko
*/
@ParametersAreNonnullByDefault
final class ParamsImmutableMap implements Params {
static final ParamsImmutableMap EMPTY = new ParamsImmutableMap(Collections.emptyMap());
private final Map> params;
private ParamsImmutableMap(Map> params) {
this.params = params;
}
static ParamsImmutableMap create(String name, Value> value) {
return new ParamsImmutableMap(Collections.singletonMap(name, value));
}
static ParamsImmutableMap create(String name1, Value> value1, String name2, Value> value2) {
checkArgument(!name1.equals(name2), "parameter duplicate: %s", name1);
HashMap> params = Maps.newHashMapWithExpectedSize(2);
params.put(name1, value1);
params.put(name2, value2);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
static ParamsImmutableMap create(
String name1, Value> value1,
String name2, Value> value2,
String name3, Value> value3) {
HashMap> params = Maps.newHashMapWithExpectedSize(3);
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
static ParamsImmutableMap create(
String name1, Value> value1,
String name2, Value> value2,
String name3, Value> value3,
String name4, Value> value4) {
HashMap> params = Maps.newHashMapWithExpectedSize(4);
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
putParam(params, name4, value4);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
static ParamsImmutableMap create(
String name1, Value> value1,
String name2, Value> value2,
String name3, Value> value3,
String name4, Value> value4,
String name5, Value> value5) {
HashMap> params = Maps.newHashMapWithExpectedSize(5);
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
putParam(params, name4, value4);
putParam(params, name5, value5);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
static ParamsImmutableMap create(
String name1, Value> value1,
String name2, Value> value2,
String name3, Value> value3,
String name4, Value> value4,
String name5, Value> value5,
String name6, Value> value6) {
HashMap> params = Maps.newHashMapWithExpectedSize(6);
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
putParam(params, name4, value4);
putParam(params, name5, value5);
putParam(params, name6, value6);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
static ParamsImmutableMap create(
String name1, Value> value1,
String name2, Value> value2,
String name3, Value> value3,
String name4, Value> value4,
String name5, Value> value5,
String name6, Value> value6,
String name7, Value> value7,
String name8, Value> value8) {
HashMap> params = Maps.newHashMapWithExpectedSize(8);
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
putParam(params, name4, value4);
putParam(params, name5, value5);
putParam(params, name6, value6);
putParam(params, name7, value7);
putParam(params, name8, value8);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
static ParamsImmutableMap create(
String name1, Value> value1,
String name2, Value> value2,
String name3, Value> value3,
String name4, Value> value4,
String name5, Value> value5,
String name6, Value> value6,
String name7, Value> value7,
String name8, Value> value8,
String name9, Value> value9) {
HashMap> params = Maps.newHashMapWithExpectedSize(9);
params.put(name1, value1);
putParam(params, name2, value2);
putParam(params, name3, value3);
putParam(params, name4, value4);
putParam(params, name5, value5);
putParam(params, name6, value6);
putParam(params, name7, value7);
putParam(params, name8, value8);
putParam(params, name9, value9);
return new ParamsImmutableMap(Collections.unmodifiableMap(params));
}
private static void putParam(HashMap> params, String name, Value> value) {
checkArgument(params.putIfAbsent(name, value) == null, "parameter duplicate: %s", name);
}
@Override
public boolean isEmpty() {
return params.isEmpty();
}
@Override
public Params put(String name, Value value) {
throw new UnsupportedOperationException("cannot put parameter into immutable params map");
}
@Override
public Map toPb() {
Map result = new HashMap<>(
(int) ((((float) params.size()) / 0.75f) + 1.0f)
);
for (Map.Entry> entry : params.entrySet()) {
result.put(entry.getKey(), toTypedValue(entry.getValue()));
}
return result;
}
@Override
public Map> values() {
return Collections.unmodifiableMap(params);
}
}