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.Trim;
import org.springframework.format.AnnotationFormatterFactory;
import org.springframework.context.support.EmbeddedValueResolutionSupport;

/**
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Jun 18, 2017 23:35:10
 */
public class TrimAnnotationFormatterFactory
    extends EmbeddedValueResolutionSupport
    implements AnnotationFormatterFactory<Trim> {

    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(Trim annotation,
            Class<?> fieldType) {
        return new TrimFormatter();
    }

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