Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WDifferencesState.java @ 1154:24b87650136f
Fix ArrayIndexOutOfBounds in certain cases.
flys-artifacts/trunk@2685 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 09 Sep 2011 12:37:52 +0000 |
parents | 62ad0a753b68 |
children | fbe18ad4caff |
rev | line source |
---|---|
1151
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.states; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
3 import java.util.List; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
4 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
6 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.artifacts.CallContext; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
8 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.artifactdatabase.state.Facet; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.artifacts.FLYSArtifact; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.flys.artifacts.WINFOArtifact; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.artifacts.math.WKmsOperation; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.flys.artifacts.model.DurationCurveFacet; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.flys.artifacts.model.FacetTypes; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.flys.artifacts.model.WKms; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.artifacts.model.WQKms; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.artifacts.model.WQDay; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.artifacts.model.DataFacet; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.flys.artifacts.model.ReportFacet; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.flys.artifacts.model.CalculationResult; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 import de.intevation.flys.artifacts.resources.Resources; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 import de.intevation.flys.utils.FLYSUtils; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 public class WDifferencesState |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 extends DefaultState |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 implements FacetTypes |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 /** The logger that is used in this state. */ |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 private static Logger logger = Logger.getLogger(WDifferencesState.class); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 public WDifferencesState() { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 /** Specify to display a datacage_twin_panel. */ |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
42 @Override |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
43 protected String getUIProvider() { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
44 return "datacage_twin_panel"; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
45 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
46 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
47 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 @Override |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
49 public Object computeAdvance( |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 FLYSArtifact artifact, |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
51 String hash, |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
52 CallContext context, |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
53 List<Facet> facets, |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
54 Object old |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
55 ) { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
56 WINFOArtifact winfo = (WINFOArtifact)artifact; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
57 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
58 // Get a data item (uuids) or parameterization of the respective |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
59 // artifacts. |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
60 // TODO Fix, choose artifacts/parameterization dynamically. |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
61 WINFOArtifact flys1 = (WINFOArtifact) FLYSUtils.getArtifact( |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
62 //"a110a16d-d155-4115-ab0d-c4c61101c9cb", //Collection |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
63 "a0ec533f-b05b-4dcd-9db3-7850686f90a2", |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
64 context); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
65 WINFOArtifact flys2 = (WINFOArtifact) FLYSUtils.getArtifact( |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
66 //"8ebb696d-771a-4540-bd18-15e19744a6e2", //Collection |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
67 "ce5a2c4e-3f9c-4c4d-a35c-109dd8670992", |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
68 context); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
69 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
70 if (flys1 == null) { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
71 logger.warn("One of the artifacts (1) for diff calculation could not be loaded"); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
72 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
73 if (flys2 == null) { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
74 logger.warn("One of the artifacts (2) for diff calculation could not be loaded"); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
75 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
76 WKms wkms = null; |
1153
62ad0a753b68
Fix facet name and legend of w-differences, walk over distance state, too.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1151
diff
changeset
|
77 String facetName = "diff ()"; |
1151
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
78 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
79 if (flys1 != null && flys2 != null) { |
1153
62ad0a753b68
Fix facet name and legend of w-differences, walk over distance state, too.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1151
diff
changeset
|
80 // TODO also check size. |
62ad0a753b68
Fix facet name and legend of w-differences, walk over distance state, too.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1151
diff
changeset
|
81 // TODO also need index of wqkms. |
1151
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
82 WQKms[] minuend = (WQKms[]) flys1.getWaterlevelData().getData(); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
83 WQKms[] subtrahend = (WQKms[]) flys2.getWaterlevelData().getData(); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
84 wkms = WKmsOperation.SUBTRACTION.operate(minuend[0], subtrahend[0]); |
1153
62ad0a753b68
Fix facet name and legend of w-differences, walk over distance state, too.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1151
diff
changeset
|
85 facetName = "W ("+minuend[0].getName() + ") - W (" + subtrahend[0].getName()+")"; |
1151
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
86 logger.warn("Did a WKMSSubtraction"); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
87 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
88 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
89 if (facets != null) { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
90 // TODO: pass computetype and state id. |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
91 //, ComputeType.ADVANCE, getID(), hash)); |
1153
62ad0a753b68
Fix facet name and legend of w-differences, walk over distance state, too.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1151
diff
changeset
|
92 facets.add(new DataFacet(W_DIFFERENCES, facetName)); |
1151
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
93 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
94 else { |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
95 logger.debug("Not adding facets in WDifferencesState."); |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
96 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
97 |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
98 return wkms; |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
99 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
100 } |
08048bd090e6
Added very stubby WDifferences State/OutGenerator for WINFOArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |