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