comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffCalculation.java @ 8647:5f60bd7c4b42

(issue1754) Simplify code to handle a>b cases.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 30 Mar 2015 19:28:41 +0200
parents 1f6b30310360
children 5e38e2924c07
comparison
equal deleted inserted replaced
8646:8e5c026216fd 8647:5f60bd7c4b42
35 public CalculationResult calculate(BedDifferencesAccess access, CallContext context) { 35 public CalculationResult calculate(BedDifferencesAccess access, CallContext context) {
36 log.info("BedDiffCalculation.calculate"); 36 log.info("BedDiffCalculation.calculate");
37 37
38 this.river = access.getRiverName(); 38 this.river = access.getRiverName();
39 this.heightIds = access.extractHeightIds(context); 39 this.heightIds = access.extractHeightIds(context);
40 double from = access.getFrom(); 40 double from = access.getFrom(true);
41 double to = access.getTo(); 41 double to = access.getTo(true);
42 double start;
43 double end;
44
45 if ((!Double.isNaN(from) && !Double.isNaN(to)) && from > to) {
46 log.debug("Reordering range.");
47 start = to;
48 end = from;
49 } else {
50 start = from;
51 end = to;
52 }
53 42
54 BedDiffYearResult [] results = new BedDiffYearResult[heightIds.length]; 43 BedDiffYearResult [] results = new BedDiffYearResult[heightIds.length];
55 for (int i = 0; i < heightIds.length; i++) { 44 for (int i = 0; i < heightIds.length; i++) {
56 BedHeightData [] pair = getHeightPair(heightIds[i], start, end); 45 BedHeightData [] pair = getHeightPair(heightIds[i], from, to);
57 if (pair[0].getYear() == null || pair[1].getYear() == null) { 46 if (pair[0].getYear() == null || pair[1].getYear() == null) {
58 addProblem("beddiff.missing.year"); 47 addProblem("beddiff.missing.year");
59 } 48 }
60 results[i] = calculateYearDifference(pair, heightIds[i]); 49 results[i] = calculateYearDifference(pair, heightIds[i]);
61 } 50 }

http://dive4elements.wald.intevation.org