Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationRegionalResult.java @ 9319:c36befc9011c
Salix: Fixed ArrrayoutOfBoundsException; minor cleanup
author | gernotbelger |
---|---|
date | Fri, 27 Jul 2018 10:18:18 +0200 |
parents | 72b3270e1568 |
children | b3d3c958a594 |
comparison
equal
deleted
inserted
replaced
9317:61b5de0b673b | 9319:c36befc9011c |
---|---|
11 | 11 |
12 import java.text.NumberFormat; | 12 import java.text.NumberFormat; |
13 import java.util.Collection; | 13 import java.util.Collection; |
14 import java.util.List; | 14 import java.util.List; |
15 | 15 |
16 import org.apache.commons.lang.StringUtils; | |
16 import org.dive4elements.river.artifacts.common.ExportContextCSV; | 17 import org.dive4elements.river.artifacts.common.ExportContextCSV; |
17 import org.dive4elements.river.artifacts.common.GeneralResultType; | 18 import org.dive4elements.river.artifacts.common.GeneralResultType; |
18 import org.dive4elements.river.artifacts.common.IExportContext; | 19 import org.dive4elements.river.artifacts.common.IExportContext; |
19 import org.dive4elements.river.artifacts.common.ResultRow; | 20 import org.dive4elements.river.artifacts.common.ResultRow; |
20 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; | 21 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
41 } | 42 } |
42 | 43 |
43 public String getScenarioLabel(final int i) { | 44 public String getScenarioLabel(final int i) { |
44 if ((this.scenarioLabels != null) && (i < this.scenarioLabels.length)) | 45 if ((this.scenarioLabels != null) && (i < this.scenarioLabels.length)) |
45 return this.scenarioLabels[i]; | 46 return this.scenarioLabels[i]; |
46 else | 47 |
47 return ""; | 48 return ""; |
48 } | 49 } |
49 | 50 |
50 @Override | 51 @Override |
51 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { | 52 public void writeCSVHeader(final ExportContextCSV exportContextCSV, final RiverInfo river) { |
52 | 53 |
61 | 62 |
62 @Override | 63 @Override |
63 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { | 64 protected void writeCSVResultMetadata(final ExportContextCSV exportContextCSV) { |
64 writeRegionalEffectsCSVMetadata(exportContextCSV); | 65 writeRegionalEffectsCSVMetadata(exportContextCSV); |
65 exportContextCSV.writeBlankLine(); | 66 exportContextCSV.writeBlankLine(); |
66 | |
67 } | 67 } |
68 | 68 |
69 @Override | 69 @Override |
70 protected String[] formatRow(final IExportContext context, final ResultRow row) { | 70 protected String[] formatRow(final IExportContext context, final ResultRow row) { |
71 | 71 |
75 final NumberFormat formatter = ((ExportContextCSV) context).getSalixScenFormatter(); | 75 final NumberFormat formatter = ((ExportContextCSV) context).getSalixScenFormatter(); |
76 final List<SalixScenario> scenList = (List<SalixScenario>) row.getValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl); | 76 final List<SalixScenario> scenList = (List<SalixScenario>) row.getValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl); |
77 | 77 |
78 for (final SalixScenario scenario : scenList) { | 78 for (final SalixScenario scenario : scenList) { |
79 // scenario unused; index wurde ja verworfen, stattdessen 2 spalten | 79 // scenario unused; index wurde ja verworfen, stattdessen 2 spalten |
80 lines.add(scenario.getSalixValueFormatted(formatter)); | 80 if (scenario == null) { |
81 lines.add(scenario.getDwsplFormatted()); | 81 lines.add(StringUtils.EMPTY); |
82 lines.add(StringUtils.EMPTY); | |
83 } else { | |
84 lines.add(scenario.getSalixValueFormatted(formatter)); | |
85 lines.add(scenario.getDwsplFormatted()); | |
86 } | |
82 } | 87 } |
83 } | 88 } |
84 return lines.toArray(new String[lines.size()]); | 89 return lines.toArray(new String[lines.size()]); |
85 } | 90 } |
86 | 91 |
104 for (final ResultRow row : rows) { | 109 for (final ResultRow row : rows) { |
105 | 110 |
106 final double station = row.getDoubleValue(GeneralResultType.station); | 111 final double station = row.getDoubleValue(GeneralResultType.station); |
107 | 112 |
108 final List<SalixScenario> scenarios = (List<SalixScenario>) row.getValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl); | 113 final List<SalixScenario> scenarios = (List<SalixScenario>) row.getValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl); |
109 if (dataIndex <= scenarios.size() - 1) { | 114 final SalixScenario salixScenario = scenarios.get(dataIndex); |
110 final double value = scenarios.get(dataIndex).getSalixValue(); | 115 if (salixScenario != null) { |
116 final double value = salixScenario.getSalixValue(); | |
111 xPoints.add(station); | 117 xPoints.add(station); |
112 yPoints.add(value); | 118 yPoints.add(value); |
113 } | 119 } |
114 } | 120 } |
115 | 121 |
116 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | 122 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
117 } | 123 } |
118 | |
119 // TODO: move to SupraRegionalEffectsResult-Class; remove here | |
120 // private void writeExtendedRegionalEffectsCSVMetadata(final ExportContextCSV exportContextCSV) { | |
121 // final String main = "uinfo.export.csv.meta.header.salix.regionalextended"; | |
122 // // "##Überregional wirkende Eingriffe" | |
123 // exportContextCSV.writeCSVMetaEntry(main); | |
124 // | |
125 // writeRegionalCommonCSVMeta(exportContextCSV); | |
126 // } | |
127 | |
128 // TODO: move to historical class and delete here | |
129 // private void writeHistoricalViewCSVMetadata(final ExportContextCSV exportContextCSV) { | |
130 // final String main = "uinfo.export.csv.meta.header.salix.historical"; | |
131 // // "##Historische Betrachtung" | |
132 // exportContextCSV.writeCSVMetaEntry(main); | |
133 // | |
134 // final String mainSub = "uinfo.export.csv.meta.header.salix"; | |
135 // // "# Szenariotyp: " | |
136 // exportContextCSV.writeCSVMetaEntry(mainSub + ".szenariotyp"); | |
137 // // "# Teilabschnitt: " | |
138 // exportContextCSV.writeCSVMetaEntry(mainSub + ".teilabschnitt"); | |
139 // | |
140 // // "# Art des Zeitraums: " | |
141 // exportContextCSV.writeCSVMetaEntry(main + ".zeitart"); | |
142 // // "# Historischer Zeitpunkt: " | |
143 // exportContextCSV.writeCSVMetaEntry(main + ".zeitpunkt"); | |
144 // } | |
145 } | 124 } |