]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.util/src/org/argeo/util/CsvParserWithLinesAsMap.java
1 package org
.argeo
.util
;
3 import java
.util
.HashMap
;
8 * CSV parser allowing to process lines as maps whose keys are the header
11 public abstract class CsvParserWithLinesAsMap
extends CsvParser
{
14 * Actually processes a line.
17 * the current line number, starts at 1 (the header, if header
18 * processing is enabled, the first lien otherwise)
20 * the parsed tokens as a map whose keys are the header fields
22 protected abstract void processLine(Integer lineNumber
,
23 Map
<String
, String
> line
);
25 protected final void processLine(Integer lineNumber
, List
<String
> header
,
26 List
<String
> tokens
) {
28 throw new UtilsException("Only CSV with header is supported");
29 Map
<String
, String
> line
= new HashMap
<String
, String
>();
30 for (int i
= 0; i
< header
.size(); i
++) {
31 String key
= header
.get(i
);
33 if (i
< tokens
.size())
34 value
= tokens
.get(i
);
37 processLine(lineNumber
, line
);