comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java @ 8193:8d447516b7dd

Sum up fractions from stations and previous stations according to respective validity model.
author Tom Gottfried <tom@intevation.de>
date Thu, 04 Sep 2014 17:33:01 +0200
parents a1ceacf15d3a
children 42ac86ec19c7
comparison
equal deleted inserted replaced
8192:adbf980004c0 8193:8d447516b7dd
209 public Station getNext() { 209 public Station getNext() {
210 return next; 210 return next;
211 } 211 }
212 212
213 public void setPrev(Station prev) { 213 public void setPrev(Station prev) {
214 this.prev = next; 214 this.prev = prev;
215 } 215 }
216 216
217 public Station getPrev() { 217 public Station getPrev() {
218 return prev; 218 return prev;
219 }
220
221 public Station getNext(boolean isKMUp) {
222 return isKMUp ? getNext() : getPrev();
223 }
224
225 public Station getPrev(boolean isKMUp) {
226 return isKMUp ? getPrev() : getNext();
227 } 219 }
228 220
229 public void merge(Station other) { 221 public void merge(Station other) {
230 this.type |= other.type; 222 this.type |= other.type;
231 for (int i = 0, N = grainFractions.size(); i < N; ++i) { 223 for (int i = 0, N = grainFractions.size(); i < N; ++i) {
248 // re-establish id order. 240 // re-establish id order.
249 Collections.sort(a, ID_CMP); 241 Collections.sort(a, ID_CMP);
250 return a; 242 return a;
251 } 243 }
252 244
253 public Station nextByType(int type, boolean isKMUp) { 245 public Station nextByType(int type) {
254 for (Station curr = this; curr != null; curr = curr.getNext(isKMUp)) { 246 for (Station curr = this; curr != null; curr = curr.getNext()) {
255 if (curr.isType(type)) { 247 if (curr.isType(type)) {
256 return curr; 248 return curr;
257 } 249 }
258 } 250 }
259 return null; 251 return null;
260 } 252 }
261 253
262 public Station prevByType(int type, boolean isKMUp) { 254 public Station prevByType(int type) {
263 for (Station curr = this; curr != null; curr = curr.getPrev(isKMUp)) { 255 for (Station curr = this; curr != null; curr = curr.getPrev()) {
264 if (curr.isType(type)) { 256 if (curr.isType(type)) {
265 return curr; 257 return curr;
266 } 258 }
267 } 259 }
268 return null; 260 return null;
348 private Station [] stations; 340 private Station [] stations;
349 341
350 public SedimentLoadData() { 342 public SedimentLoadData() {
351 } 343 }
352 344
353 public SedimentLoadData(Collection<Station> stations) { 345 public SedimentLoadData(Collection<Station> stations, boolean kmUp) {
354 setStations(stations); 346 setStations(stations, kmUp);
355 } 347 }
356 348
357 public Station[] getStations() { 349 public Station[] getStations() {
358 return stations; 350 return stations;
359 } 351 }
360 352
361 public void setStations(Collection<Station> stations) { 353 public void setStations(Collection<Station> stations, boolean kmUp) {
362 TreeMap<Double, Station> same = 354 TreeMap<Double, Station> same =
363 new TreeMap<Double, Station>(EpsilonComparator.CMP); 355 new TreeMap<Double, Station>(EpsilonComparator.CMP);
364 356
365 for (Station station: stations) { 357 for (Station station: stations) {
366 Double key = station.getStation(); 358 Double key = station.getStation();
374 this.stations = new Station[same.size()]; 366 this.stations = new Station[same.size()];
375 int i = 0; 367 int i = 0;
376 for (Station station: same.values()) { 368 for (Station station: same.values()) {
377 this.stations[i++] = station; 369 this.stations[i++] = station;
378 } 370 }
379 wireNeighbors(); 371 wireNeighbors(kmUp);
380 } 372 }
381 373
382 private void wireNeighbors() { 374 private void wireNeighbors(boolean kmUp) {
383 for (int i = 1; i < stations.length; ++i) { 375 if (kmUp) {
384 stations[i-1].setNext(stations[i]); 376 for (int i = stations.length - 1; i > 0; --i) {
385 stations[i].setPrev(stations[i-1]); 377 stations[i].setNext(stations[i-1]);
378 stations[i-1].setPrev(stations[i]);
379 }
380 }
381 else {
382 for (int i = 1; i < stations.length; ++i) {
383 stations[i-1].setNext(stations[i]);
384 stations[i].setPrev(stations[i-1]);
385 }
386 } 386 }
387 } 387 }
388 388
389 private void recursiveFindStations( 389 private void recursiveFindStations(
390 double a, double b, 390 double a, double b,

http://dive4elements.wald.intevation.org