Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractCalculationResult.java @ 8999:e3b3ce32c825
Work on uinfo
author | gernotbelger |
---|---|
date | Thu, 12 Apr 2018 19:15:42 +0200 |
parents | |
children | 23945061daec |
comparison
equal
deleted
inserted
replaced
8998:c38098b15427 | 8999:e3b3ce32c825 |
---|---|
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 | |
18 import org.dive4elements.river.artifacts.common.IResultType; | |
19 import gnu.trove.TDoubleArrayList; | |
20 | |
21 /** | |
22 * @author Gernot Belger | |
23 */ | |
24 public abstract class AbstractCalculationResult implements Serializable { | |
25 | |
26 private static final long serialVersionUID = 1L; | |
27 | |
28 protected final Collection<ResultRow> rows; | |
29 | |
30 private final String label; | |
31 | |
32 | |
33 | |
34 public AbstractCalculationResult(final String label, final Collection<ResultRow> rows) { | |
35 this.label = label; | |
36 this.rows = new ArrayList<>(rows); | |
37 } | |
38 | |
39 public final String getLabel() { | |
40 return this.label; | |
41 } | |
42 | |
43 | |
44 public boolean isEmpty() { | |
45 return this.rows.isEmpty(); | |
46 } | |
47 | |
48 public final void addRow(final ResultRow resultRow) { | |
49 this.rows.add(resultRow); | |
50 } | |
51 | |
52 public final Collection<ResultRow> getRows() { | |
53 return Collections.unmodifiableCollection(this.rows); | |
54 } | |
55 | |
56 public final double[][] getStationPoints(final IResultType type) { //gehört die Methode hier rein? oder in erbende Klassen? | |
57 | |
58 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | |
59 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
60 | |
61 for (final ResultRow row : this.rows) { | |
62 | |
63 final double station = row.getDoubleValue(GeneralResultType.station); //TODO: move "station" (and others) to common | |
64 final double value = row.getDoubleValue(type); | |
65 | |
66 xPoints.add(station); | |
67 yPoints.add(value); | |
68 } | |
69 | |
70 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | |
71 } | |
72 | |
73 protected final <TYPE> List<TYPE> getValues(final IResultType type) { | |
74 | |
75 final List<TYPE> values = new ArrayList<>(); | |
76 | |
77 for (final ResultRow row : this.rows) { | |
78 @SuppressWarnings("unchecked") | |
79 final TYPE value = (TYPE) row.getValue(type); | |
80 values.add(value); | |
81 } | |
82 | |
83 return values; | |
84 } | |
85 } |