comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoCalculationResult.java @ 9000:50cc99579a46

Work on uinfo
author gernotbelger
date Thu, 12 Apr 2018 19:16:10 +0200
parents b194fa64506a
children
comparison
equal deleted inserted replaced
8999:e3b3ce32c825 9000:50cc99579a46
6 * This file is Free Software under the GNU AGPL (>=v3) 6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package org.dive4elements.river.artifacts.sinfo.common; 10 package org.dive4elements.river.artifacts.sinfo.common;
11 11
12 import java.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.Collection; 12 import java.util.Collection;
15 import java.util.Collections; 13 import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
16 import java.util.List; 14 import org.dive4elements.river.artifacts.common.ResultRow;
17
18 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; 15 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
19 16
20 import gnu.trove.TDoubleArrayList;
21 17
22 /** 18 /**
23 * @author Gernot Belger 19 * @author Gernot Belger
24 */ 20 */
25 public abstract class AbstractSInfoCalculationResult implements Serializable { 21 public abstract class AbstractSInfoCalculationResult extends AbstractCalculationResult {
26 22
27 private static final long serialVersionUID = 1L; 23 private static final long serialVersionUID = 1L;
28 24
29 private final Collection<SInfoResultRow> rows;
30
31 private final String label;
32
33 private final WstInfo wst; 25 private final WstInfo wst;
34 26
35 public AbstractSInfoCalculationResult(final String label, final WstInfo wst, final Collection<SInfoResultRow> rows) { 27 public AbstractSInfoCalculationResult(final String label, final WstInfo wst, final Collection< ResultRow> rows) {
36 this.label = label; 28 super(label, rows);
37 this.wst = wst; 29 this.wst = wst;
38 this.rows = new ArrayList<>(rows);
39 } 30 }
40 31
41 public final String getLabel() {
42 return this.label;
43 }
44 32
45 public final WstInfo getWst() { 33 public final WstInfo getWst() {
46 return this.wst; 34 return this.wst;
47 } 35 }
48
49 public boolean isEmpty() {
50 return this.rows.isEmpty();
51 }
52
53 public final void addRow(final SInfoResultRow resultRow) {
54 this.rows.add(resultRow);
55 }
56
57 public final Collection<SInfoResultRow> getRows() {
58 return Collections.unmodifiableCollection(this.rows);
59 }
60
61 public final double[][] getStationPoints(final SInfoResultType type) {
62
63 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
64 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
65
66 for (final SInfoResultRow row : this.rows) {
67
68 final double station = row.getDoubleValue(SInfoResultType.station);
69 final double value = row.getDoubleValue(type);
70
71 xPoints.add(station);
72 yPoints.add(value);
73 }
74
75 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
76 }
77
78 protected final <TYPE> List<TYPE> getValues(final SInfoResultType type) {
79
80 final List<TYPE> values = new ArrayList<>();
81
82 for (final SInfoResultRow row : this.rows) {
83 @SuppressWarnings("unchecked")
84 final TYPE value = (TYPE) row.getValue(type);
85 values.add(value);
86 }
87
88 return values;
89 }
90 } 36 }

http://dive4elements.wald.intevation.org