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

org.simpleflatmapper.datastax.impl.setter.SetWithConverterSettableDataSetter Maven / Gradle / Ivy

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

import com.datastax.driver.core.SettableByIndexData;
import org.simpleflatmapper.reflect.Setter;
import org.simpleflatmapper.converter.Converter;

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

public class SetWithConverterSettableDataSetter implements Setter, Set> {
    private final int index;
    private final Converter converter;

    public SetWithConverterSettableDataSetter(int index, Converter converter) {
        this.index = index;
        this.converter = converter;
    }

    @Override
    public void set(SettableByIndexData target, Set value) throws Exception {
        if (value == null) {
            target.setToNull(index);
        } else {
            Set list = new HashSet(value.size());
            for(I i : value) {
                list.add(converter.convert(i));
            }
            target.setSet(index, list);
        }
    }
}