Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsUtils.java @ 9400:8e100593aec3
Missing class added
author | mschaefer |
---|---|
date | Tue, 14 Aug 2018 11:06:00 +0200 |
parents | |
children | b9c87bbff6a4 |
comparison
equal
deleted
inserted
replaced
9399:77367e8da74d | 9400:8e100593aec3 |
---|---|
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.sinfo.tkhstate; | |
11 | |
12 import java.util.Collection; | |
13 import java.util.TreeSet; | |
14 | |
15 import org.apache.commons.lang.ArrayUtils; | |
16 import org.apache.commons.lang.math.DoubleRange; | |
17 | |
18 /** | |
19 * Helper functions for bed height calculations | |
20 */ | |
21 public final class BedHeightsUtils { | |
22 | |
23 /** | |
24 * Get a union of all stations in a collection of bed heights | |
25 */ | |
26 public static double[] extractStations(final Collection<BedHeightsFinder> bedHeightFinders) { | |
27 | |
28 return extractStations(bedHeightFinders, false); | |
29 } | |
30 | |
31 /** | |
32 * Get a union of all stations in a collection of bed heights | |
33 */ | |
34 public static double[] extractStations(final Collection<BedHeightsFinder> bedHeightFinders, final boolean minMaxAware) { | |
35 | |
36 final Collection<Double> allStations = extractStationCollection(bedHeightFinders, minMaxAware); | |
37 return ArrayUtils.toPrimitive(allStations.toArray(new Double[allStations.size()])); | |
38 } | |
39 | |
40 /** | |
41 * Get a union of all stations in a collection of bed heights | |
42 */ | |
43 public static Collection<Double> extractStationCollection(final Collection<BedHeightsFinder> bedHeightFinders, final boolean minMaxAware) { | |
44 | |
45 if (!minMaxAware) | |
46 return extractStationCollection(bedHeightFinders); | |
47 | |
48 final DoubleRange kmRange = extractMinimumStationRange(bedHeightFinders); | |
49 | |
50 final Collection<Double> allStations = new TreeSet<>(); | |
51 for (final BedHeightsFinder bhf : bedHeightFinders) { | |
52 for (final Double station : bhf.getStations()) | |
53 if ((station.doubleValue() >= kmRange.getMinimumDouble() - 0.0001) && (station.doubleValue() <= kmRange.getMaximumDouble() + 0.0001)) | |
54 allStations.add(station.doubleValue()); | |
55 } | |
56 return allStations; | |
57 } | |
58 | |
59 /** | |
60 * Get a union of all stations in a collection of bed heights | |
61 */ | |
62 public static Collection<Double> extractStationCollection(final Collection<BedHeightsFinder> bedHeights) { | |
63 | |
64 final Collection<Double> allStations = new TreeSet<>(); | |
65 | |
66 for (final BedHeightsFinder bedHeight : bedHeights) | |
67 allStations.addAll(bedHeight.getStations()); | |
68 | |
69 return allStations; | |
70 } | |
71 | |
72 /** | |
73 * Intersects all km ranges of a collection of bed heights | |
74 */ | |
75 public static DoubleRange extractMinimumStationRange(final Collection<BedHeightsFinder> bedHeightFinders) { | |
76 DoubleRange kmRange = null; | |
77 for (final BedHeightsFinder bhf : bedHeightFinders) | |
78 kmRange = intersectRanges(kmRange, bhf.getKmRange()); | |
79 return new DoubleRange(kmRange.getMinimumDouble() - 0.0001, kmRange.getMaximumDouble() + 0.0001); | |
80 } | |
81 | |
82 /** | |
83 * Creates a range with the minimum overlapping of two ranges | |
84 */ | |
85 public static DoubleRange intersectRanges(final DoubleRange a, final DoubleRange b) { | |
86 if (a == null) | |
87 return new DoubleRange(b.getMinimumDouble(), b.getMaximumDouble()); | |
88 if (b == null) | |
89 return new DoubleRange(a.getMinimumDouble(), a.getMaximumDouble()); | |
90 return new DoubleRange(Math.max(a.getMinimumDouble(), b.getMinimumDouble()), Math.min(a.getMaximumDouble(), b.getMaximumDouble())); | |
91 } | |
92 } |