package com.datastax.oss.protocol.internal.util;
import java.util.HashMap;
import java.util.Map;
public class IntIntMap<V> {
public static <V> Builder<V> builder() {
return new Builder<>();
}
private final IntMap<IntMap<V>> outer;
private IntIntMap(IntMap<IntMap<V>> outer) {
this.outer = outer;
}
public V get(int key1, int key2) {
IntMap<V> inner = outer.get(key1);
return (inner == null) ? null : inner.get(key2);
}
public static class Builder<V> {
private Map<Integer, IntMap.Builder<V>> innerBuilders = new HashMap<>();
public Builder<V> put(int key1, int key2, V value) {
innerBuilders.computeIfAbsent(key1, k -> IntMap.builder()).put(key2, value);
return this;
}
public IntIntMap<V> build() {
IntMap.Builder<IntMap<V>> outerBuilder = IntMap.builder();
for (Map.Entry<Integer, IntMap.Builder<V>> entry : innerBuilders.entrySet()) {
outerBuilder.put(entry.getKey(), entry.getValue().build());
}
return new IntIntMap<>(outerBuilder.build());
}
}
}