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
12
13
14
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 }