Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 655:913b52064449
Refactored version of "Berechnung 4"
flys-artifacts/trunk@2053 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 05 Jun 2011 18:24:46 +0000 |
parents | 6695e03e9b82 |
children | ed7c901ee712 |
comparison
equal
deleted
inserted
replaced
654:bbc966c81809 | 655:913b52064449 |
---|---|
31 import de.intevation.artifactdatabase.data.StateData; | 31 import de.intevation.artifactdatabase.data.StateData; |
32 import de.intevation.artifactdatabase.state.State; | 32 import de.intevation.artifactdatabase.state.State; |
33 import de.intevation.artifactdatabase.state.StateEngine; | 33 import de.intevation.artifactdatabase.state.StateEngine; |
34 import de.intevation.artifactdatabase.transition.TransitionEngine; | 34 import de.intevation.artifactdatabase.transition.TransitionEngine; |
35 | 35 |
36 import de.intevation.flys.utils.DoubleUtil; | |
37 | |
36 import de.intevation.flys.model.Gauge; | 38 import de.intevation.flys.model.Gauge; |
37 import de.intevation.flys.model.Range; | 39 import de.intevation.flys.model.Range; |
38 import de.intevation.flys.model.River; | 40 import de.intevation.flys.model.River; |
39 | 41 |
40 import de.intevation.flys.artifacts.context.FLYSContext; | 42 import de.intevation.flys.artifacts.context.FLYSContext; |
76 * range.*/ | 78 * range.*/ |
77 public static final int DEFAULT_Q_STEPS = 30; | 79 public static final int DEFAULT_Q_STEPS = 30; |
78 | 80 |
79 /** The default step width between the start end end kilometer.*/ | 81 /** The default step width between the start end end kilometer.*/ |
80 public static final double DEFAULT_KM_STEPS = 0.1; | 82 public static final double DEFAULT_KM_STEPS = 0.1; |
81 | |
82 public static final double DEFAULT_PRECISION = 1e6; | |
83 | 83 |
84 | 84 |
85 /** The identifier of the current state. */ | 85 /** The identifier of the current state. */ |
86 protected String currentStateId; | 86 protected String currentStateId; |
87 | 87 |
609 else { | 609 else { |
610 return LocationDistanceSelect.getLocations(this); | 610 return LocationDistanceSelect.getLocations(this); |
611 } | 611 } |
612 } | 612 } |
613 | 613 |
614 public double [] getFromToStep() { | |
615 if (!isRange()) { | |
616 return null; | |
617 } | |
618 double [] fromTo = getDistance(); | |
619 | |
620 if (fromTo == null) { | |
621 return null; | |
622 } | |
623 | |
624 StateData dStep = getData("ld_step"); | |
625 if (dStep == null) { | |
626 return null; | |
627 } | |
628 | |
629 double [] result = new double[3]; | |
630 result[0] = fromTo[0]; | |
631 result[1] = fromTo[1]; | |
632 | |
633 try { | |
634 String step = (String)dStep.getValue(); | |
635 result[2] = DoubleUtil.round(Double.parseDouble(step) / 1000d); | |
636 } | |
637 catch (NumberFormatException nfe) { | |
638 return null; | |
639 } | |
640 | |
641 return result; | |
642 } | |
643 | |
614 | 644 |
615 /** | 645 /** |
616 * Returns the gauge based on the current distance and river. | 646 * Returns the gauge based on the current distance and river. |
617 * | 647 * |
618 * @return the gauge. | 648 * @return the gauge. |
965 public static double[] getExplodedValues( | 995 public static double[] getExplodedValues( |
966 double from, | 996 double from, |
967 double to, | 997 double to, |
968 double step | 998 double step |
969 ) { | 999 ) { |
970 return getExplodedValues(from, to, step, DEFAULT_PRECISION); | 1000 return DoubleUtil.explode(from, to, step); |
971 } | 1001 } |
972 | |
973 public static double[] getExplodedValues( | |
974 double from, | |
975 double to, | |
976 double step, | |
977 double precision | |
978 ) { | |
979 double lower = from; | |
980 | |
981 double diff = to - from; | |
982 double tmp = diff / step; | |
983 int num = (int)Math.abs(Math.ceil(tmp)) + 1; | |
984 | |
985 double [] values = new double[num]; | |
986 | |
987 if (from > to) { | |
988 step = -step; | |
989 } | |
990 | |
991 for (int idx = 0; idx < num; idx++) { | |
992 values[idx] = Math.round(lower * precision)/precision; | |
993 lower += step; | |
994 } | |
995 | |
996 return values; | |
997 } | |
998 | |
999 | 1002 |
1000 /** | 1003 /** |
1001 * Method to dump the artifacts state/data. | 1004 * Method to dump the artifacts state/data. |
1002 */ | 1005 */ |
1003 protected void dumpArtifact() { | 1006 protected void dumpArtifact() { |