]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/CsvParserWithLinesAsMap.java
1 package org
.argeo
.util
;
3 import java
.util
.HashMap
;
7 import org
.argeo
.ArgeoException
;
10 * CSV parser allowing to process lines as maps whose keys are the header
13 public abstract class CsvParserWithLinesAsMap
extends CsvParser
{
16 * Actually processes a line.
19 * the current line number, starts at 1 (the header, if header
20 * processing is enabled, the first lien otherwise)
22 * the parsed tokens as a map whose keys are the header fields
24 protected abstract void processLine(Integer lineNumber
,
25 Map
<String
, String
> line
);
27 protected final void processLine(Integer lineNumber
, List
<String
> header
,
28 List
<String
> tokens
) {
30 throw new ArgeoException("Only CSV with header is supported");
31 Map
<String
, String
> line
= new HashMap
<String
, String
>();
32 for (int i
= 0; i
< header
.size(); i
++) {
33 String key
= header
.get(i
);
35 if (i
< tokens
.size())
36 value
= tokens
.get(i
);
39 processLine(lineNumber
, line
);