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