package me.chyxion.tigon.webmvc.formatter;

import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.Formatter;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Jun 15, 2016 11:29:55 AM
 */
public class EmptyToNullFormatter implements Formatter<String> {

    /**
     * {@inheritDoc}
     */
    @Override
    public String print(String text, Locale locale) {
        return text;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String parse(String text, Locale locale) {
        return StringUtils.isNotEmpty(text) ? text : null;
    }
}
