Mercurial > dive4elements > river
changeset 9400:8e100593aec3
Missing class added
author | mschaefer |
---|---|
date | Tue, 14 Aug 2018 11:06:00 +0200 |
parents | 77367e8da74d |
children | 361de818f76e |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsUtils.java |
diffstat | 1 files changed, 92 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsUtils.java Tue Aug 14 11:06:00 2018 +0200 @@ -0,0 +1,92 @@ +/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde + * Software engineering by + * Björnsen Beratende Ingenieure GmbH + * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ +package org.dive4elements.river.artifacts.sinfo.tkhstate; + +import java.util.Collection; +import java.util.TreeSet; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.math.DoubleRange; + +/** + * Helper functions for bed height calculations + */ +public final class BedHeightsUtils { + + /** + * Get a union of all stations in a collection of bed heights + */ + public static double[] extractStations(final Collection<BedHeightsFinder> bedHeightFinders) { + + return extractStations(bedHeightFinders, false); + } + + /** + * Get a union of all stations in a collection of bed heights + */ + public static double[] extractStations(final Collection<BedHeightsFinder> bedHeightFinders, final boolean minMaxAware) { + + final Collection<Double> allStations = extractStationCollection(bedHeightFinders, minMaxAware); + return ArrayUtils.toPrimitive(allStations.toArray(new Double[allStations.size()])); + } + + /** + * Get a union of all stations in a collection of bed heights + */ + public static Collection<Double> extractStationCollection(final Collection<BedHeightsFinder> bedHeightFinders, final boolean minMaxAware) { + + if (!minMaxAware) + return extractStationCollection(bedHeightFinders); + + final DoubleRange kmRange = extractMinimumStationRange(bedHeightFinders); + + final Collection<Double> allStations = new TreeSet<>(); + for (final BedHeightsFinder bhf : bedHeightFinders) { + for (final Double station : bhf.getStations()) + if ((station.doubleValue() >= kmRange.getMinimumDouble() - 0.0001) && (station.doubleValue() <= kmRange.getMaximumDouble() + 0.0001)) + allStations.add(station.doubleValue()); + } + return allStations; + } + + /** + * Get a union of all stations in a collection of bed heights + */ + public static Collection<Double> extractStationCollection(final Collection<BedHeightsFinder> bedHeights) { + + final Collection<Double> allStations = new TreeSet<>(); + + for (final BedHeightsFinder bedHeight : bedHeights) + allStations.addAll(bedHeight.getStations()); + + return allStations; + } + + /** + * Intersects all km ranges of a collection of bed heights + */ + public static DoubleRange extractMinimumStationRange(final Collection<BedHeightsFinder> bedHeightFinders) { + DoubleRange kmRange = null; + for (final BedHeightsFinder bhf : bedHeightFinders) + kmRange = intersectRanges(kmRange, bhf.getKmRange()); + return new DoubleRange(kmRange.getMinimumDouble() - 0.0001, kmRange.getMaximumDouble() + 0.0001); + } + + /** + * Creates a range with the minimum overlapping of two ranges + */ + public static DoubleRange intersectRanges(final DoubleRange a, final DoubleRange b) { + if (a == null) + return new DoubleRange(b.getMinimumDouble(), b.getMaximumDouble()); + if (b == null) + return new DoubleRange(a.getMinimumDouble(), a.getMaximumDouble()); + return new DoubleRange(Math.max(a.getMinimumDouble(), b.getMinimumDouble()), Math.min(a.getMaximumDouble(), b.getMaximumDouble())); + } +}