All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mygreen.supercsv.builder.standard.CharacterProcessorBuilder Maven / Gradle / Ivy

Go to download

CSVのJavaライブラリであるSuperCSVに、アノテーション機能を追加したライブラリです。

There is a newer version: 2.3
Show newest version
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
                
            }
            
        };
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy