9400
|
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 /** |
9573
|
19 * Helper functions for bed level calculations |
9400
|
20 */ |
|
21 public final class BedHeightsUtils { |
|
22 |
|
23 /** |
9573
|
24 * Get a union of all stations in a collection of bed levels |
9400
|
25 */ |
|
26 public static double[] extractStations(final Collection<BedHeightsFinder> bedHeightFinders) { |
|
27 |
|
28 return extractStations(bedHeightFinders, false); |
|
29 } |
|
30 |
|
31 /** |
9573
|
32 * Get a union of all stations in a collection of bed levels |
9400
|
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 /** |
9573
|
41 * Get a union of all stations in a collection of bed levels |
9400
|
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 /** |
9573
|
60 * Get a union of all stations in a collection of bed levels |
9400
|
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 /** |
9573
|
73 * Intersects all km ranges of a collection of bed levels |
9400
|
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 } |