package me.chyxion.tigon.webmvc.formatter;

import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import org.springframework.format.Parser;
import org.springframework.format.Printer;
import me.chyxion.tigon.format.annotation.EmptyToNull;
import org.springframework.format.AnnotationFormatterFactory;
import org.springframework.context.support.EmbeddedValueResolutionSupport;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Jun 15, 2016 11:23:03 AM
 */
public class EmptyToNullAnnotationFormatterFactory
    extends EmbeddedValueResolutionSupport
    implements AnnotationFormatterFactory<EmptyToNull> {

    private static final Set<Class<?>> FIELD_TYPES;

    static {
        Set<Class<?>> fieldTypes = new HashSet<Class<?>>(1);
        fieldTypes.add(String.class);
        FIELD_TYPES = Collections.unmodifiableSet(fieldTypes);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Set<Class<?>> getFieldTypes() {
        return FIELD_TYPES;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Printer<?> getPrinter(EmptyToNull annotation,
            Class<?> fieldType) {
        return new EmptyToNullFormatter();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Parser<?> getParser(EmptyToNull annotation,
            Class<?> fieldType) {
        return new EmptyToNullFormatter();
    }
}
