@Override
public Map<K, V> parse(String value) {
int idx = ParseUtils.skipSpaces(value, 0);
if (value.charAt(idx++) != '{')
throw new InvalidTypeException(String.format("cannot parse map value from \"%s\", at character %d expecting '{' but got '%c'", value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == '}')
return Collections.<K, V>emptyMap();
Map<K, V> m = new HashMap<K, V>();
while (idx < value.length()) {
int n;
try {
n = ParseUtils.skipCQLValue(value, idx);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse map value from \"%s\", invalid CQL value at character %d", value, idx), e);
}
K k = keyCodec.parse(value.substring(idx, n));
idx = n;
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx++) != ':')
throw new InvalidTypeException(String.format("Cannot parse map value from \"%s\", at character %d expecting ':' but got '%c'", value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
try {
n = ParseUtils.skipCQLValue(value, idx);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse map value from \"%s\", invalid CQL value at character %d", value, idx), e);
}
V v = valueCodec.parse(value.substring(idx, n));
idx = n;
m.put(k, v);
idx = ParseUtils.skipSpaces(value, idx);
if (value.charAt(idx) == '}')
return m;
if (value.charAt(idx++) != ',')
throw new InvalidTypeException(String.format("Cannot parse map value from \"%s\", at character %d expecting ',' but got '%c'", value, idx, value.charAt(idx)));
idx = ParseUtils.skipSpaces(value, idx);
}
throw new InvalidTypeException(String.format("Malformed map value \"%s\", missing closing '}'", value));
}