1 package com.github.mygreen.supercsv.cellprocessor.conversion;
2
3 import org.supercsv.cellprocessor.CellProcessorAdaptor;
4 import org.supercsv.cellprocessor.ift.StringCellProcessor;
5 import org.supercsv.util.CsvContext;
6
7
8
9
10
11
12
13
14 public class FullChar extends CellProcessorAdaptor implements StringCellProcessor {
15
16 private final CharCategory[] categories;
17
18 private final JapaneseCharReplacer replacer;
19
20 public FullChar(final CharCategory[] categories) {
21 super();
22 checkPreconditions(categories);
23 this.categories = categories;
24 this.replacer = new JapaneseCharReplacer(categories);
25 }
26
27 public FullChar(final CharCategory[] categories, final StringCellProcessor next) {
28 super(next);
29 checkPreconditions(categories);
30 this.categories = categories;
31 this.replacer = new JapaneseCharReplacer(categories);
32 }
33
34 private static void checkPreconditions(final CharCategory[] categories) {
35 if(categories == null) {
36 throw new NullPointerException("categories should not be null.");
37
38 } else if(categories.length == 0) {
39 throw new IllegalArgumentException("categories should not be empty.");
40 }
41 }
42
43 @Override
44 public <T> T execute(final Object value, final CsvContext context) {
45
46 if(value == null) {
47 return next.execute(value, context);
48 }
49
50 final String result = replacer.replaceToFullChar(value.toString());
51 return next.execute(result, context);
52 }
53
54
55
56
57
58 public CharCategory[] getCategories() {
59 return categories;
60 }
61
62 }