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

org.supercsv.ext.builder.joda.DateTimeZoneCellProcessorBuilder Maven / Gradle / Ivy

Go to download

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

There is a newer version: 2.3
Show newest version
package org.supercsv.ext.builder.joda;

import java.lang.annotation.Annotation;
import java.util.Optional;

import org.joda.time.DateTimeZone;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.cellprocessor.joda.FmtDateTimeZone;
import org.supercsv.cellprocessor.joda.ParseDateTimeZone;
import org.supercsv.ext.builder.AbstractCellProcessorBuilder;
import org.supercsv.ext.exception.SuperCsvInvalidAnnotationException;

/**
 * Joda-Timeの{@link DateTimeZone}型の{@link CellProcessor}のビルダ。
 * @since 1.2
 * @author T.TSUCHIE
 *
 */
public class DateTimeZoneCellProcessorBuilder extends AbstractCellProcessorBuilder {
    
    @Override
    public CellProcessor buildOutputCellProcessor(final Class type, final Annotation[] annos,
            final CellProcessor processor, final boolean ignoreValidationProcessor) {
        
        CellProcessor cp = processor;
        cp = (cp == null ? new FmtDateTimeZone() : new FmtDateTimeZone(cp));
        
        return cp;
    }
    
    @Override
    public CellProcessor buildInputCellProcessor(final Class type, final Annotation[] annos,
            final CellProcessor processor) {
        
        CellProcessor cp = processor;
        cp = (cp == null ? new ParseDateTimeZone() : new ParseDateTimeZone(cp));
        
        return cp;
    }
    
    @Override
    public Optional parseValue(final Class type, final Annotation[] annos, final String strValue) {
        
        try {
            return Optional.of(DateTimeZone.forID(strValue));
            
        } catch(IllegalArgumentException e) {
            throw new SuperCsvInvalidAnnotationException(
                    String.format("default '%s' value cannot parse to DateTimeZone.", strValue), e);
            
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy