Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/common/AccessHelper.java @ 9069:1ffd38826175
access uinfo.vegetationzones+inundation_duration
author | gernotbelger |
---|---|
date | Tue, 15 May 2018 12:00:26 +0200 |
parents | 2ed3824a3d53 |
children |
rev | line source |
---|---|
9067 | 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.common; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 import org.dive4elements.artifacts.Artifact; | |
14 import org.dive4elements.river.artifacts.D4EArtifact; | |
15 import org.dive4elements.river.artifacts.access.Access; | |
16 | |
17 import gnu.trove.TIntArrayList; | |
18 | |
19 /** | |
20 * @author Domenico Nardi Tironi | |
21 * | |
22 */ | |
23 public class AccessHelper extends Access { | |
24 | |
25 private static Logger log = Logger.getLogger(AccessHelper.class); | |
26 | |
27 // private final Artifact artifact; | |
28 | |
29 public AccessHelper(final Artifact artifact) { | |
30 this.artifact = (D4EArtifact) artifact; | |
31 } | |
32 | |
33 public String getYearEpoch() { | |
34 | |
35 return getString("ye_select"); // ACHTUNG, Ergebniswerte wurden geändert in state.sinfo.epoch und state.sinfo.year | |
36 | |
37 } | |
38 | |
39 /** [year1, years2,..] if its about years. */ | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9067
diff
changeset
|
40 public int[] getYears(final String yearSelectedValue, final String yearKey) { |
9067 | 41 int[] years = null; |
42 // if (years != null) { | |
43 // return years; | |
44 // } | |
45 if (getYearEpoch().equals(yearSelectedValue)) { | |
46 final TIntArrayList ints = new TIntArrayList(); | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9067
diff
changeset
|
47 final String yearsData = getString(yearKey); |
9067 | 48 if (yearsData == null || yearsData.isEmpty()) { |
49 log.warn("No years provided"); | |
50 return null; | |
51 } | |
52 for (final String sValue : yearsData.split(" ")) { | |
53 try { | |
54 ints.add(Integer.parseInt(sValue)); | |
55 } | |
56 catch (final NumberFormatException e) { | |
57 /* Client should prevent this */ | |
58 log.warn("Invalid year value: " + sValue); | |
59 continue; | |
60 } | |
61 } | |
62 | |
63 if (!ints.isEmpty()) { | |
64 ints.sort(); | |
65 years = ints.toNativeArray(); | |
66 } | |
67 return years; | |
68 } | |
69 return null; | |
70 } | |
71 | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9067
diff
changeset
|
72 public int[][] getEpochs(final String epochSelectedValue, final String epochKey) { |
9067 | 73 int epochs[][] = null; |
74 // if (epochs != null) { | |
75 // return epochs; | |
76 // } | |
77 | |
78 if (!getYearEpoch().equals(epochSelectedValue)) { | |
79 return null; | |
80 } | |
81 | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9067
diff
changeset
|
82 final String data = getString(epochKey); |
9067 | 83 |
84 if (data == null) { | |
85 log.warn("No 'epochs' parameter specified!"); | |
86 return null; | |
87 } | |
88 | |
89 final String[] parts = data.split(";"); | |
90 | |
91 epochs = new int[parts.length][]; | |
92 | |
93 for (int i = 0; i < parts.length; i++) { | |
94 final String[] values = parts[i].split(","); | |
95 final TIntArrayList ints = new TIntArrayList(); | |
96 try { | |
97 ints.add(Integer.parseInt(values[0])); | |
98 ints.add(Integer.parseInt(values[1])); | |
99 epochs[i] = ints.toNativeArray(); | |
100 } | |
101 catch (final NumberFormatException nfe) { | |
102 log.warn("Cannot parse int from string: '" + values + "'"); | |
103 } | |
104 } | |
105 return epochs; | |
106 } | |
107 | |
108 } |