comparison artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java @ 9132:8cc192731c7d

WQSelect can now handle distance-only data
author gernotbelger
date Wed, 06 Jun 2018 14:24:51 +0200
parents 850ce16034e9
children
comparison
equal deleted inserted replaced
9131:0a19a79663dd 9132:8cc192731c7d
21 // TODO employ 'Caching' like other Accesses, remove usage of RiverUtils. 21 // TODO employ 'Caching' like other Accesses, remove usage of RiverUtils.
22 public class RangeAccess extends RiverAccess { 22 public class RangeAccess extends RiverAccess {
23 private static Logger log = Logger.getLogger(RangeAccess.class); 23 private static Logger log = Logger.getLogger(RangeAccess.class);
24 24
25 public static enum KM_MODE { 25 public static enum KM_MODE {
26 RANGE, LOCATIONS, NONE 26 RANGE, LOCATIONS, NONE, DISTANCE_ONLY
27 }; 27 }
28 28
29 /** The default step width between the start end end kilometer. */ 29 /** The default step width between the start end end kilometer. */
30 public static final double DEFAULT_KM_STEPS = 0.1; 30 public static final double DEFAULT_KM_STEPS = 0.1;
31 31
32 double[] kmRange; 32 private Double from;
33 33
34 Double from; 34 private Double to;
35 35
36 Double to; 36 private Double step;
37
38 Double step;
39 37
40 private KM_MODE mode; 38 private KM_MODE mode;
41
42 public RangeAccess() {
43 }
44 39
45 public RangeAccess(final D4EArtifact artifact) { 40 public RangeAccess(final D4EArtifact artifact) {
46 super(artifact); 41 super(artifact);
47 } 42 }
48 43
49 /** Evaluate the ld_mode data of artifact. */ 44 /** Evaluate the ld_mode data of artifact. */
50 public KM_MODE getKmRangeMode() { 45 public KM_MODE getKmRangeMode() {
51 if (this.mode != null) { 46 if (this.mode != null)
52 return this.mode; 47 return this.mode;
53 } 48
54 final String modeData = getString("ld_mode"); 49 final String modeData = getString("ld_mode");
55 50 this.mode = parseRangeMode(modeData);
56 if (modeData == null || modeData.length() == 0) {
57 this.mode = KM_MODE.NONE;
58 } else if (modeData.equals("distance")) {
59 this.mode = KM_MODE.RANGE;
60 } else if (modeData.equals("locations")) {
61 this.mode = KM_MODE.LOCATIONS;
62 } else {
63 this.mode = KM_MODE.NONE;
64 }
65 51
66 return this.mode; 52 return this.mode;
53 }
54
55 private KM_MODE parseRangeMode(final String modeData) {
56
57 if (modeData == null)
58 return KM_MODE.NONE;
59
60 switch (modeData) {
61 case "distance":
62 return KM_MODE.RANGE;
63
64 case "distance_only":
65 return KM_MODE.DISTANCE_ONLY;
66
67 case "locations":
68 return KM_MODE.LOCATIONS;
69
70 default:
71 return KM_MODE.NONE;
72 }
67 } 73 }
68 74
69 public final DoubleRange getRange() { 75 public final DoubleRange getRange() {
70 final double from = getFrom(); 76 final double from = getFrom();
71 final double to = getTo(); 77 final double to = getTo();
202 * (ld_from/to vs ld_locations). 208 * (ld_from/to vs ld_locations).
203 */ 209 */
204 public double[] getKmRange() { 210 public double[] getKmRange() {
205 // TODO store kmRange in field. 211 // TODO store kmRange in field.
206 switch (getKmRangeMode()) { 212 switch (getKmRangeMode()) {
207 case RANGE: { 213 case RANGE:
214 case DISTANCE_ONLY:
208 return getKmFromTo(); 215 return getKmFromTo();
209 }
210 216
211 case LOCATIONS: { 217 case LOCATIONS: {
212 final double[] locs = getLocations(); 218 final double[] locs = getLocations();
213 // if no locations, nPE. 219 // if no locations, nPE.
214 if (locs == null) { 220 if (locs == null) {

http://dive4elements.wald.intevation.org