Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResult.java @ 9265:e5367900dd6d
Small cleanup concerning getPoints
Adding validStations as dataItem to flood duration calculation
Flood duration now km aware
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 19:48:28 +0200 |
parents | 3dae6b78e1da |
children | 3f49835a00c3 |
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 | |
55 public final double[][] getPoints(final IResultType typeX, final IResultType typeY, final Predicate rowFilter) { | |
8999 | 56 |
57 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | |
58 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
59 | |
60 for (final ResultRow row : this.rows) { | |
61 | |
9265 | 62 if (rowFilter.evaluate(row)) { |
63 final double station = row.getDoubleValue(typeX); | |
64 final double value = row.getDoubleValue(typeY); | |
8999 | 65 |
9265 | 66 xPoints.add(station); |
67 yPoints.add(value); | |
68 } | |
8999 | 69 } |
70 | |
71 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | |
72 } | |
73 | |
74 protected final <TYPE> List<TYPE> getValues(final IResultType type) { | |
75 | |
76 final List<TYPE> values = new ArrayList<>(); | |
77 | |
78 for (final ResultRow row : this.rows) { | |
79 @SuppressWarnings("unchecked") | |
80 final TYPE value = (TYPE) row.getValue(type); | |
81 values.add(value); | |
82 } | |
83 | |
84 return values; | |
85 } | |
86 } |