org.sfm.datastax.impl.getter.DatastaxMapWithConverterGetter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-datastax Show documentation
Show all versions of sfm-datastax Show documentation
Cassandra Datastax SFM supports.
package org.sfm.datastax.impl.getter;
import com.datastax.driver.core.GettableByIndexData;
import org.sfm.reflect.Getter;
import org.sfm.utils.conv.Converter;
import java.util.HashMap;
import java.util.Map;
public class DatastaxMapWithConverterGetter implements Getter> {
private final int index;
private final Class keyType;
private final Class valueType;
private final Converter keyConverter;
private final Converter valueConverter;
public DatastaxMapWithConverterGetter(int index, Class keyType, Class valueType, Converter keyConverter, Converter valueConverter) {
this.index = index;
this.keyType = keyType;
this.valueType = valueType;
this.keyConverter = keyConverter;
this.valueConverter = valueConverter;
}
@Override
public Map get(GettableByIndexData target) throws Exception {
Map map = target.getMap(index, keyType, valueType);
Map outMap = new HashMap();
for(Map.Entry e : map.entrySet()) {
outMap.put(keyConverter.convert(e.getKey()), valueConverter.convert(e.getValue()));
}
return outMap;
}
}