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

org.simpleflatmapper.datastax.impl.getter.DatastaxSetWithConverterGetter Maven / Gradle / Ivy

There is a newer version: 8.2.3
Show newest version
package org.simpleflatmapper.datastax.impl.getter;

import com.datastax.driver.core.GettableByIndexData;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.converter.ContextualConverter;

import java.util.HashSet;
import java.util.Set;

public class DatastaxSetWithConverterGetter implements Getter> {

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

    public DatastaxSetWithConverterGetter(int index, Class type, ContextualConverter 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, null));
        }
        return convertedSet;
    }
}