View Javadoc
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    * 文字列をトリムするCellProcessor。
10   * <p>値がNullの時も処理を続行する</p>
11   * 
12   * @since 1.0.2
13   * @author T.TSUCHIE
14   *
15   */
16  public class Trim extends CellProcessorAdaptor implements StringCellProcessor {
17      
18      /**
19       * Constructs a new <tt>Trim</tt> processor, which trims a String to ensure it has no surrounding whitespace.
20       */
21      public Trim() {
22          super();
23      }
24      
25      /**
26       * Constructs a new <tt>Trim</tt> processor, which trims a String to ensure it has no surrounding whitespace then
27       * calls the next processor in the chain.
28       * 
29       * @param next the next processor in the chain
30       * @throws NullPointerException {@literal if next is null}
31       */
32      public Trim(final StringCellProcessor next) {
33          super(next);
34      }
35      
36      @SuppressWarnings("unchecked")
37      public Object execute(final Object value, final CsvContext context) {
38          
39          if(value == null) {
40              return next.execute(value, context);
41          }
42          
43          final String result = value.toString().trim();
44          return next.execute(result, context);
45      }
46      
47  }