[PATCH] SedimentLoadCalculation: Refactoring, extracted method
Wald Commits
scm-commit at wald.intevation.org
Tue Aug 27 15:26:56 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1377608283 -7200
# Node ID 2119f13f95ab05c268a82c2d4d04159655c57e9d
# Parent 0288db5e90d587d861f3272954020e3080d6ce1b
SedimentLoadCalculation: Refactoring, extracted method.
diff -r 0288db5e90d5 -r 2119f13f95ab artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java Tue Aug 27 12:46:11 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java Tue Aug 27 14:58:03 2013 +0200
@@ -125,6 +125,76 @@
return null;
}
+ private void calculateEpochKm(
+ List<SedimentLoad> epochLoads,
+ SedimentLoad resLoad,
+ double km
+ ) {
+ int cSum = 0;
+ int fmSum = 0;
+ int sSum = 0;
+ int ssSum = 0;
+ int ssbSum = 0;
+ int sseSum = 0;
+ for (SedimentLoad load : epochLoads) {
+ SedimentLoadFraction f = load.getFraction(km);
+ if (f.getCoarse() > 0d) {
+ double c = resLoad.getFraction(km).getCoarse();
+ resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange());
+ cSum++;
+ }
+ if (f.getFineMiddle() > 0d) {
+ double fm = resLoad.getFraction(km).getFineMiddle();
+ resLoad.setFineMiddle(km, fm + f.getFineMiddle(), f.getFineMiddleRange());
+ fmSum++;
+ }
+ if (f.getSand() > 0d) {
+ double s = resLoad.getFraction(km).getSand();
+ resLoad.setSand(km, s + f.getSand(), f.getSandRange());
+ sSum++;
+ }
+ if (f.getSuspSand() > 0d) {
+ double s = resLoad.getFraction(km).getSuspSand();
+ resLoad.setSuspSand(km, s + f.getSuspSand(), f.getSuspSandRange());
+ ssSum++;
+ }
+ if (f.getSuspSandBed() > 0d) {
+ double s = resLoad.getFraction(km).getSuspSandBed();
+ resLoad.setSuspSandBed(km, s + f.getSuspSandBed(), f.getSuspSandBedRange());
+ ssbSum++;
+ }
+ if (f.getSuspSediment() > 0d) {
+ double s = resLoad.getFraction(km).getSuspSediment();
+ resLoad.setSuspSediment(km, s + f.getSuspSediment(), f.getSuspSedimentRange());
+ sseSum++;
+ }
+ }
+
+ SedimentLoadFraction fr = resLoad.getFraction(km);
+ // Prevent divisions by zero, the fraction defaults to 0d.
+ if (cSum != 0) {
+ resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
+ }
+ if (fmSum != 0) {
+ resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum,
+ fr.getFineMiddleRange());
+ }
+ if (sSum != 0) {
+ resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
+ }
+ if (ssSum != 0) {
+ resLoad.setSuspSand(km, fr.getSuspSand()/ssSum,
+ fr.getSuspSandRange());
+ }
+ if (ssbSum != 0) {
+ resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum,
+ fr.getSuspSandBedRange());
+ }
+ if (sseSum != 0) {
+ resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
+ }
+ }
+
private SedimentLoadResult calculateEpoch(int i) {
List<SedimentLoad> epochLoads = new ArrayList<SedimentLoad>();
for (int j = epoch[i][0]; j < epoch[i][1]; j++) {
@@ -149,69 +219,7 @@
}
for (int j = 0; j < kms.size(); j++) {
- int cSum = 0;
- int fmSum = 0;
- int sSum = 0;
- int ssSum = 0;
- int ssbSum = 0;
- int sseSum = 0;
- double km = kms.get(j);
- for (SedimentLoad load : epochLoads) {
- SedimentLoadFraction f = load.getFraction(km);
- if (f.getCoarse() > 0d) {
- double c = resLoad.getFraction(km).getCoarse();
- resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange());
- cSum++;
- }
- if (f.getFineMiddle() > 0d) {
- double fm = resLoad.getFraction(km).getFineMiddle();
- resLoad.setFineMiddle(km, fm + f.getFineMiddle(), f.getFineMiddleRange());
- fmSum++;
- }
- if (f.getSand() > 0d) {
- double s = resLoad.getFraction(km).getSand();
- resLoad.setSand(km, s + f.getSand(), f.getSandRange());
- sSum++;
- }
- if (f.getSuspSand() > 0d) {
- double s = resLoad.getFraction(km).getSuspSand();
- resLoad.setSuspSand(km, s + f.getSuspSand(), f.getSuspSandRange());
- ssSum++;
- }
- if (f.getSuspSandBed() > 0d) {
- double s = resLoad.getFraction(km).getSuspSandBed();
- resLoad.setSuspSandBed(km, s + f.getSuspSandBed(), f.getSuspSandBedRange());
- ssbSum++;
- }
- if (f.getSuspSediment() > 0d) {
- double s = resLoad.getFraction(km).getSuspSediment();
- resLoad.setSuspSediment(km, s + f.getSuspSediment(), f.getSuspSedimentRange());
- sseSum++;
- }
- }
- SedimentLoadFraction fr = resLoad.getFraction(km);
- // Prevent divisions by zero, the fraction defaults to 0d.
- if (cSum != 0) {
- resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
- }
- if (fmSum != 0) {
- resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum,
- fr.getFineMiddleRange());
- }
- if (sSum != 0) {
- resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
- }
- if (ssSum != 0) {
- resLoad.setSuspSand(km, fr.getSuspSand()/ssSum,
- fr.getSuspSandRange());
- }
- if (ssbSum != 0) {
- resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum,
- fr.getSuspSandBedRange());
- }
- if (sseSum != 0) {
- resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
- }
+ calculateEpochKm(epochLoads, resLoad, kms.get(j));
}
resLoad.setDescription("");
resLoad.setEpoch(true);
More information about the Dive4elements-commits
mailing list