1 /*
2 * ObjectLab, http://www.objectlab.co.uk/open is supporting FlatPack.
3 *
4 * Based in London, we are world leaders in the design and development
5 * of bespoke applications for the securities financing markets.
6 *
7 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
8 * ___ _ _ _ _ _
9 * / _ \| |__ (_) ___ ___| |_| | __ _| |__
10 * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \
11 * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) |
12 * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
13 * |__/
14 *
15 * www.ObjectLab.co.uk
16 *
17 * $Id: ColorProvider.java 74 2006-10-24 22:19:05Z benoitx $
18 *
19 * Copyright 2006 the original author or authors.
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
22 * use this file except in compliance with the License. You may obtain a copy of
23 * the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
30 * License for the specific language governing permissions and limitations under
31 * the License.
32 */
33 package net.sf.flatpack;
34
35 import java.util.stream.Stream;
36
37 /**
38 * PZParser is ready to parse the data and return an object that can then be
39 * traversed. The default parser should NOT handle short lines, the user can
40 * change it prior to calling parse.
41 *
42 * @author Benoit Xhenseval
43 * @author Paul Zepernick
44 */
45 public interface Parser {
46
47 /**
48 * Start the parsing. Will return "null" if the parse fails and the DataSet
49 * cannot be created
50 *
51 * @return the data set resulting from parsing
52 */
53 DataSet parse();
54
55 /**
56 * Parse the data and return an interface where one can extract one record at a time, until
57 * next returns false;
58 * @since 3.4
59 * @return a stream of Dataset
60 */
61 StreamingDataSet parseAsStream();
62
63 /**
64 * Parse the data and return a stream or records;
65 * @since 4.0
66 * @return a stream of Record
67 */
68 Stream<Record> stream();
69
70 /**
71 * @return true, lines with less columns then the amount of column headers
72 * will be added as empty's instead of producing an error
73 */
74 boolean isHandlingShortLines();
75
76 /**
77 * @param handleShortLines -
78 * when flagged as true, lines with less columns then the amount
79 * of column headers will be added as empty's instead of
80 * producing an error
81 * @return the Parser
82 */
83 Parser setHandlingShortLines(boolean handleShortLines);
84
85 /**
86 * @param addSuffixToDuplicateColumnNames
87 * when true, add a count to duplicate colum names. eg the second column called "Asset" will become "Asset2".
88 * @return the Parser
89 */
90 Parser setAddSuffixToDuplicateColumnNames(boolean addSuffixToDuplicateColumnNames);
91
92 /**
93 *
94 * @return true, detail lines with a length or column count > the mapping
95 * definition will be truncated and the reader will NOT register
96 * these lines as errors in the DataError collection.
97 */
98 boolean isIgnoreExtraColumns();
99
100 /**
101 *
102 * @param ignoreExtraColumns
103 * when true, detail lines with a length or column count > the
104 * mapping definition will be truncated and the reader will NOT
105 * register these lines as errors in the DataError collection.
106 * @return the Parser
107 */
108 Parser setIgnoreExtraColumns(boolean ignoreExtraColumns);
109
110 /**
111 * Defaults to <code>true</code>.
112 * @return true, the parser will preserve leading whitespace in each column when splitting a line
113 */
114 boolean isPreserveLeadingWhitespace();
115
116 /**
117 * Defaults to <code>true</code>.
118 * @param preserveLeadingWhitespace
119 * when true, the parser will preserve leading whitespace in each column when splitting a line
120 * @return the Parser
121 */
122 Parser setPreserveLeadingWhitespace(boolean preserveLeadingWhitespace);
123
124 /**
125 * Defaults to <code>false</code>.
126 * @return true, the parser will preserve trailing whitespace in each column when splitting a line
127 */
128 boolean isPreserveTrailingWhitespace();
129
130 /**
131 * Defaults to <code>false</code>.
132 * @param preserveTrailingWhitespace
133 * when true, the parser will preserve trailing whitespace in each column when splitting a line
134 * @return the Parser
135 */
136 Parser setPreserveTrailingWhitespace(boolean preserveTrailingWhitespace);
137
138 /**
139 * Default is false
140 *
141 * @return true, column names will have to be an exact match when retrieving
142 * the value of a column. Example when true: Column name =
143 * AColumnName ; getString("acolumnname") would fail Example when
144 * false: Column name = AColumnName ; getString("acolumnname") would
145 * pass
146 */
147 boolean isColumnNamesCaseSensitive();
148
149 /**
150 * Default is false
151 *
152 * @param columnNamesCaseSensitive
153 * when true, column names will have to be an exact match when
154 * retrieving the value of a column. Example when true: Column
155 * name = AColumnName ; getString("acolumnname") would fail
156 * Example when false: Column name = AColumnName ;
157 * getString("acolumnname") would pass
158 * @return the Parser
159 */
160 Parser setColumnNamesCaseSensitive(boolean columnNamesCaseSensitive);
161
162 /**
163 * Default is false
164 *
165 * @return true, warnings encountered during parsing will not be included in
166 * the DataSet errors
167 */
168 boolean isIgnoreParseWarnings();
169
170 /**
171 *
172 * @param ignoreParseWarnings
173 * when true, warnings encountered during parsing will not be
174 * included in the DataSet errors
175 * @return the Parser
176 */
177 Parser setIgnoreParseWarnings(boolean ignoreParseWarnings);
178
179 /**
180 *
181 * @return true, empty Strings will get returned as NULL when calling
182 * DataSet.getString()
183 */
184 boolean isNullEmptyStrings();
185
186 /**
187 *
188 * @param nullEmptyStrings
189 * when true, empty Strings will get returned as NULL when
190 * calling DataSet.getString()
191 * @return the Parser
192 */
193 Parser setNullEmptyStrings(boolean nullEmptyStrings);
194
195 /**
196 *
197 * @return flagEmptyRows when true, will analyze the row to see if all
198 * elements are empty and place a flag on the DataSet indicating if
199 * the row is empty
200 */
201 boolean isFlagEmptyRows();
202
203 /**
204 * when true, will analyze the row to see if all elements are empty and
205 * place a flag on the DataSet indicating if the row is empty. This will slow
206 * down the parse and should only be used when necessary. It is off by default.
207 *
208 * @param flagEmptyRows true if we need to flag empty rows
209 * @return the Parser
210 */
211 Parser setFlagEmptyRows(boolean flagEmptyRows);
212
213 /**
214 * @return when true, the parser will place the data of the line which failed the parse and
215 * place it into the DataError object. DataError.getRawData() can be called to retrieve
216 * the line.
217 */
218 boolean isStoreRawDataToDataError();
219
220 /**
221 * when true, the parser will place the data of the line which failed the parse and
222 * place it into the DataError object. DataError.getRawData() can be called to retrieve
223 * the line.
224 *
225 * @param storeRawDataToDataError true if we need to store each lines
226 * @return the Parser
227 */
228 Parser setStoreRawDataToDataError(boolean storeRawDataToDataError);
229
230 /**
231 * @return when true, the parser will place the data of the line into the DataSet object.
232 * DataSet.getRawData() can be called to retrieve the line.
233 */
234 boolean isStoreRawDataToDataSet();
235
236 /**
237 * WARNING!! Setting this option has potential to cause high memory usage.
238 *
239 * when true, the parser will place the data of the line into the DataSet object.
240 * DataSet.getRawData() can be called to retrieve the line.
241 *
242 * @param storeRawDataToDataError true if we need to store the raw data
243 * @return the Parser
244 */
245 Parser setStoreRawDataToDataSet(boolean storeRawDataToDataError);
246
247 /**
248 * Returns the table name that will be used to read the MetaData from the db. The
249 * default table name is DATAFILE. This may be problimatic for some who are using case
250 * sensistive db table names or who wish to provide a different table name in the db.
251 *
252 * This is only applicable when using a database for file mappings.
253 *
254 * @return the DATAFILE table name
255 */
256 String getDataFileTable();
257
258 /**
259 * Sets the table name that will be used to read the MetaData from the db. The
260 * default table name is DATAFILE. This may be problimatic for some who are using case
261 * sensistive db table names or who wish to provide a different table name in the db.
262 *
263 * This is only applicable when using a database for file mappings.
264 *
265 * @param dataFileTable
266 * Name of the table name to use in place of "DATAFILE"
267 * @return the Parser
268 */
269 Parser setDataFileTable(String dataFileTable);
270
271 /**
272 * Returns the table name that will be used to read the MetaData from the db. The
273 * default table name is DATASTRUCTURE. This may be problimatic for some who are using case
274 * sensistive db table names or who wish to provide a different table name in the db.
275 *
276 * This is only applicable when using a database for file mappings.
277 *
278 * @return the DATASTRUCTURE table name
279 */
280 String getDataStructureTable();
281
282 /**
283 * Sets the table name that will be used to read the MetaData from the db. The
284 * default table name is DATASTRUCTURE. This may be problimatic for some who are using case
285 * sensistive db table names or who wish to provide a different table name in the db.
286 *
287 * This is only applicable when using a database for file mappings.
288 *
289 * @param dataStructureTable
290 * Name of the table name to us in placfe of "DATASTRUCTURE"
291 *
292 * @return the Parser
293 */
294 Parser setDataStructureTable(String dataStructureTable);
295 }