Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/util/MetaAndTableJRDataSource.java @ 8854:7bbfb24e6eec
SINFO - first prototype of BArt Fließtiefen
author | gernotbelger |
---|---|
date | Thu, 18 Jan 2018 18:34:41 +0100 |
parents | |
children | 5d5d482da3e9 |
comparison
equal
deleted
inserted
replaced
8853:8c64617a7991 | 8854:7bbfb24e6eec |
---|---|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.sinfo.util; | |
11 | |
12 import java.util.ArrayList; | |
13 import java.util.HashMap; | |
14 import java.util.List; | |
15 import java.util.Map; | |
16 | |
17 import net.sf.jasperreports.engine.JRDataSource; | |
18 import net.sf.jasperreports.engine.JRException; | |
19 import net.sf.jasperreports.engine.JRField; | |
20 | |
21 /** | |
22 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
23 */ | |
24 public final class MetaAndTableJRDataSource implements JRDataSource | |
25 { | |
26 private List<String[]> data = new ArrayList<>(); | |
27 | |
28 private Map<String, String> metaData = new HashMap<>(); | |
29 | |
30 private int index = -1; | |
31 | |
32 public void addData(final String[] data) { | |
33 this.data.add(data); | |
34 } | |
35 | |
36 public void addMetaData(final String key, final String value) { | |
37 this.metaData.put(key, value); | |
38 } | |
39 | |
40 @Override | |
41 public boolean next() throws JRException | |
42 { | |
43 index++; | |
44 | |
45 return index < data.size(); | |
46 } | |
47 | |
48 @Override | |
49 public Object getFieldValue(final JRField field) throws JRException | |
50 { | |
51 final String fieldName = field.getName(); | |
52 | |
53 if( fieldName.startsWith("meta:")) | |
54 return metaData.get(fieldName.substring("meta:".length())); | |
55 | |
56 if( fieldName.startsWith("data:")) | |
57 { | |
58 int column = Integer.valueOf(fieldName.substring("data:".length())); | |
59 return data.get(index)[column]; | |
60 } | |
61 | |
62 return null; | |
63 } | |
64 } |