8961
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.artifacts.model.minfo; |
|
10 |
|
11 import java.util.List; |
|
12 |
|
13 import org.dive4elements.artifacts.Artifact; |
|
14 import org.dive4elements.artifacts.CallContext; |
|
15 import org.dive4elements.river.artifacts.D4EArtifact; |
|
16 import org.dive4elements.river.artifacts.access.BedHeightAccess; |
|
17 import org.dive4elements.river.artifacts.model.BlackboardDataFacet; |
|
18 import org.dive4elements.river.artifacts.model.FacetTypes; |
|
19 import org.dive4elements.river.artifacts.resources.Resources; |
|
20 import org.dive4elements.river.model.BedHeight; |
|
21 import org.dive4elements.river.model.BedHeightValue; |
|
22 |
|
23 import gnu.trove.TDoubleArrayList; |
|
24 |
|
25 /** |
|
26 * More or less the same as {@link BedHeightFacet}, but was necessary to copy because else we break the old |
|
27 * serialization. |
|
28 * |
|
29 * @author Gernot Belger |
|
30 */ |
|
31 public class BedHeightMinMaxFacet extends BlackboardDataFacet implements FacetTypes { |
|
32 |
|
33 private static final long serialVersionUID = 1L; |
|
34 |
|
35 public static enum BedHeightValueType { |
|
36 min { |
|
37 @Override |
|
38 public Double getValue(final BedHeightValue bedheightValue) { |
|
39 return bedheightValue.getMinHeight(); |
|
40 } |
|
41 }, |
|
42 max { |
|
43 @Override |
|
44 public Double getValue(final BedHeightValue bedheightValue) { |
|
45 return bedheightValue.getMaxHeight(); |
|
46 } |
|
47 }, |
|
48 value { |
|
49 @Override |
|
50 public Double getValue(final BedHeightValue bedheightValue) { |
|
51 return bedheightValue.getHeight(); |
|
52 } |
|
53 }; |
|
54 |
|
55 public abstract Double getValue(final BedHeightValue bedheightValue); |
|
56 } |
|
57 |
|
58 private final BedHeightValueType valueType; |
|
59 |
|
60 public BedHeightMinMaxFacet(final String name, final String description, final BedHeightValueType valueType) { |
|
61 super(0, name, description); |
|
62 |
|
63 this.valueType = valueType; |
|
64 |
|
65 this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); |
|
66 this.metaData.put("Y", "chart.bedheight_middle.section.yaxis.label"); |
|
67 } |
|
68 |
|
69 /** |
|
70 * Returns the data this facet requires. |
|
71 * |
|
72 * @param artifact |
|
73 * the owner artifact. |
|
74 * @param context |
|
75 * the CallContext (ignored). |
|
76 * |
|
77 * @return the data. |
|
78 */ |
|
79 @Override |
|
80 public Object getData(final Artifact artifact, final CallContext context) { |
|
81 |
|
82 final BedHeightAccess access = new BedHeightAccess((D4EArtifact) artifact); |
|
83 |
|
84 final BedHeight single = BedHeight.getBedHeightById(access.getHeightId()); |
|
85 |
|
86 final List<BedHeightValue> bedheightValues = BedHeightValue.getBedHeightValues(single, access.getFrom(true), access.getTo(true)); |
|
87 |
|
88 final TDoubleArrayList stations = new TDoubleArrayList(bedheightValues.size()); |
|
89 final TDoubleArrayList values = new TDoubleArrayList(bedheightValues.size()); |
|
90 |
|
91 for (final BedHeightValue bedheightValue : bedheightValues) { |
|
92 |
|
93 final Double station = bedheightValue.getStation(); |
|
94 final Double value = this.valueType.getValue(bedheightValue); |
|
95 |
|
96 if (station != null && value != null) { |
|
97 stations.add(station); |
|
98 values.add(value); |
|
99 } |
|
100 } |
|
101 |
|
102 this.addMetaData(Resources.getMsg(context.getMeta(), "meta.bedheight.cur.elevation"), single.getCurElevationModel().getName()); |
|
103 |
|
104 if (single.getOldElevationModel() != null) |
|
105 this.addMetaData(Resources.getMsg(context.getMeta(), "meta.bedheight.old.elevation"), single.getOldElevationModel().getName()); |
|
106 |
|
107 this.addMetaData(Resources.getMsg(context.getMeta(), "meta.bedheight.river.elevation"), access.getRiver().getWstUnit().getName()); |
|
108 |
|
109 return new double[][] { stations.toNativeArray(), values.toNativeArray() }; |
|
110 } |
|
111 |
|
112 /** |
|
113 * Create a deep copy of this Facet. |
|
114 * |
|
115 * @return a deep copy. |
|
116 */ |
|
117 @Override |
|
118 public BedHeightMinMaxFacet deepCopy() { |
|
119 final BedHeightMinMaxFacet copy = new BedHeightMinMaxFacet(this.name, this.description, this.valueType); |
|
120 copy.set(this); |
|
121 return copy; |
|
122 } |
|
123 } |