com.github.mygreen.supercsv.builder.standard.CharacterProcessorBuilder 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 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.TextFormatter;
import com.github.mygreen.supercsv.cellprocessor.format.TextParseException;
/**
* char/Character型に対するビルダ
*
* @version 2.0
* @author T.TSUCHIE
*
*/
public class CharacterProcessorBuilder extends AbstractProcessorBuilder {
@Override
protected TextFormatter getDefaultFormatter(final FieldAccessor field, final Configuration config) {
return new TextFormatter() {
@Override
public Character parse(final String text) {
if(text.length() >= 1) {
return text.charAt(0);
} else {
throw new TextParseException(text, field.getDeclaredClass(),
"Cannot be parsed as a char as it is a String longer than 1 character");
}
}
@Override
public String print(final Character object) {
return object.toString();
}
@Override
public void setValidationMessage(String validationMessage) {
// not support
}
};
}
}