}
public <K, V> T setMap(int i, Map<K, V> v) {
DataType type = getType(i);
if (type.getName() != DataType.Name.MAP)
throw new InvalidTypeException(String.format("Column %s is of type %s, cannot set to a map", getName(i), type));
if (v == null)
return setValue(i, null);
if (!v.isEmpty()) {
// Ugly? Yes
Map.Entry<K, V> entry = v.entrySet().iterator().next();
Class<?> providedKeysClass = entry.getKey().getClass();
Class<?> providedValuesClass = entry.getValue().getClass();
Class<?> expectedKeysClass = type.getTypeArguments().get(0).getName().javaType;
Class<?> expectedValuesClass = type.getTypeArguments().get(1).getName().javaType;
if (!expectedKeysClass.isAssignableFrom(providedKeysClass) || !expectedValuesClass.isAssignableFrom(providedValuesClass))
throw new InvalidTypeException(String.format("Invalid value for column %s of CQL type %s, expecting map of %s->%s but provided map of %s->%s", getName(i), type, expectedKeysClass, expectedValuesClass, providedKeysClass, providedValuesClass));
}
return setValue(i, type.codec(protocolVersion).serialize(v));
}