DateCellConverterFactory.java

  1. package com.gh.mygreen.xlsmapper.cellconverter.impl;

  2. import java.util.Date;

  3. import com.gh.mygreen.xlsmapper.Configuration;
  4. import com.gh.mygreen.xlsmapper.cellconverter.CellConverter;
  5. import com.gh.mygreen.xlsmapper.fieldaccessor.FieldAccessor;

  6. /**
  7.  * {@link Date}を処理する{@link CellConverter}を作成するためのファクトリクラス。
  8.  *
  9.  * @since 2.0
  10.  * @author T.TSUCHIE
  11.  *
  12.  */
  13. public class DateCellConverterFactory extends AbstractDateCellConverterFactory<Date> {
  14.    
  15.     @Override
  16.     public DateCellConverter create(final FieldAccessor field, final Configuration config) {
  17.        
  18.         final DateCellConverter cellConverter = new DateCellConverter(this, field, config);
  19.         setupCellConverter(cellConverter, field, config);
  20.        
  21.         return cellConverter;
  22.     }
  23.    
  24.     @Override
  25.     protected Date convertTypeValue(final Date date) {
  26.         return date;
  27.     }
  28.    
  29.     /**
  30.      * {@inheritDoc}
  31.      * <p>{@code yyyy-MM-dd HH:mm:ss}の値を返す。</p>
  32.      */
  33.     @Override
  34.     protected String getDefaultJavaPattern() {
  35.         return "yyyy-MM-dd HH:mm:ss";
  36.     }
  37.    
  38.     /**
  39.      * {@inheritDoc}
  40.      * <p>{@code yyyy-mm-dd hh:mm:ss}の値を返す。</p>
  41.      */
  42.     @Override
  43.     protected String getDefaultExcelPattern() {
  44.         return "yyyy-mm-dd hh:mm:ss";
  45.     }
  46.    
  47.     public class DateCellConverter extends AbstractDateCellConverter<Date> {
  48.        
  49.         private final DateCellConverterFactory convererFactory;
  50.        
  51.         private DateCellConverter(final DateCellConverterFactory convererFactory,
  52.                 final FieldAccessor field, final Configuration config) {
  53.             super(field, config);
  54.             this.convererFactory = convererFactory;
  55.         }
  56.        
  57.         @Override
  58.         protected Date convertTypeValue(final Date value) {
  59.             return convererFactory.convertTypeValue(value);
  60.         }
  61.     }
  62.    
  63. }