]>
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.
16 * @param lineNumber the current line number, starts at 1 (the header, if header
17 * processing is enabled, the first lien otherwise)
18 * @param line the parsed tokens as a map whose keys are the header fields
20 protected abstract void processLine(Integer lineNumber
, Map
<String
, String
> line
);
22 protected final void processLine(Integer lineNumber
, List
<String
> header
, List
<String
> tokens
) {
24 throw new IllegalArgumentException("Only CSV with header is supported");
25 Map
<String
, String
> line
= new HashMap
<String
, String
>();
26 for (int i
= 0; i
< header
.size(); i
++) {
27 String key
= header
.get(i
);
29 if (i
< tokens
.size())
30 value
= tokens
.get(i
);
33 processLine(lineNumber
, line
);