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@2198: this.ww = ww; sascha@2198: this.function1 = Identity.IDENTITY; sascha@2198: this.function2 = Identity.IDENTITY; 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@2182: public WW() { 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@2201: String name, sascha@2201: double startKm, sascha@2201: double [] ws, sascha@2201: double endKm, sascha@2201: double [] ws2 sascha@2201: ) { sascha@2201: this.name = name; sascha@2201: this.ws = new TDoubleArrayList(ws); sascha@2201: this.ws2 = new TDoubleArrayList(ws2); sascha@2201: this.startKm = startKm; sascha@2201: this.endKm = endKm; 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@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: } sascha@2182: } sascha@2182: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :