View Javadoc
1   package net.sf.flatpack;
2   
3   import java.math.BigDecimal;
4   import java.text.ParseException;
5   import java.text.SimpleDateFormat;
6   import java.time.LocalDate;
7   import java.time.format.DateTimeFormatter;
8   import java.util.Date;
9   import java.util.NoSuchElementException;
10  import java.util.function.DoubleSupplier;
11  import java.util.function.IntSupplier;
12  import java.util.function.LongSupplier;
13  import java.util.function.Supplier;
14  
15  /**
16   * @since 3.4
17   */
18  public interface Record {
19      /**
20       * Returns the string value of a specified column
21       *
22       * @param column
23       *            - Name of the column
24       * @return String
25       */
26      String getString(String column);
27  
28      /**
29       * Returns the string value of a specified column
30       *
31       * @param column
32       *            - Name of the column
33       * @param defaultSupplier for default value if result in column is null/empty
34       * @exception NoSuchElementException if col does not exist
35       * @return String
36       * @since 4.0
37       */
38      String getString(String column, Supplier<String> defaultSupplier);
39  
40      /**
41       * Returns the double value of a specified column
42       *
43       * @param column
44       *            - Name of the column
45       * @param defaultSupplier for default value if result in column is null/empty
46       * @exception NoSuchElementException if no such record
47       * @exception NumberFormatException if wrong number format
48       * @return double
49       * @since 4.0
50       */
51      double getDouble(String column, DoubleSupplier defaultSupplier);
52  
53      /**
54       * Returns the double value of a specified column
55       *
56       * @param column
57       *            - Name of the column
58       * @exception NoSuchElementException if no such record
59       * @exception NumberFormatException if wrong number format
60       * @return double
61       */
62      double getDouble(String column);
63  
64      /**
65       * Returns the BigDecimal value of a specified column
66       *
67       * @param column
68       *            - Name of the column
69       * @param defaultSupplier for default value if result in column is null/empty
70       * @exception NoSuchElementException if no such record
71       * @exception NumberFormatException if wrong number format
72       * @return BigDecimal
73       * @since 4.0
74       */
75      BigDecimal getBigDecimal(String column, Supplier<BigDecimal> defaultSupplier);
76  
77      /**
78       * Returns the BigDecimal value of a specified column
79       *
80       * @param column
81       *            - Name of the column
82       * @exception NoSuchElementException if no such record
83       * @exception NumberFormatException if wrong number format
84       * @return BigDecimal
85       */
86      BigDecimal getBigDecimal(String column);
87  
88      /**
89       * Returns the integer value of a specified column
90       *
91       * @param column
92       *            - Name of the column
93       * @param defaultSupplier for default value if result in column is null/empty
94       * @exception NoSuchElementException if no such record
95       * @exception NumberFormatException if wrong number format
96       * @return double
97       * @since 4.0
98       */
99      int getInt(String column, IntSupplier defaultSupplier);
100 
101     /**
102      * Returns the integer value of a specified column
103      *
104      * @param column
105      *            - Name of the column
106      * @exception NoSuchElementException if no such record
107      * @exception NumberFormatException if wrong number format
108      * @return double
109      */
110     int getInt(String column);
111 
112     /**
113      * Returns the long value of a specified column
114      *
115      * @param column
116      *            - Name of the column
117      * @param defaultSupplier for default value if result in column is null/empty
118      * @exception NoSuchElementException if no such record
119      * @exception NumberFormatException if wrong number format
120      * @return long
121      * @since 4.0
122      */
123     long getLong(String column, LongSupplier defaultSupplier);
124 
125     /**
126      * Returns the long value of a specified column
127      *
128      * @param column
129      *            - Name of the column
130      * @exception NoSuchElementException if no such record
131      * @exception NumberFormatException if wrong number format
132      * @return long
133      */
134     long getLong(String column);
135 
136     /**
137      * Returns the date value of a specified column. This assumes the date is in
138      * yyyyMMdd. If your date is not in this format, see
139      * getDate(String,SimpleDateFormat)
140      *
141      * Will return "null" on empty Strings
142      *
143      * @param column
144      *            - Name of the column
145      * @param defaultSupplier for default value if result in column is null/empty
146      * @exception ParseException if date format incorect
147      * @return Date
148      * @since 4.0
149      */
150     Date getDate(String column, Supplier<Date> defaultSupplier) throws ParseException;
151 
152     /**
153      * Returns the date value of a specified column. This assumes the date is in
154      * yyyyMMdd. If your date is not in this format, see
155      * getDate(String,SimpleDateFormat)
156      *
157      * Will return "null" on empty Strings
158      *
159      * @param column
160      *            - Name of the column
161      * @exception ParseException if date format incorrect
162      * @return Date
163      */
164     Date getDate(String column) throws ParseException;
165 
166     /**
167      * Returns the date value of a specified column. This should be used if the
168      * date is NOT in yyyyMMdd format. The SimpleDateFormat object will specify
169      * what kind of format the date is in.
170      *
171      * Will return "null" on empty Strings
172      *
173      * @param column
174      *            - Name of the column
175      * @param sdf
176      *            - SimpleDateFormat of the date
177      * @param defaultSupplier for default value if result in column is null/empty
178      * @exception ParseException
179      * @see java.text.SimpleDateFormat
180      * @return Date
181      * @since 4.0
182      */
183     Date getDate(String column, SimpleDateFormat sdf, Supplier<Date> defaultSupplier) throws ParseException;
184 
185     /**
186      * Returns the date value of a specified column. This should be used if the
187      * date is NOT in yyyyMMdd format. The SimpleDateFormat object will specify
188      * what kind of format the date is in.
189      *
190      * Will return "null" on empty Strings
191      *
192      * @param column
193      *            - Name of the column
194      * @param sdf
195      *            - SimpleDateFormat of the date
196      * @exception ParseException if date format does not match the SimpleDateFormat
197      * @see java.text.SimpleDateFormat
198      * @return Date
199      */
200     Date getDate(String column, SimpleDateFormat sdf) throws ParseException;
201 
202     /**
203      * Returns the date value of a specified column. This assumes the date is in
204      * yyy-mm-dd. If your date is not in this format, see
205      * getDate(String,SimpleDateFormat)
206      *
207      * Will return "null" on empty Strings
208      *
209      * @param column
210      *            - Name of the column
211      * @param defaultSupplier for default value if result in column is null/empty
212      * @exception ParseException if date format does not match
213      * @return Date
214      * @since 4.0
215      */
216     LocalDate getLocalDate(String column, Supplier<LocalDate> defaultSupplier) throws ParseException;
217 
218     /**
219      * Returns the local date value of a specified column. This assumes the date is in
220      * yyyy-MM-dd. If your date is not in this format, see
221      * getLocalDate(String,SimpleDateFormat)
222      *
223      * Will return "null" on empty Strings
224      *
225      * @param column
226      *            - Name of the column
227      * @exception ParseException if date format does not match
228      * @return Date
229      */
230     LocalDate getLocalDate(String column) throws ParseException;
231 
232     /**
233      * Returns the local date value of a specified column. This assumes the date is in
234      * yyyy-MM-dd. If your date is not in this format, see
235      * getLocalDate(String,SimpleDateFormat)
236      *
237      * Will return "null" on empty Strings
238      *
239      * @param column
240      *            - Name of the column
241      *        formatter
242      *            - formatter for the date parsing
243      * @exception ParseException if date format does not match
244      * @return Date
245      */
246     LocalDate getLocalDate(String column, DateTimeFormatter formatter) throws ParseException;
247 
248     /**
249      * Returns the local date value of a specified column. This should be used if the
250      * date is NOT in yyyyMMdd format. The SimpleDateFormat object will specify
251      * what kind of format the date is in.
252      *
253      * Will return "null" on empty Strings
254      *
255      * @param column
256      *            - Name of the column
257      * @param dateFormat
258      *            - dateFormat of the date
259      * @param defaultSupplier for default value if result in column is null/empty
260      * @exception ParseException if date format does not match
261      * @see java.text.SimpleDateFormat
262      * @return Date
263      * @since 4.0
264      */
265     LocalDate getLocalDate(String column, String dateFormat, Supplier<LocalDate> defaultSupplier) throws ParseException;
266 
267     /**
268      * Returns the lcoal date value of a specified column. This should be used if the
269      * date is NOT in yyy-mm-dd format. The SimpleDateFormat object will specify
270      * what kind of format the date is in.
271      *
272      * Will return "null" on empty Strings
273      *
274      * @param column
275      *            - Name of the column
276      * @param dateFormat
277      *            - dateFormat of the date
278      * @exception ParseException if date format does not match
279      * @see java.text.SimpleDateFormat
280      * @return Date
281      */
282     LocalDate getLocalDate(String column, String dateFormat) throws ParseException;
283 
284     /**
285      * Returns the value of the column with the type of object specified
286      *
287      * @param column
288      *            Name of the column
289      * @param classToConvertTo
290      *            Class type to convert to
291      * @return Object Value of the column in the specified object
292      */
293     Object getObject(String column, Class<?> classToConvertTo);
294 
295     /**
296      * Returns a String array of column names in the DataSet. This will assume
297      * 'detail' &lt;RECORD&gt; ID.
298      *
299      * @return String[]
300      */
301     String[] getColumns();
302 
303     /**
304      * Returns a String array of column names in the DataSet for a given
305      *  &lt;RECORD&gt; id
306      *
307      * @param recordID
308      * @return String[]
309      */
310     String[] getColumns(String recordID);
311 
312     /**
313      * Returns the line number the pointer is on. These are the actual line
314      * numbers from the flat file, before any sorting.
315      *
316      * @exception NoSuchElementException
317      * @exception NumberFormatException
318      * @return int
319      */
320     int getRowNo();
321 
322     /**
323      * Checks to see if the row has the given  &lt;RECORD&gt; id
324      *
325      * @param recordID
326      * @return boolean
327      */
328     boolean isRecordID(String recordID);
329 
330     /**
331      * Show the record ID (default is 'detail')
332      * @return the record ID (default is 'detail')
333      */
334     String getRecordID();
335 
336     /**
337      * Does this DataSet contain a column with the given name?
338      *
339      * @param column
340      *          Column name to check for
341      * @return boolean true if the row contain that column name.
342      */
343     boolean contains(String column);
344 
345     /**
346      * Checks to see if there was no data on the row which was parsed.  This
347      * will thrown an exception if Parser.FlagEmptyRows() is not set to true.
348      *
349      * @return true if the row has no data
350      */
351     boolean isRowEmpty();
352 
353     /**
354      *
355      * @return the raw data used to create this Row in the DataSet.  Parser.setStoreRawDataToDataSet(true)
356      * must be specified before calling this method.
357      */
358     String getRawData();
359 }