Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurements.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurements.java@bd047b71ab37 |
children | 4897a58c8746 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/Measurements.java Thu Apr 25 15:23:37 2013 +0200 @@ -0,0 +1,164 @@ +package org.dive4elements.river.artifacts.model.sq; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +public class Measurements +{ + private static final Logger log = Logger.getLogger(Measurements.class); + + public interface SExtractor { + double getS(Measurement measument); + } // interface SExtractor + + public static final SExtractor S_SF_EXTRACTOR = new SExtractor() { + @Override + public double getS(Measurement measument) { + return measument.S_SF(); + } + }; + + public static final SExtractor S_SS_EXTRACTOR = new SExtractor() { + @Override + public double getS(Measurement measument) { + return measument.S_SS(); + } + }; + + public static final SExtractor S_BL_S_EXTRACTOR = new SExtractor() { + @Override + public double getS(Measurement measument) { + return measument.S_BL_S(); + } + }; + + public static final SExtractor S_BL_FG_EXTRACTOR = new SExtractor() { + @Override + public double getS(Measurement measument) { + return measument.S_BL_FG(); + } + }; + + public static final SExtractor S_BL_CG_EXTRACTOR = new SExtractor() { + @Override + public double getS(Measurement measument) { + return measument.S_BL_CG(); + } + }; + + public static final SExtractor S_BL_EXTRACTOR = new SExtractor() { + @Override + public double getS(Measurement measument) { + return measument.BL_S(); + } + }; + + protected List<Measurement> measuments; + protected List<Measurement> accumulated; + + public Measurements() { + } + + public Measurements( + List<Measurement> measuments, + List<Measurement> accumulated + ) { + if (log.isDebugEnabled()) { + log.debug("number of measuments: " + measuments.size()); + log.debug("number of accumulated: " + accumulated.size()); + } + this.measuments = measuments; + this.accumulated = accumulated; + } + + public static List<SQ> extractSQ( + List<Measurement> measuments, + SExtractor extractor + ) { + List<SQ> result = new ArrayList<SQ>(measuments.size()); + int invalid = 0; + for (Measurement measument: measuments) { + SQ sq = new SQ(extractor.getS(measument), measument.Q()); + if (sq.isValid()) { + result.add(sq); + } + else { + ++invalid; + } + } + if (log.isDebugEnabled()) { + log.debug("Removed num invalid: " + invalid + + " of " + measuments.size()); + } + return result; + } + + public List<SQ> S_SF() { + return extractSQ(measuments, S_SF_EXTRACTOR); + } + + public List<SQ> S_SS() { + return extractSQ(measuments, S_SS_EXTRACTOR); + } + + public List<SQ> S_BL_S() { + return extractSQ(accumulated, S_BL_S_EXTRACTOR); + } + + public List<SQ> S_BL_FG() { + return extractSQ(accumulated, S_BL_FG_EXTRACTOR); + } + + public List<SQ> S_BL_CG() { + return extractSQ(accumulated, S_BL_CG_EXTRACTOR); + } + + public List<SQ> S_BL() { + return extractSQ(accumulated, S_BL_EXTRACTOR); + } + + public List<SQ> getSQs(int index) { + switch (index) { + case 0: return S_SF(); + case 1: return S_SS(); + case 2: return S_BL_S(); + case 3: return S_BL_FG(); + case 4: return S_BL_CG(); + case 5: return S_BL(); + } + log.error("THIS SHOULD NOT HAPPEN: Tried to access SQ[" + index + "]"); + return new ArrayList<SQ>(0); + } + + /** + * Gets the accumulated for this instance. + * + * @return The accumulated. + */ + public List<Measurement> getAccumulated() { + return this.accumulated; + } + + /** + * Sets the accumulated for this instance. + * + * @param accumulated The accumulated. + */ + public void setAccumulated(List<Measurement> accumulated) { + this.accumulated = accumulated; + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Measurements ["); + for (int i = 0, M = measuments.size(); i < M; ++i) { + if (i > 0) sb.append(", "); + sb.append(measuments.get(i)); + } + return sb.append(']').toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :