annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixReferenceEventsFacet.java @ 6873:6848c5c8fc23

FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 19 Aug 2013 22:19:09 +0200
parents 08e3c22500f3
children 437856cec419
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
9 package org.dive4elements.river.artifacts.model.fixings;
3035
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
3466
8160e62bbb3a Registered new output 'fix_vollmer_wq_curve' for the vollmer path of fixings analysis module; create required Facets for it after calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3415
diff changeset
11 import org.apache.log4j.Logger;
8160e62bbb3a Registered new output 'fix_vollmer_wq_curve' for the vollmer path of fixings analysis module; create required Facets for it after calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3415
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
13 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
14 import org.dive4elements.artifacts.CallContext;
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
15 import org.dive4elements.river.artifacts.D4EArtifact;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
16 import org.dive4elements.river.artifacts.model.CalculationResult;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
17 import org.dive4elements.river.artifacts.model.FacetTypes;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
18 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5335
diff changeset
19 import org.dive4elements.river.utils.KMIndex;
3035
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 /**
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 * Facet to show W values for Q values at km for a date.
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 *
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 */
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 public class FixReferenceEventsFacet
4442
26774405c884 Introduce a new FixingsFacet to add save access to the current Km
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3610
diff changeset
28 extends FixingsFacet
3035
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 implements FacetTypes {
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 /** House logger. */
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 private static Logger logger = Logger.getLogger(FixReferenceEventsFacet.class);
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 /** Trivial Constructor. */
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 public FixReferenceEventsFacet() {
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 }
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 /**
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 * @param name
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 */
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3039
diff changeset
42 public FixReferenceEventsFacet(int index, String name, String description) {
3039
7db919b1bc1e Added new facet for analysis periods and updated facet names in fix analysis.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3035
diff changeset
43 super(index,
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3039
diff changeset
44 name,
3039
7db919b1bc1e Added new facet for analysis periods and updated facet names in fix analysis.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3035
diff changeset
45 description,
7db919b1bc1e Added new facet for analysis periods and updated facet names in fix analysis.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3035
diff changeset
46 ComputeType.ADVANCE,
7db919b1bc1e Added new facet for analysis periods and updated facet names in fix analysis.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3035
diff changeset
47 null,
7db919b1bc1e Added new facet for analysis periods and updated facet names in fix analysis.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3035
diff changeset
48 null);
3035
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 }
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 /**
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 * Returns the data this facet requires.
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 *
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 * @param artifact the owner artifact.
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 * @param context the CallContext (ignored).
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 *
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 * @return the data.
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 */
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 @Override
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 public Object getData(Artifact artifact, CallContext context) {
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 logger.debug("FixReferenceEventsFacet.getData");
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63
6868
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
64 if (!(artifact instanceof D4EArtifact)) {
3035
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 logger.debug("Not an instance of FixationArtifact.");
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 return null;
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 }
6868
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
68
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
69 D4EArtifact flys = (D4EArtifact)artifact;
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
70
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
71 CalculationResult res =
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
72 (CalculationResult) flys.compute(context,
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
73 ComputeType.ADVANCE,
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
74 false);
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
75
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
76 FixResult result = (FixResult) res.getData();
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
77 double currentKm = getCurrentKm(context);
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
78
6873
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
79 if (logger.isDebugEnabled()) {
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
80 logger.debug("current km in FRE: " + currentKm);
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
81 }
6868
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
82
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
83 KMIndex<QWD []> kmQWs = result.getReferenced();
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
84 KMIndex.Entry<QWD []> kmQWsEntry = kmQWs.binarySearch(currentKm);
6873
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
85
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
86 if (kmQWsEntry == null) {
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
87 return null;
6868
08e3c22500f3 Fix Analysis: Code simplification in facets.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
88 }
6873
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
89
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
90 // The lower eight bits contain the index of the point.
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
91 int ndx = index & 255;
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
92 QWD [] qwds = kmQWsEntry.getValue();
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
93 if (ndx >= qwds.length) {
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
94 logger.error("index too large: " + ndx + " " + qwds.length);
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
95 return null;
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
96 }
6848c5c8fc23 FixA: Reference points facets: the index of the point is stored in the lower 8 bits of the facect index. Why was it search via getIndex()?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6868
diff changeset
97 return qwds[ndx];
3035
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 }
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 /**
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 * Create a deep copy of this Facet.
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 * @return a deep copy.
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 */
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 @Override
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 public FixReferenceEventsFacet deepCopy() {
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 FixReferenceEventsFacet copy = new FixReferenceEventsFacet();
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 copy.set(this);
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 return copy;
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 }
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 }
b388d888330d Implemented facets and splitted up the event facet.Implemented facets and splitted up the event facet.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org