Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedQualityD50TimeRangeConfig.java @ 9522:23d97d60b889
Selection range of D50 values for tkh calculation can now be configured with a river specific table.
author | gernotbelger |
---|---|
date | Mon, 01 Oct 2018 16:37:12 +0200 |
parents | 787fc085459b |
children | 8e6b9cb9486a |
comparison
equal
deleted
inserted
replaced
9521:ce54388d6efe | 9522:23d97d60b889 |
---|---|
17 import java.util.List; | 17 import java.util.List; |
18 import java.util.Map; | 18 import java.util.Map; |
19 | 19 |
20 import org.dive4elements.river.artifacts.model.Calculation; | 20 import org.dive4elements.river.artifacts.model.Calculation; |
21 import org.dive4elements.river.artifacts.model.DateRange; | 21 import org.dive4elements.river.artifacts.model.DateRange; |
22 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.BedQualityD50KmValueFinder; | |
22 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; | 23 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; |
23 import org.dive4elements.river.model.River; | 24 import org.dive4elements.river.model.River; |
24 | 25 |
25 /** | 26 /** |
26 * Represents the contents of the 'bedheights.properties' files. | 27 * Represents the contents of the 'bedheights.properties' files. |
37 | 38 |
38 public static class BedQualityParseException extends Exception { | 39 public static class BedQualityParseException extends Exception { |
39 | 40 |
40 private static final long serialVersionUID = 1L; | 41 private static final long serialVersionUID = 1L; |
41 | 42 |
42 private BedQualityParseException(final String string) { | 43 BedQualityParseException(final String message) { |
43 super(string); | 44 super(message); |
45 } | |
46 | |
47 BedQualityParseException(final String message, final Throwable cause) { | |
48 super(message, cause); | |
44 } | 49 } |
45 } | 50 } |
46 | 51 |
47 public static synchronized DateRange getDefaults(final River river, final int soundingYear, final Calculation problems) | 52 public static synchronized DateRange getDefaults(final River river, final int soundingYear, final Calculation problems) |
48 throws BedQualityParseException, IOException, TsvReaderException { | 53 throws BedQualityParseException { |
49 return INSTANCE.getBedHeightDefaultsForRiver(river, soundingYear, problems); | 54 return INSTANCE.getBedHeightDefaultsForRiver(river, soundingYear, problems); |
50 } | 55 } |
51 | 56 |
52 private synchronized DateRange getBedHeightDefaultsForRiver(final River river, final int soundingYear, final Calculation problems) | 57 private synchronized DateRange getBedHeightDefaultsForRiver(final River river, final int soundingYear, final Calculation problems) |
53 throws BedQualityParseException { | 58 throws BedQualityParseException { |
90 try { | 95 try { |
91 | 96 |
92 return Integer.valueOf(value); | 97 return Integer.valueOf(value); |
93 } | 98 } |
94 catch (final NumberFormatException e) { | 99 catch (final NumberFormatException e) { |
95 throw new BedQualityParseException("Invalid input; should be year ('yyyy') or 'MIN' or 'MAX'"); | 100 throw new BedQualityParseException("Invalid input; should be year ('yyyy') or 'MIN' or 'MAX'", e); |
96 } | 101 } |
97 } | 102 } |
98 | 103 |
99 private static class CalRange { | 104 private static final class CalRange { |
100 private final long startTimeSounding; | 105 private final long startTimeSounding; |
101 private final long endTimeSounding; | 106 private final long endTimeSounding; |
102 | 107 |
103 private final long startTimeQuery; | 108 private final long startTimeQuery; |
104 private final long endTimeQuery; | 109 private final long endTimeQuery; |
105 | 110 |
106 private final static Calendar cal = Calendar.getInstance(); | 111 private final static Calendar cal = Calendar.getInstance(); |
107 | 112 |
108 private Date getStartTimeQuery() { | 113 public Date getStartTimeQuery() { |
109 return new Date(this.startTimeQuery); | 114 return new Date(this.startTimeQuery); |
110 } | 115 } |
111 | 116 |
112 private Date getEndTimeQuery() { | 117 public Date getEndTimeQuery() { |
113 return new Date(this.endTimeQuery); | 118 return new Date(this.endTimeQuery); |
114 } | 119 } |
115 | 120 |
116 private CalRange(final Integer startYearSounding, final Integer endYearSounding, final Integer startYearQuery, final Integer endYearQuery) { | 121 public CalRange(final Integer startYearSounding, final Integer endYearSounding, final Integer startYearQuery, final Integer endYearQuery) { |
117 | 122 |
118 this.startTimeSounding = 1L;// (startYearSounding != null) ? getLongValForYear(startYearSounding, 0, 1) : | 123 this.startTimeSounding = (startYearSounding != null) ? getLongValForYear(startYearSounding, 0, 1) : BedQualityD50KmValueFinder.MIN_DATE.getTime(); |
119 // BedQualityD50KmValueFinder.MIN_DATE.getTime(); | 124 this.startTimeQuery = (startYearQuery != null) ? getLongValForYear(startYearQuery, 0, 1) : BedQualityD50KmValueFinder.MIN_DATE.getTime(); |
120 this.startTimeQuery = 1L;// (startYearQuery != null) ? getLongValForYear(startYearQuery, 0, 1) : BedQualityD50KmValueFinder.MIN_DATE.getTime(); | 125 this.endTimeSounding = (endYearSounding != null) ? getLongValForYear(endYearSounding, 11, 31) : BedQualityD50KmValueFinder.MAX_DATE.getTime(); |
121 this.endTimeSounding = 1L;// (endYearSounding != null) ? getLongValForYear(endYearSounding, 11, 31) : | 126 this.endTimeQuery = (endYearQuery != null) ? getLongValForYear(endYearQuery, 11, 31) : BedQualityD50KmValueFinder.MAX_DATE.getTime(); |
122 // BedQualityD50KmValueFinder.MAX_DATE.getTime(); | |
123 this.endTimeQuery = 1L;// (endYearQuery != null) ? getLongValForYear(endYearQuery, 11, 31) : BedQualityD50KmValueFinder.MAX_DATE.getTime(); | |
124 | |
125 } | 127 } |
126 | 128 |
127 private long getLongValForYear(final int year, final int month0based, final int dayOfMonth) { | 129 private long getLongValForYear(final int year, final int month0based, final int dayOfMonth) { |
128 cal.clear(); | 130 cal.clear(); |
129 cal.set(year, month0based, dayOfMonth); | 131 cal.set(year, month0based, dayOfMonth); |
130 | 132 |
131 return cal.getTimeInMillis(); | 133 return cal.getTimeInMillis(); |
132 } | 134 } |
133 | 135 |
134 private boolean isSoundingYearInRange(final int soundingYear) { | 136 public boolean isSoundingYearInRange(final int soundingYear) { |
135 cal.clear(); | 137 cal.clear(); |
136 | 138 |
137 cal.set(soundingYear, 5, 5); // random date in the middle of the year | 139 cal.set(soundingYear, 5, 5); // random date in the middle of the year |
138 | 140 |
139 final Long time = cal.getTimeInMillis(); | 141 final Long time = cal.getTimeInMillis(); |
141 if (time > this.startTimeSounding && time < this.endTimeSounding) | 143 if (time > this.startTimeSounding && time < this.endTimeSounding) |
142 return true; | 144 return true; |
143 | 145 |
144 return false; | 146 return false; |
145 } | 147 } |
146 | |
147 } | 148 } |
148 | |
149 } | 149 } |