Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityPeriodsSelect.java @ 8625:362abb64e897
Add default value to BedQuality period selection
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 26 Mar 2015 11:51:47 +0100 |
parents | e4606eae8ea5 |
children | 5a5331dd3e8d |
comparison
equal
deleted
inserted
replaced
8624:4f702ea1fd3a | 8625:362abb64e897 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states.minfo; | 9 package org.dive4elements.river.artifacts.states.minfo; |
10 | 10 |
11 import java.util.List; | |
12 import java.util.Date; | |
13 import java.util.TreeSet; | |
14 | |
11 import org.apache.log4j.Logger; | 15 import org.apache.log4j.Logger; |
12 | 16 |
13 import org.dive4elements.river.artifacts.states.DefaultState; | 17 import org.dive4elements.river.artifacts.states.DefaultState; |
18 | |
19 import org.w3c.dom.Element; | |
20 | |
21 import org.dive4elements.river.artifacts.access.RangeAccess; | |
22 import org.dive4elements.river.artifacts.D4EArtifact; | |
23 import org.dive4elements.river.artifacts.model.minfo.BedOverview; | |
24 import org.dive4elements.river.artifacts.model.minfo.BedOverviewFactory; | |
25 import org.dive4elements.river.artifacts.model.minfo.BedloadOverview; | |
26 import org.dive4elements.river.artifacts.model.minfo.BedloadOverviewFactory; | |
27 | |
28 import org.dive4elements.river.utils.KMIndex; | |
29 | |
30 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
31 import org.dive4elements.artifacts.Artifact; | |
32 import org.dive4elements.artifacts.CallContext; | |
33 | |
34 import org.dive4elements.artifactdatabase.data.StateData; | |
35 | |
14 | 36 |
15 public class BedQualityPeriodsSelect extends DefaultState { | 37 public class BedQualityPeriodsSelect extends DefaultState { |
16 | 38 |
17 /** The log used in this class. */ | 39 /** The log used in this class. */ |
18 private static Logger log = Logger.getLogger(BedQualityPeriodsSelect.class); | 40 private static Logger log = Logger.getLogger(BedQualityPeriodsSelect.class); |
22 * The default constructor that initializes an empty State object. | 44 * The default constructor that initializes an empty State object. |
23 */ | 45 */ |
24 public BedQualityPeriodsSelect() { | 46 public BedQualityPeriodsSelect() { |
25 } | 47 } |
26 | 48 |
49 /** Get either the start and end date of the data at the current position. */ | |
50 protected Long[] getDataMinMaxDate(Artifact artifact) { | |
51 D4EArtifact arti = (D4EArtifact) artifact; | |
52 RangeAccess access = new RangeAccess(arti); | |
53 double a = access.getFrom(); | |
54 double b = access.getTo(); | |
55 | |
56 if (a > b) { | |
57 double buf = a; | |
58 a = b; | |
59 b = buf; | |
60 } | |
61 | |
62 BedOverview overview = BedOverviewFactory.getOverview(access.getRiverName()); | |
63 BedloadOverview overview2 = BedloadOverviewFactory.getOverview(access.getRiverName()); | |
64 | |
65 /* Filter is not implemented and only checks if a complete | |
66 * KMIndex list is acceptable or not. So KMFiltering wont work */ | |
67 KMIndex<List<Date>> entries = overview.filter(BedOverview.ACCEPT); | |
68 KMIndex<List<Date>> loads = overview2.filter(BedloadOverview.ACCEPT); | |
69 TreeSet<Date> allDates = new TreeSet<Date>(); | |
70 | |
71 for (int i = 0; i < entries.size(); i++) { | |
72 if (entries.get(i).getKm() >= a && entries.get(i).getKm() <= b) { | |
73 allDates.addAll(entries.get(i).getValue()); | |
74 } | |
75 } | |
76 for (int i = 0; i < loads.size(); i++) { | |
77 if (loads.get(i).getKm() >= a && loads.get(i).getKm() <= b) { | |
78 allDates.addAll(loads.get(i).getValue()); | |
79 } | |
80 } | |
81 if (allDates.size() < 2) { | |
82 return null; | |
83 } | |
84 | |
85 return new Long[] {allDates.first().getTime(), | |
86 allDates.last().getTime()}; | |
87 } | |
88 | |
89 @Override | |
90 protected Element[] createItems( | |
91 XMLUtils.ElementCreator cr, | |
92 Artifact artifact, | |
93 String name, | |
94 CallContext context) | |
95 { | |
96 if (!name.equals("periods")) { | |
97 return null; | |
98 } | |
99 Long[] values = getDataMinMaxDate(artifact); | |
100 if (values == null) { | |
101 return null; | |
102 } | |
103 Element def = createItem( | |
104 cr, | |
105 new String[] {"default", values[0].toString() + "," + values[1].toString()}); | |
106 | |
107 return new Element[] { def }; | |
108 } | |
109 | |
27 @Override | 110 @Override |
28 protected String getUIProvider() { | 111 protected String getUIProvider() { |
29 return "bedquality_periods_select"; | 112 return "bedquality_periods_select"; |
30 } | 113 } |
31 | 114 |