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

org.sfm.datastax.impl.getter.DatastaxSetWithConverterGetter 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.HashSet;
import java.util.Set;

public class DatastaxSetWithConverterGetter implements Getter> {

    private final int index;
    private final Class type;
    private final Converter converter;

    public DatastaxSetWithConverterGetter(int index, Class type, Converter converter) {
        this.index = index;
        this.type = type;
        this.converter = converter;
    }

    @Override
    public Set get(GettableByIndexData target) throws Exception {
        Set set = target.getSet(index, type);

        if (set == null) return null;

        Set convertedSet = new HashSet();
        for(I i : set) {
            convertedSet.add(converter.convert(i));
        }
        return convertedSet;
    }
}