com.github.mygreen.supercsv.builder.standard.EnumProcessorBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of super-csv-annotation Show documentation
Show all versions of super-csv-annotation Show documentation
CSVのJavaライブラリであるSuperCSVに、アノテーション機能を追加したライブラリです。
package com.github.mygreen.supercsv.builder.standard;
import java.util.Optional;
import com.github.mygreen.supercsv.annotation.format.CsvEnumFormat;
import com.github.mygreen.supercsv.builder.AbstractProcessorBuilder;
import com.github.mygreen.supercsv.builder.Configuration;
import com.github.mygreen.supercsv.builder.FieldAccessor;
import com.github.mygreen.supercsv.cellprocessor.format.EnumFormatter;
/**
* 列挙型に対するビルダ
*
* @version 2.0
* @author T.TSUCHIE
*
*/
public class EnumProcessorBuilder> extends AbstractProcessorBuilder {
public EnumProcessorBuilder() {
super();
}
@Override
protected void init() {
super.init();
// 制約のアノテーションの追加
}
@SuppressWarnings("unchecked")
@Override
protected EnumFormatter getDefaultFormatter(final FieldAccessor field, final Configuration config) {
final Optional formatAnno = field.getAnnotation(CsvEnumFormat.class);
final Optional selector = formatAnno.map(a -> a.selector().isEmpty() ? null : a.selector());
final boolean ignoreCase = formatAnno.map(a -> a.ignoreCase()).orElse(false);
final EnumFormatter formatter;
if(selector.isPresent()) {
formatter = new EnumFormatter((Class)field.getType(), ignoreCase, selector.get());
} else {
formatter = new EnumFormatter((Class)field.getType(), ignoreCase);
}
formatAnno.ifPresent(a -> formatter.setValidationMessage(a.message()));
return formatter;
}
}