sascha@2182: package de.intevation.flys.artifacts.model; sascha@2182: sascha@2198: import de.intevation.flys.artifacts.math.Function; sascha@2198: import de.intevation.flys.artifacts.math.Identity; sascha@2198: sascha@2182: import gnu.trove.TDoubleArrayList; sascha@2182: sascha@2182: public class WW sascha@2182: extends W sascha@2182: { sascha@2198: public static class ApplyFunctionIterator sascha@2198: { sascha@2198: protected Function function1; sascha@2198: protected Function function2; sascha@2198: protected int pos; sascha@2198: protected WW ww; sascha@2198: sascha@2198: public ApplyFunctionIterator(WW ww) { sascha@2256: this(ww, Identity.IDENTITY, Identity.IDENTITY); sascha@2256: } sascha@2256: sascha@2256: public ApplyFunctionIterator( sascha@3076: WW ww, sascha@2256: Function function1, sascha@2256: Function function2 sascha@2256: ) { sascha@2198: this.ww = ww; sascha@2256: this.function1 = function1; sascha@2256: this.function2 = function2; sascha@2198: } sascha@2198: sascha@2198: public boolean hasNext() { sascha@2198: return pos < ww.size(); sascha@2198: } sascha@2198: sascha@2198: public int size() { sascha@2198: return ww.size(); sascha@2198: } sascha@2198: sascha@2198: public void reset() { sascha@2198: pos = 0; sascha@2198: } sascha@2198: sascha@2198: public WW getWW() { sascha@2198: return ww; sascha@2198: } sascha@2198: sascha@2198: public void get(int idx, double [] wwPair) { sascha@2198: wwPair[0] = function1.value(ww.getW(idx)); sascha@2198: wwPair[1] = function2.value(ww.getW2(idx)); sascha@2198: } sascha@2198: sascha@2198: public void next(double [] wwPair) { sascha@2198: get(pos++, wwPair); sascha@2198: } sascha@2198: } // class FunctionIterator sascha@2198: sascha@2182: protected TDoubleArrayList ws2; sascha@2182: sascha@2201: protected double startKm; sascha@2201: protected double endKm; sascha@2201: sascha@2256: protected Double startDatum; sascha@2256: protected Double endDatum; sascha@2256: sascha@2182: public WW() { sascha@2271: this(""); sascha@2182: } sascha@2182: sascha@2182: public WW(String name) { sascha@2182: super(name); sascha@2182: } sascha@2182: sascha@2182: public WW(int capacity) { sascha@2182: this(capacity, ""); sascha@2182: } sascha@2182: sascha@2182: public WW(int capacity, String name) { sascha@2182: super(capacity, name); sascha@2182: ws2 = new TDoubleArrayList(capacity); sascha@2182: } sascha@2182: sascha@2201: public WW( sascha@3076: String name, sascha@2256: double startKm, sascha@2256: Double startDatum, sascha@3076: double [] ws, sascha@2201: double endKm, sascha@2256: Double endDatum, sascha@2201: double [] ws2 sascha@2201: ) { sascha@2256: this.name = name; sascha@2256: this.ws = new TDoubleArrayList(ws); sascha@2256: this.ws2 = new TDoubleArrayList(ws2); sascha@2256: this.startKm = startKm; sascha@2256: this.startDatum = startDatum; sascha@2256: this.endKm = endKm; sascha@2256: this.endDatum = endDatum; sascha@2186: } sascha@2186: sascha@2197: public WW(String name, TDoubleArrayList ws, TDoubleArrayList ws2) { sascha@2197: this.name = name; sascha@2197: this.ws = ws; sascha@2197: this.ws2 = ws2; sascha@2197: } sascha@2197: sascha@2182: public void add(double w1, double w2) { sascha@2182: ws .add(w1); sascha@2182: ws2.add(w2); sascha@2182: } sascha@2182: felix@2229: public double getW1(int idx) { felix@2229: return ws.getQuick(idx); felix@2229: } felix@2229: sascha@2182: public double getW2(int idx) { sascha@2182: return ws2.getQuick(idx); sascha@2182: } sascha@2182: sascha@2182: public double [] getWs2() { sascha@2182: return ws2.toNativeArray(); sascha@2182: } sascha@2182: sascha@2182: @Override sascha@2182: public double [] get(int idx) { sascha@2182: return get(idx, new double[2]); sascha@2182: } sascha@2182: sascha@2182: @Override sascha@2182: public double [] get(int idx, double [] dst) { sascha@2182: dst[0] = ws .getQuick(idx); sascha@2182: dst[1] = ws2.getQuick(idx); sascha@2182: return dst; sascha@2182: } sascha@2182: sascha@2201: public double getStartKm() { sascha@2201: return startKm; sascha@2201: } sascha@2201: sascha@2201: public void setStartKm(double startKm) { sascha@2201: this.startKm = startKm; sascha@2201: } sascha@2201: sascha@2201: public double getEndKm() { sascha@2201: return endKm; sascha@2201: } sascha@2201: sascha@2201: public void setEndKm(double endKm) { sascha@2201: this.endKm = endKm; sascha@2201: } sascha@2201: sascha@2256: public Double getStartDatum() { sascha@2256: return startDatum; sascha@2256: } sascha@2256: sascha@2256: public boolean startAtGauge() { sascha@2256: return startDatum != null; sascha@2256: } sascha@2256: sascha@2256: public boolean endAtGauge() { sascha@2256: return endDatum != null; sascha@2256: } sascha@2256: sascha@2256: public void setStartDatum(Double startDatum) { sascha@2256: this.startDatum = startDatum; sascha@2256: } sascha@2256: sascha@2256: public Double getEndDatum() { sascha@2256: return endDatum; sascha@2256: } sascha@2256: sascha@2256: public void setEndDatum(Double endDatum) { sascha@2256: this.endDatum = endDatum; sascha@2256: } sascha@2256: sascha@2182: @Override sascha@2182: public void removeNaNs() { sascha@2182: removeNaNs(new TDoubleArrayList [] { ws, ws2 }); sascha@2182: } sascha@2197: sascha@2198: public double minWs2() { sascha@2198: return ws2.min(); sascha@2197: } felix@2329: felix@2329: // Note that we can also easily define a Function to do so. felix@2329: public double getRelHeight1Cm(int idx) { felix@2329: if (this.startAtGauge()) { felix@2329: return (ws.getQuick(idx) - getStartDatum())*100d; felix@2329: } felix@2329: else return ws.getQuick(idx)*100d; felix@2329: } felix@2329: felix@2329: public double getRelHeight2Cm(int idx) { felix@2329: if (this.endAtGauge()) { felix@2329: return (ws2.getQuick(idx) - getEndDatum())*100d; felix@2329: } felix@2329: else return ws2.getQuick(idx)*100d; felix@2329: } sascha@2182: } sascha@2182: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :