Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResult.java @ 9425:3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
Also allows to have acces to the potentially already computed artifact result via its normal computation cache.
author | gernotbelger |
---|---|
date | Fri, 17 Aug 2018 15:31:02 +0200 |
parents | e5367900dd6d |
children | aa6ee96071b7 |
rev | line source |
---|---|
8999 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.common; | |
11 | |
12 import java.io.Serializable; | |
13 import java.util.ArrayList; | |
14 import java.util.Collection; | |
15 import java.util.Collections; | |
16 import java.util.List; | |
17 | |
9265 | 18 import org.apache.commons.collections.Predicate; |
19 import org.apache.commons.collections.functors.TruePredicate; | |
20 | |
8999 | 21 import gnu.trove.TDoubleArrayList; |
22 | |
23 /** | |
24 * @author Gernot Belger | |
25 */ | |
26 public abstract class AbstractCalculationResult implements Serializable { | |
27 | |
28 private static final long serialVersionUID = 1L; | |
29 | |
9265 | 30 private final Collection<ResultRow> rows; |
8999 | 31 |
32 private final String label; | |
33 | |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8999
diff
changeset
|
34 public AbstractCalculationResult(final String label, final Collection<ResultRow> rows) { |
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8999
diff
changeset
|
35 this.label = label; |
8999 | 36 this.rows = new ArrayList<>(rows); |
37 } | |
38 | |
39 public final String getLabel() { | |
40 return this.label; | |
41 } | |
42 | |
43 public boolean isEmpty() { | |
44 return this.rows.isEmpty(); | |
45 } | |
46 | |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9150
diff
changeset
|
47 public Collection<ResultRow> getRows() { |
8999 | 48 return Collections.unmodifiableCollection(this.rows); |
49 } | |
50 | |
9265 | 51 public final double[][] getStationPoints(final IResultType yType) { |
52 return getPoints(GeneralResultType.station, yType, TruePredicate.INSTANCE); | |
53 } | |
54 | |
9425
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
55 /** |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
56 * Return the row with the given station (within the given tolerance) by linear search. |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
57 * Returns <code>null</code>, if no such station was found. |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
58 */ |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
59 protected final ResultRow getRowForStation(final double searchStation, final double stationTolerance) { |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
60 |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
61 for (final ResultRow row : this.rows) { |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
62 final double station = row.getDoubleValue(GeneralResultType.station); |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
63 if (Math.abs(station - searchStation) < stationTolerance) |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
64 return row; |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
65 } |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
66 |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
67 return null; |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
68 } |
3f49835a00c3
Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents:
9265
diff
changeset
|
69 |
9265 | 70 public final double[][] getPoints(final IResultType typeX, final IResultType typeY, final Predicate rowFilter) { |
8999 | 71 |
72 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | |
73 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
74 | |
75 for (final ResultRow row : this.rows) { | |
76 | |
9265 | 77 if (rowFilter.evaluate(row)) { |
78 final double station = row.getDoubleValue(typeX); | |
79 final double value = row.getDoubleValue(typeY); | |
8999 | 80 |
9265 | 81 xPoints.add(station); |
82 yPoints.add(value); | |
83 } | |
8999 | 84 } |
85 | |
86 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | |
87 } | |
88 | |
89 protected final <TYPE> List<TYPE> getValues(final IResultType type) { | |
90 | |
91 final List<TYPE> values = new ArrayList<>(); | |
92 | |
93 for (final ResultRow row : this.rows) { | |
94 @SuppressWarnings("unchecked") | |
95 final TYPE value = (TYPE) row.getValue(type); | |
96 values.add(value); | |
97 } | |
98 | |
99 return values; | |
100 } | |
101 } |