Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java @ 3786:4adc35aa655c
merged flys-artifacts/2.9.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:47 +0200 |
parents | e727e3ebdf85 |
children | 26774405c884 |
comparison
equal
deleted
inserted
replaced
3719:e82acd5c86f7 | 3786:4adc35aa655c |
---|---|
1 package de.intevation.flys.artifacts.model.fixings; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import de.intevation.artifacts.Artifact; | |
6 import de.intevation.artifacts.CallContext; | |
7 import de.intevation.flys.artifacts.FLYSArtifact; | |
8 import de.intevation.flys.artifacts.model.CalculationResult; | |
9 import de.intevation.flys.artifacts.model.DataFacet; | |
10 import de.intevation.flys.artifacts.model.FacetTypes; | |
11 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | |
12 import de.intevation.flys.utils.KMIndex; | |
13 | |
14 /** | |
15 * Facet to show the outliers in a fix calculation. | |
16 * | |
17 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
18 */ | |
19 public class FixOutlierFacet | |
20 extends DataFacet | |
21 implements FacetTypes { | |
22 | |
23 /** House logger. */ | |
24 private static Logger logger = Logger.getLogger(FixOutlierFacet.class); | |
25 | |
26 /** Trivial Constructor. */ | |
27 public FixOutlierFacet() { | |
28 } | |
29 | |
30 | |
31 /** | |
32 * @param name | |
33 */ | |
34 public FixOutlierFacet(String name, String description) { | |
35 super(0, name, description, ComputeType.ADVANCE, null, null); | |
36 } | |
37 | |
38 public FixOutlierFacet(int index, String name, String description) { | |
39 super(index, name, description, ComputeType.ADVANCE, null, null); | |
40 } | |
41 | |
42 | |
43 /** | |
44 * Returns the data this facet requires. | |
45 * | |
46 * @param artifact the owner artifact; needs to be a FLYSArtifact. | |
47 * @param context the CallContext; required to retrieve the value of | |
48 * <i>currentKm</i>. | |
49 * | |
50 * @return an array of QW objects or null. | |
51 */ | |
52 @Override | |
53 public Object getData(Artifact artifact, CallContext context) { | |
54 logger.debug("FixOutlierFacet.getData"); | |
55 | |
56 if (artifact instanceof FLYSArtifact) { | |
57 FLYSArtifact flys = (FLYSArtifact)artifact; | |
58 | |
59 CalculationResult res = | |
60 (CalculationResult) flys.compute(context, | |
61 ComputeType.ADVANCE, | |
62 false); | |
63 | |
64 FixResult result = (FixResult) res.getData(); | |
65 double currentKm = | |
66 ((Double)context.getContextValue("currentKm")).doubleValue(); | |
67 | |
68 KMIndex<QWI []> kmQWs = result.getOutliers(); | |
69 KMIndex.Entry<QWI []> qwsEntry = kmQWs.binarySearch(currentKm); | |
70 | |
71 QWI [] qws = null; | |
72 if (qwsEntry != null) { | |
73 qws = qwsEntry.getValue(); | |
74 | |
75 if (logger.isDebugEnabled()) { | |
76 logger.debug("Found " + (qws != null ? qws.length : 0) | |
77 + " KMIndex.Entry for km " + currentKm); | |
78 } | |
79 } | |
80 else { | |
81 logger.debug("Found no KMIndex.Entry for km " + currentKm); | |
82 } | |
83 | |
84 return qws; | |
85 } | |
86 | |
87 logger.warn("Not an instance of FLYSArtifact."); | |
88 return null; | |
89 } | |
90 | |
91 | |
92 /** | |
93 * Create a deep copy of this Facet. | |
94 * @return a deep copy. | |
95 */ | |
96 @Override | |
97 public FixOutlierFacet deepCopy() { | |
98 FixOutlierFacet copy = new FixOutlierFacet(); | |
99 copy.set(this); | |
100 return copy; | |
101 } | |
102 } | |
103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |