Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Thu Sep 04 16:25:06 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Thu Sep 04 17:33:01 2014 +0200 @@ -211,21 +211,13 @@ } public void setPrev(Station prev) { - this.prev = next; + this.prev = prev; } public Station getPrev() { return prev; } - public Station getNext(boolean isKMUp) { - return isKMUp ? getNext() : getPrev(); - } - - public Station getPrev(boolean isKMUp) { - return isKMUp ? getPrev() : getNext(); - } - public void merge(Station other) { this.type |= other.type; for (int i = 0, N = grainFractions.size(); i < N; ++i) { @@ -250,8 +242,8 @@ return a; } - public Station nextByType(int type, boolean isKMUp) { - for (Station curr = this; curr != null; curr = curr.getNext(isKMUp)) { + public Station nextByType(int type) { + for (Station curr = this; curr != null; curr = curr.getNext()) { if (curr.isType(type)) { return curr; } @@ -259,8 +251,8 @@ return null; } - public Station prevByType(int type, boolean isKMUp) { - for (Station curr = this; curr != null; curr = curr.getPrev(isKMUp)) { + public Station prevByType(int type) { + for (Station curr = this; curr != null; curr = curr.getPrev()) { if (curr.isType(type)) { return curr; } @@ -350,15 +342,15 @@ public SedimentLoadData() { } - public SedimentLoadData(Collection<Station> stations) { - setStations(stations); + public SedimentLoadData(Collection<Station> stations, boolean kmUp) { + setStations(stations, kmUp); } public Station[] getStations() { return stations; } - public void setStations(Collection<Station> stations) { + public void setStations(Collection<Station> stations, boolean kmUp) { TreeMap<Double, Station> same = new TreeMap<Double, Station>(EpsilonComparator.CMP); @@ -376,13 +368,21 @@ for (Station station: same.values()) { this.stations[i++] = station; } - wireNeighbors(); + wireNeighbors(kmUp); } - private void wireNeighbors() { - for (int i = 1; i < stations.length; ++i) { - stations[i-1].setNext(stations[i]); - stations[i].setPrev(stations[i-1]); + private void wireNeighbors(boolean kmUp) { + if (kmUp) { + for (int i = stations.length - 1; i > 0; --i) { + stations[i].setNext(stations[i-1]); + stations[i-1].setPrev(stations[i]); + } + } + else { + for (int i = 1; i < stations.length; ++i) { + stations[i-1].setNext(stations[i]); + stations[i].setPrev(stations[i-1]); + } } }