Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisEventsFacet.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 | af13ceeba52a |
children | e4606eae8ea5 |
comparison
equal
deleted
inserted
replaced
6867:0f3dad5d74a2 | 6868:08e3c22500f3 |
---|---|
62 */ | 62 */ |
63 @Override | 63 @Override |
64 public Object getData(Artifact artifact, CallContext context) { | 64 public Object getData(Artifact artifact, CallContext context) { |
65 logger.debug("FixAnalysisEventsFacet.getData"); | 65 logger.debug("FixAnalysisEventsFacet.getData"); |
66 | 66 |
67 if (artifact instanceof D4EArtifact) { | 67 if (!(artifact instanceof D4EArtifact)) { |
68 D4EArtifact flys = (D4EArtifact)artifact; | |
69 | |
70 CalculationResult res = | |
71 (CalculationResult) flys.compute(context, | |
72 ComputeType.ADVANCE, | |
73 false); | |
74 | |
75 FixAnalysisResult result = (FixAnalysisResult) res.getData(); | |
76 double currentKm = getCurrentKm(context); | |
77 | |
78 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods(); | |
79 KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = | |
80 kmPeriods.binarySearch(currentKm); | |
81 | |
82 if(kmPeriodsEntry == null) { | |
83 logger.debug("getData: kmPeriodsEntry == null"); | |
84 return null; | |
85 } | |
86 | |
87 AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); | |
88 if (periods == null) { | |
89 logger.debug("getData: periods == null"); | |
90 return null; | |
91 } | |
92 int ndx = index >> 8; | |
93 QWD[] qwdData = periods[ndx].getQWDs(); | |
94 if (qwdData == null) { | |
95 return null; | |
96 } | |
97 int ndy = index & 255; | |
98 for (int i = 0; i < qwdData.length; i++) { | |
99 if (qwdData[i].getIndex() == ndy) { | |
100 return qwdData[i]; | |
101 } | |
102 } | |
103 return null; | |
104 } | |
105 else { | |
106 logger.debug("Not an instance of FixationArtifact."); | 68 logger.debug("Not an instance of FixationArtifact."); |
107 return null; | 69 return null; |
108 } | 70 } |
71 D4EArtifact flys = (D4EArtifact)artifact; | |
72 | |
73 CalculationResult res = | |
74 (CalculationResult) flys.compute(context, | |
75 ComputeType.ADVANCE, | |
76 false); | |
77 | |
78 FixAnalysisResult result = (FixAnalysisResult) res.getData(); | |
79 double currentKm = getCurrentKm(context); | |
80 | |
81 KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods(); | |
82 KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry = | |
83 kmPeriods.binarySearch(currentKm); | |
84 | |
85 if (kmPeriodsEntry == null) { | |
86 logger.debug("getData: kmPeriodsEntry == null"); | |
87 return null; | |
88 } | |
89 | |
90 AnalysisPeriod[] periods = kmPeriodsEntry.getValue(); | |
91 if (periods == null) { | |
92 logger.debug("getData: periods == null"); | |
93 return null; | |
94 } | |
95 int ndx = index >> 8; | |
96 QWD[] qwdData = periods[ndx].getQWDs(); | |
97 if (qwdData == null) { | |
98 return null; | |
99 } | |
100 int ndy = index & 255; | |
101 | |
102 for (QWD qwd: qwdData) { | |
103 if (qwd.getIndex() == ndy) { | |
104 return qwd; | |
105 } | |
106 } | |
107 return null; | |
109 } | 108 } |
110 | 109 |
111 | 110 |
112 /** | 111 /** |
113 * Create a deep copy of this Facet. | 112 * Create a deep copy of this Facet. |