Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/DischargeLongitudinalSection.java @ 9479:2b83d3a96703
i18n TODO "benutzerdefiniert" = "custom" fixed
author | gernotbelger |
---|---|
date | Mon, 10 Sep 2018 15:31:55 +0200 |
parents | 3f49835a00c3 |
children |
comparison
equal
deleted
inserted
replaced
9478:7e2eebc14e1f | 9479:2b83d3a96703 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states; | 9 package org.dive4elements.river.artifacts.states; |
10 | 10 |
11 import java.util.List; | |
12 | |
13 import org.apache.log4j.Logger; | |
11 import org.dive4elements.artifactdatabase.state.Facet; | 14 import org.dive4elements.artifactdatabase.state.Facet; |
12 import org.dive4elements.artifactdatabase.state.FacetActivity; | 15 import org.dive4elements.artifactdatabase.state.FacetActivity; |
13 | |
14 import org.dive4elements.artifacts.Artifact; | 16 import org.dive4elements.artifacts.Artifact; |
15 import org.dive4elements.artifacts.CallContext; | 17 import org.dive4elements.artifacts.CallContext; |
16 | |
17 import org.dive4elements.river.artifacts.ChartArtifact; | 18 import org.dive4elements.river.artifacts.ChartArtifact; |
18 import org.dive4elements.river.artifacts.D4EArtifact; | 19 import org.dive4elements.river.artifacts.D4EArtifact; |
19 | |
20 import org.dive4elements.river.artifacts.access.Calculation4Access; | 20 import org.dive4elements.river.artifacts.access.Calculation4Access; |
21 | |
22 import org.dive4elements.river.artifacts.model.Calculation4; | 21 import org.dive4elements.river.artifacts.model.Calculation4; |
23 import org.dive4elements.river.artifacts.model.CalculationResult; | 22 import org.dive4elements.river.artifacts.model.CalculationResult; |
24 import org.dive4elements.river.artifacts.model.ConstantWQKms; | 23 import org.dive4elements.river.artifacts.model.ConstantWQKms; |
25 import org.dive4elements.river.artifacts.model.CrossSectionWaterLineFacet; | 24 import org.dive4elements.river.artifacts.model.CrossSectionWaterLineFacet; |
26 import org.dive4elements.river.artifacts.model.DataFacet; | 25 import org.dive4elements.river.artifacts.model.DataFacet; |
28 import org.dive4elements.river.artifacts.model.FacetTypes; | 27 import org.dive4elements.river.artifacts.model.FacetTypes; |
29 import org.dive4elements.river.artifacts.model.ReportFacet; | 28 import org.dive4elements.river.artifacts.model.ReportFacet; |
30 import org.dive4elements.river.artifacts.model.WQCKms; | 29 import org.dive4elements.river.artifacts.model.WQCKms; |
31 import org.dive4elements.river.artifacts.model.WQKms; | 30 import org.dive4elements.river.artifacts.model.WQKms; |
32 import org.dive4elements.river.artifacts.model.WaterlevelFacet; | 31 import org.dive4elements.river.artifacts.model.WaterlevelFacet; |
32 import org.dive4elements.river.artifacts.resources.Resources; | |
33 | 33 |
34 import java.util.List; | 34 public class DischargeLongitudinalSection extends DefaultState implements FacetTypes { |
35 | 35 private static Logger log = Logger.getLogger(DischargeLongitudinalSection.class); |
36 import org.apache.log4j.Logger; | |
37 | |
38 public class DischargeLongitudinalSection | |
39 extends DefaultState | |
40 implements FacetTypes | |
41 { | |
42 private static Logger log = | |
43 Logger.getLogger(DischargeLongitudinalSection.class); | |
44 | 36 |
45 static { | 37 static { |
46 // Active/deactivate facets. | 38 // Active/deactivate facets. |
47 FacetActivity.Registry.getInstance().register( | 39 FacetActivity.Registry.getInstance().register("winfo", new FacetActivity() { |
48 "winfo", | 40 @Override |
49 new FacetActivity() { | 41 public Boolean isInitialActive(final Artifact artifact, final Facet facet, final String output) { |
50 @Override | 42 final String name = facet.getName(); |
51 public Boolean isInitialActive( | 43 if (name.equals(DISCHARGE_LONGITUDINAL_Q_INFOLD_CUT)) { |
52 Artifact artifact, | 44 return Boolean.FALSE; |
53 Facet facet, | |
54 String output | |
55 ) { | |
56 String name = facet.getName(); | |
57 if (name.equals(DISCHARGE_LONGITUDINAL_Q_INFOLD_CUT)) { | |
58 return Boolean.FALSE; | |
59 } | |
60 return Boolean.TRUE; | |
61 } | 45 } |
62 }); | 46 return Boolean.TRUE; |
47 } | |
48 }); | |
63 } | 49 } |
64 | 50 |
65 @Override | 51 @Override |
66 public Object computeAdvance( | 52 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
67 D4EArtifact artifact, | |
68 String hash, | |
69 CallContext context, | |
70 List<Facet> facets, | |
71 Object old | |
72 ) { | |
73 if (artifact instanceof ChartArtifact) { | 53 if (artifact instanceof ChartArtifact) { |
74 facets.add(new EmptyFacet()); | 54 facets.add(new EmptyFacet()); |
75 return null; | 55 return null; |
76 } | 56 } |
77 | 57 |
78 Calculation4Access access = new Calculation4Access(artifact); | 58 final Calculation4Access access = new Calculation4Access(artifact); |
79 | 59 |
80 CalculationResult res = old instanceof CalculationResult | 60 final CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old : new Calculation4(access).calculate(context.getMeta()); |
81 ? (CalculationResult)old | |
82 : new Calculation4(access).calculate(); | |
83 | 61 |
84 if (facets == null) { | 62 if (facets == null) { |
85 return res; | 63 return res; |
86 } | 64 } |
87 | 65 |
88 WQKms [] wqkms = (WQKms [])res.getData(); | 66 final WQKms[] wqkms = (WQKms[]) res.getData(); |
89 | 67 |
90 for (int i = 0; i < wqkms.length; i++) { | 68 for (int i = 0; i < wqkms.length; i++) { |
91 String nameW = null; | 69 String nameW = null; |
92 String nameQ = null; | 70 String nameQ = null; |
93 | 71 |
94 if (access.isQ()) { | 72 if (access.isQ()) { |
95 nameQ = wqkms[i].getName(); | 73 nameQ = wqkms[i].getName(); |
96 nameW = "W(" + nameQ + ")"; | 74 nameW = "W(" + nameQ + ")"; |
97 } | 75 } else { |
98 else { | |
99 nameW = wqkms[i].getName(); | 76 nameW = wqkms[i].getName(); |
100 nameQ = "Q(" + nameW + ")"; | 77 nameQ = "Q(" + nameW + ")"; |
101 } | 78 } |
102 | 79 |
103 // Do not generate Waterlevel/Waterline facets | 80 // Do not generate Waterlevel/Waterline facets |
104 // for Q only curves. | 81 // for Q only curves. |
105 if (!(wqkms[i] instanceof ConstantWQKms)) { | 82 if (!(wqkms[i] instanceof ConstantWQKms)) { |
106 | 83 |
107 Facet w = new WaterlevelFacet( | 84 final Facet w = new WaterlevelFacet(i, DISCHARGE_LONGITUDINAL_W, nameW); |
108 i, DISCHARGE_LONGITUDINAL_W, nameW); | |
109 | 85 |
110 Facet s = new CrossSectionWaterLineFacet(i, nameW, ComputeType.ADVANCE, hash, getID(), Integer.valueOf(i)); | 86 final Facet s = new CrossSectionWaterLineFacet(i, nameW, ComputeType.ADVANCE, hash, getID(), Integer.valueOf(i)); |
111 | 87 |
112 Facet q = new WaterlevelFacet( | 88 final Facet q = new WaterlevelFacet(i, DISCHARGE_LONGITUDINAL_Q, nameQ); |
113 i, DISCHARGE_LONGITUDINAL_Q, nameQ); | |
114 facets.add(s); | 89 facets.add(s); |
115 facets.add(w); | 90 facets.add(w); |
116 facets.add(q); | 91 facets.add(q); |
117 } | 92 } else { |
118 else { | |
119 Facet q; | 93 Facet q; |
120 if (nameQ.contains("geschnitten")) { | 94 if (nameQ.contains("geschnitten")) { |
121 q = new WaterlevelFacet( | 95 q = new WaterlevelFacet(i, DISCHARGE_LONGITUDINAL_Q_INFOLD_CUT, nameQ); |
122 i, DISCHARGE_LONGITUDINAL_Q_INFOLD_CUT, nameQ); | 96 } else { |
123 } | 97 q = new WaterlevelFacet(i, DISCHARGE_LONGITUDINAL_Q_INFOLD, nameQ); |
124 else { | |
125 q = new WaterlevelFacet( | |
126 i, DISCHARGE_LONGITUDINAL_Q_INFOLD, nameQ); | |
127 } | 98 } |
128 facets.add(q); | 99 facets.add(q); |
129 } | 100 } |
130 | 101 |
102 final String custom = Resources.getMsg(context.getMeta(), "common.custom"); | |
131 if (wqkms[i] instanceof WQCKms) { | 103 if (wqkms[i] instanceof WQCKms) { |
132 // TODO DO i18n | 104 // TODO DO i18n |
133 | 105 |
134 String nameC = nameW.replace( | 106 final String nameC = nameW.replace(custom, Resources.getMsg(context.getMeta(), "custom.corrected")); |
135 "benutzerdefiniert", | |
136 "benutzerdefiniert [korrigiert]"); | |
137 | 107 |
138 Facet c = new WaterlevelFacet( | 108 final Facet c = new WaterlevelFacet(i, DISCHARGE_LONGITUDINAL_C, nameC); |
139 i, DISCHARGE_LONGITUDINAL_C, nameC); | |
140 | 109 |
141 // Here, avoid index clash with Facet "s" above and | 110 // Here, avoid index clash with Facet "s" above and |
142 // signal the WINFO later that we want to access Cs. | 111 // signal the WINFO later that we want to access Cs. |
143 Facet r = new CrossSectionWaterLineFacet(i + 1, nameC, ComputeType.ADVANCE, hash, getID(), Integer.valueOf(i + 1)); | 112 final Facet r = new CrossSectionWaterLineFacet(i + 1, nameC, ComputeType.ADVANCE, hash, getID(), Integer.valueOf(i + 1)); |
144 | 113 |
145 facets.add(c); | 114 facets.add(c); |
146 facets.add(r); | 115 facets.add(r); |
147 } | 116 } |
148 } | 117 } |