Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java @ 6868:08e3c22500f3
Fix Analysis: Code simplification in facets.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 19 Aug 2013 16:29:28 +0200 |
parents | a0078e5e3b39 |
children | cde863b2dae3 |
comparison
equal
deleted
inserted
replaced
6867:0f3dad5d74a2 | 6868:08e3c22500f3 |
---|---|
64 * | 64 * |
65 * @return the data. | 65 * @return the data. |
66 */ | 66 */ |
67 @Override | 67 @Override |
68 public Object getData(Artifact artifact, CallContext context) { | 68 public Object getData(Artifact artifact, CallContext context) { |
69 | |
69 logger.debug("getData"); | 70 logger.debug("getData"); |
70 if (artifact instanceof D4EArtifact) { | 71 if (!(artifact instanceof D4EArtifact)) { |
71 D4EArtifact flys = (D4EArtifact)artifact; | |
72 FixAnalysisAccess access = new FixAnalysisAccess(flys); | |
73 | |
74 CalculationResult res = | |
75 (CalculationResult) flys.compute(context, | |
76 ComputeType.ADVANCE, | |
77 false); | |
78 | |
79 FixResult result = (FixResult) res.getData(); | |
80 double currentKm = getCurrentKm(context); | |
81 | |
82 logger.debug("getData: km = " + currentKm); | |
83 | |
84 String function = access.getFunction(); | |
85 Function ff = FunctionFactory.getInstance().getFunction(function); | |
86 | |
87 if (ff == null) { | |
88 logger.warn("getData: ff == null"); | |
89 return null; | |
90 } | |
91 | |
92 Parameters params = result.getParameters(); | |
93 String[] paramNames = ff.getParameterNames(); | |
94 | |
95 double [] coeffs = params.interpolate("km", currentKm, paramNames); | |
96 | |
97 if (coeffs == null) { | |
98 logger.warn("getData: coeffs == null"); | |
99 return null; | |
100 } | |
101 | |
102 org.dive4elements.river.artifacts.math.Function mf = | |
103 ff.instantiate(coeffs); | |
104 | |
105 double maxQ = FixFacetUtils.getMaxQ(params, currentKm); | |
106 logger.debug("getData: maxQ = " + maxQ); | |
107 | |
108 FixFunction fix = new FixFunction( | |
109 ff.getName(), | |
110 ff.getDescription(), | |
111 mf, | |
112 maxQ); | |
113 | |
114 return fix; | |
115 } | |
116 else { | |
117 logger.debug("Not an instance of D4EArtifact / FixationArtifact."); | 72 logger.debug("Not an instance of D4EArtifact / FixationArtifact."); |
118 return null; | 73 return null; |
119 } | 74 } |
75 | |
76 D4EArtifact flys = (D4EArtifact)artifact; | |
77 FixAnalysisAccess access = new FixAnalysisAccess(flys); | |
78 | |
79 CalculationResult res = | |
80 (CalculationResult) flys.compute(context, | |
81 ComputeType.ADVANCE, | |
82 false); | |
83 | |
84 FixResult result = (FixResult) res.getData(); | |
85 double currentKm = getCurrentKm(context); | |
86 | |
87 logger.debug("getData: km = " + currentKm); | |
88 | |
89 String function = access.getFunction(); | |
90 Function ff = FunctionFactory.getInstance().getFunction(function); | |
91 | |
92 if (ff == null) { | |
93 logger.warn("getData: ff == null"); | |
94 return null; | |
95 } | |
96 | |
97 Parameters params = result.getParameters(); | |
98 String[] paramNames = ff.getParameterNames(); | |
99 | |
100 double [] coeffs = params.interpolate("km", currentKm, paramNames); | |
101 | |
102 if (coeffs == null) { | |
103 logger.warn("getData: coeffs == null"); | |
104 return null; | |
105 } | |
106 | |
107 org.dive4elements.river.artifacts.math.Function mf = | |
108 ff.instantiate(coeffs); | |
109 | |
110 double maxQ = FixFacetUtils.getMaxQ(params, currentKm); | |
111 logger.debug("getData: maxQ = " + maxQ); | |
112 | |
113 FixFunction fix = new FixFunction( | |
114 ff.getName(), | |
115 ff.getDescription(), | |
116 mf, | |
117 maxQ); | |
118 | |
119 return fix; | |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * Create a deep copy of this Facet. | 123 * Create a deep copy of this Facet. |
124 * @return a deep copy. | 124 * @return a deep copy. |