Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractTkhCalculationResult.java @ 8948:a4f1ac81f26d
Work on SINFO-FlowDepthMinMax.
Also rework of result row stuff, in order to reduce abstraction, using result type concept
author | gernotbelger |
---|---|
date | Wed, 14 Mar 2018 14:10:32 +0100 |
parents | 5d5d482da3e9 |
children | 50cc99579a46 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractTkhCalculationResult.java Wed Mar 14 14:09:33 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractTkhCalculationResult.java Wed Mar 14 14:10:32 2018 +0100 @@ -9,7 +9,6 @@ */ package org.dive4elements.river.artifacts.sinfo.common; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -21,14 +20,15 @@ /** * @author Gernot Belger */ -public abstract class AbstractTkhCalculationResult<ROW extends AbstractTkhResultRow> extends AbstractSInfoCalculationResult<ROW> { +public abstract class AbstractTkhCalculationResult extends AbstractSInfoCalculationResult { private static final long serialVersionUID = 1L; private final boolean hasTkh; - public AbstractTkhCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ROW> rows) { + public AbstractTkhCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<SInfoResultRow> rows) { super(label, wst, rows); + this.hasTkh = hasTkh; } @@ -36,138 +36,51 @@ return this.hasTkh; } - public double[][] getFlowDepthPoints() { - - final Collection<ROW> rows = getRows(); - - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getFlowDepth()); - } - - return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; - } - - public double[][] getFlowDepthTkhPoints() { - - final Collection<ROW> rows = getRows(); - - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getFlowDepthWithTkh()); - } - - return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; - } - public final double[][] getTkhUpPoints() { - final Collection<ROW> rows = getRows(); + final double[][] points = getStationPoints(SInfoResultType.tkhup); + final List<SoilKind> kinds = getValues(SInfoResultType.soilkind); - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - final List<SoilKind> kinds = new ArrayList<>(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getTkhUp()); - kinds.add(row.getTkhKind()); - } + final double[] xPoints = points[0]; + final double[] yPoints = points[1]; return adjustTkhVisualization(xPoints, yPoints, kinds); } public final double[][] getTkhDownPoints() { - final Collection<ROW> rows = getRows(); + final double[][] points = getStationPoints(SInfoResultType.tkhdown); + final List<SoilKind> kinds = getValues(SInfoResultType.soilkind); - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - final List<SoilKind> kinds = new ArrayList<>(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getTkhDown()); - kinds.add(row.getTkhKind()); - } + final double[] xPoints = points[0]; + final double[] yPoints = points[1]; return adjustTkhVisualization(xPoints, yPoints, kinds); } - public double[][] getVelocityPoints() { - - final Collection<ROW> rows = getRows(); - - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getVelocity()); - } - - return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; - } - - public double[][] getD50Points() { - - final Collection<ROW> rows = getRows(); - - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getD50()); - } - - return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; - } - - public double[][] getTauPoints() { - - final Collection<ROW> rows = getRows(); - - final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); - - for (final ROW row : rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getTau()); - } - - return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; - } - /** * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case */ - private double[][] adjustTkhVisualization(final TDoubleArrayList xPoints, final TDoubleArrayList yPoints, final List<SoilKind> kinds) { + private double[][] adjustTkhVisualization(final double[] xPoints, final double[] yPoints, final List<SoilKind> kinds) { - final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.size()); - final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.size()); + final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.length); + final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.length); - adjustedX.add(xPoints.get(0)); - adjustedY.add(yPoints.get(0)); + adjustedX.add(xPoints[0]); + adjustedY.add(yPoints[0]); - for (int i = 1; i < xPoints.size(); i++) { + for (int i = 1; i < xPoints.length; i++) { final SoilKind kind1 = kinds.get(i - 1); final SoilKind kind2 = kinds.get(i); if (kind1 != kind2) { /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */ - final double x1 = xPoints.get(i - 1); - final double y1 = yPoints.get(i - 1); - final double x2 = xPoints.get(i); - final double y2 = yPoints.get(i); + final double x1 = xPoints[i - 1]; + final double y1 = yPoints[i - 1]; + final double x2 = xPoints[i]; + final double y2 = yPoints[i]; final double middleX = (x1 + x2) / 2; @@ -180,8 +93,8 @@ } /* always add the real point now */ - adjustedX.add(xPoints.get(i)); - adjustedY.add(yPoints.get(i)); + adjustedX.add(xPoints[i]); + adjustedY.add(yPoints[i]); } return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() };