View Javadoc
1   package org.csveed.row;
2   
3   import org.csveed.token.EncounteredSymbol;
4   import org.csveed.token.SymbolMapping;
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   
8   public class RowInstructionsImpl implements RowInstructions {
9   
10      private static final Logger LOG = LoggerFactory.getLogger(RowInstructionsImpl.class);
11  
12      private SymbolMappingping">SymbolMapping symbolMapping = new SymbolMapping();
13  
14      private boolean useHeader = true;
15  
16      private boolean skipEmptyLines = true;
17  
18      private boolean settingsLogged;
19  
20      private boolean quoteFields = true;
21  
22      public void logSettings() {
23          if (settingsLogged) {
24              return;
25          }
26          LOG.info("- CSV config / skip empty lines? {}", isSkipEmptyLines() ? "yes" : "no");
27          LOG.info("- CSV config / has header line? {}", isUseHeader() ? "yes" : "no");
28          settingsLogged = true;
29      }
30  
31      public SymbolMapping getSymbolMapping() {
32          return symbolMapping;
33      }
34  
35      public boolean isSkipEmptyLines() {
36          return skipEmptyLines;
37      }
38  
39      @Override
40      public boolean isUseHeader() {
41          return useHeader;
42      }
43  
44      @Override
45      public RowInstructions setUseHeader(boolean useHeader) {
46          this.useHeader = useHeader;
47          return this;
48      }
49  
50      @Override
51      public RowInstructions setStartRow(int startRow) {
52          this.symbolMapping.setStartLine(startRow);
53          return this;
54      }
55  
56      @Override
57      public char getEscape() {
58          return this.symbolMapping.getFirstMappedCharacter(EncounteredSymbol.ESCAPE_SYMBOL);
59      }
60  
61      @Override
62      public RowInstructions setEscape(char symbol) {
63          this.symbolMapping.addMapping(EncounteredSymbol.ESCAPE_SYMBOL, symbol);
64          return this;
65      }
66  
67      @Override
68      public char getQuote() {
69          return symbolMapping.getFirstMappedCharacter(EncounteredSymbol.QUOTE_SYMBOL);
70      }
71  
72      @Override
73      public RowInstructions setQuotingEnabled(boolean quoteFields) {
74          this.quoteFields = quoteFields;
75          return this;
76      }
77  
78      @Override
79      public boolean getQuotingEnabled() {
80          return quoteFields;
81      }
82  
83      @Override
84      public RowInstructions setQuote(char symbol) {
85          this.symbolMapping.addMapping(EncounteredSymbol.QUOTE_SYMBOL, symbol);
86          return this;
87      }
88  
89      @Override
90      public char getSeparator() {
91          return symbolMapping.getFirstMappedCharacter(EncounteredSymbol.SEPARATOR_SYMBOL);
92      }
93  
94      @Override
95      public RowInstructions setSeparator(char symbol) {
96          this.symbolMapping.addMapping(EncounteredSymbol.SEPARATOR_SYMBOL, symbol);
97          return this;
98      }
99  
100     @Override
101     public RowInstructions setComment(char symbol) {
102         this.symbolMapping.addMapping(EncounteredSymbol.COMMENT_SYMBOL, symbol);
103         return this;
104     }
105 
106     @Override
107     public char[] getEndOfLine() {
108         return this.symbolMapping.getMappedCharacters(EncounteredSymbol.EOL_SYMBOL);
109     }
110 
111     @Override
112     public RowInstructions setEndOfLine(char[] symbols) {
113         this.symbolMapping.addMapping(EncounteredSymbol.EOL_SYMBOL, symbols);
114         return this;
115     }
116 
117     @Override
118     public RowInstructions skipEmptyLines(boolean skip) {
119         this.skipEmptyLines = skip;
120         return this;
121     }
122 
123     @Override
124     public RowInstructions skipCommentLines(boolean skip) {
125         this.symbolMapping.setSkipCommentLines(skip);
126         return this;
127     }
128 
129 }