All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.datastax.impl.getter.DatastaxMapWithConverterGetter Maven / Gradle / Ivy

There is a newer version: 8.2.3
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy