View Javadoc
1   package com.gh.mygreen.xlsmapper.cellconverter.impl;
2   
3   import java.math.BigDecimal;
4   import java.math.RoundingMode;
5   
6   import com.gh.mygreen.xlsmapper.Configuration;
7   import com.gh.mygreen.xlsmapper.cellconverter.CellConverter;
8   import com.gh.mygreen.xlsmapper.fieldaccessor.FieldAccessor;
9   
10  /**
11   * {@link Short}型を処理する{@link CellConverter}を作成するクラス。
12   *
13   * @since 2.0
14   * @author T.TSUCHIE
15   *
16   */
17  public class ShortCellConverterFactory extends AbstractNumberCellConverterFactory<Short> {
18      
19      @Override
20      public ShortCellConverter create(final FieldAccessor field, final Configuration config) {
21          
22          final ShortCellConverter cellConverter = new ShortCellConverter(field, config, this);
23          setupCellConverter(cellConverter, field, config);
24          
25          return cellConverter;
26          
27      }
28      
29      @Override
30      protected Short convertTypeValue(final BigDecimal value) throws NumberFormatException, ArithmeticException {
31          // 少数以下を四捨五入
32          BigDecimal decimal = value.setScale(0, RoundingMode.HALF_UP);
33          return decimal.shortValueExact();
34      }
35      
36      public class ShortCellConverter extends AbstractNumberCellConverter<Short> {
37              
38              private final ShortCellConverterFactory convererFactory;
39              
40              private ShortCellConverter(final FieldAccessor field, final Configuration config,
41                      final ShortCellConverterFactory convererFactory) {
42                  super(field, config);
43                  this.convererFactory = convererFactory;
44              }
45              
46              @Override
47              protected Short convertTypeValue(final BigDecimal value) {
48                  return convererFactory.convertTypeValue(value);
49              }
50              
51          }
52      
53  }