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