sascha@726: package de.intevation.flys.artifacts.model; sascha@726: teichmann@4821: import de.intevation.flys.utils.DoubleUtil; teichmann@4821: teichmann@4821: import gnu.trove.TDoubleArrayList; teichmann@4821: ingo@2087: import java.util.regex.Matcher; ingo@2087: import java.util.regex.Pattern; ingo@2087: sascha@1033: import org.apache.log4j.Logger; sascha@1033: sascha@726: public class WQ sascha@2182: extends W sascha@726: { ingo@2087: public static final Pattern NUMBERS_PATTERN = ingo@2087: Pattern.compile("\\D*(\\d++.\\d*)\\D*"); ingo@2087: sascha@2182: private static Logger log = Logger.getLogger(WQ.class); sascha@1033: sascha@2182: protected TDoubleArrayList qs; sascha@726: sascha@726: public WQ() { sascha@726: this(""); sascha@726: } sascha@726: sascha@726: public WQ(String name) { sascha@2182: super(name); sascha@2182: qs = new TDoubleArrayList(); sascha@726: } sascha@726: sascha@726: public WQ(int capacity) { sascha@726: this(capacity, ""); sascha@726: } sascha@726: sascha@726: sascha@726: public WQ(int capacity, String name) { sascha@2182: super(capacity, name); sascha@2182: qs = new TDoubleArrayList(capacity); sascha@726: } sascha@726: sascha@726: public WQ(double [] qs, double [] ws) { sascha@726: this(qs, ws, ""); sascha@726: } sascha@726: sascha@726: public WQ(double [] qs, double [] ws, String name) { sascha@726: super(name); sascha@2182: this.ws = new TDoubleArrayList(ws); sascha@2182: this.qs = new TDoubleArrayList(qs); sascha@726: } sascha@726: ingo@2087: ingo@2087: public Double getRawValue() { ingo@2087: if (name == null || name.length() == 0) { ingo@2087: // this should never happen ingo@2087: return null; ingo@2087: } ingo@2087: ingo@2087: Matcher m = NUMBERS_PATTERN.matcher(name); ingo@2087: ingo@2087: if (m.matches()) { ingo@2087: String raw = m.group(1); ingo@2087: ingo@2087: try { ingo@2087: return Double.valueOf(raw); ingo@2087: } ingo@2087: catch (NumberFormatException nfe) { ingo@2087: // do nothing ingo@2087: } ingo@2087: } ingo@2087: ingo@2087: return null; ingo@2087: } ingo@2087: sascha@726: public void add(double w, double q) { sascha@2182: ws.add(w); sascha@2182: qs.add(q); sascha@726: } sascha@726: sascha@726: public double getQ(int idx) { sascha@2182: return qs.getQuick(idx); sascha@726: } sascha@726: sascha@2182: @Override sascha@726: public double [] get(int idx) { sascha@726: return get(idx, new double [2]); sascha@726: } sascha@726: sascha@2182: @Override sascha@726: public double [] get(int idx, double [] dst) { sascha@2182: dst[0] = ws.getQuick(idx); sascha@2182: dst[1] = qs.getQuick(idx); sascha@726: return dst; sascha@726: } sascha@726: sascha@726: public double [] getQs() { sascha@2182: return qs.toNativeArray(); sascha@744: } sascha@744: sascha@2182: @Override sascha@2182: public void removeNaNs() { teichmann@4821: DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs }); sascha@1033: } sascha@726: } sascha@726: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :