teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.artifacts.model.fixings;
raimund@3169:
teichmann@5831: import org.dive4elements.artifacts.Artifact;
teichmann@5831: import org.dive4elements.artifacts.CallContext;
sascha@3203:
teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact;
sascha@3203:
teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult;
teichmann@5831: import org.dive4elements.river.artifacts.model.DataFacet;
teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.utils.KMIndex;
raimund@3169:
sascha@3203: import org.apache.log4j.Logger;
raimund@3169:
raimund@3169:
raimund@3169: /**
raimund@3169: * Facet to show average W values for Q sectors.
raimund@3169: *
raimund@3169: * @author Raimund Renkert
raimund@3169: */
raimund@3169: public class FixLongitudinalReferenceFacet
raimund@3169: extends DataFacet
raimund@3169: implements FacetTypes {
raimund@3169:
teichmann@8202: /** House log. */
tom@8856: private static Logger log = Logger.getLogger(
tom@8856: FixLongitudinalReferenceFacet.class);
raimund@3169:
raimund@3169: /** Trivial Constructor. */
raimund@3169: public FixLongitudinalReferenceFacet() {
raimund@3169: }
raimund@3169:
raimund@3169:
raimund@3169: public FixLongitudinalReferenceFacet(
raimund@3169: int ndx,
raimund@3169: String name,
sascha@3172: String description)
raimund@3169: {
raimund@3169: super(
raimund@3169: ndx,
raimund@3169: name,
raimund@3169: description,
raimund@3169: ComputeType.ADVANCE,
raimund@3169: null,
raimund@3169: null);
raimund@3169: }
raimund@3169:
raimund@3169:
raimund@3169: /**
raimund@3169: * Returns the data this facet requires.
raimund@3169: *
raimund@3169: * @param artifact the owner artifact.
raimund@3169: * @param context the CallContext.
raimund@3169: *
raimund@3169: * @return the data as KMIndex.
raimund@3169: */
raimund@3169: @Override
raimund@3169: public Object getData(Artifact artifact, CallContext context) {
teichmann@8202: log.debug("FixLongitudinalReferenceFacet.getData");
raimund@3169:
teichmann@5867: if (artifact instanceof D4EArtifact) {
teichmann@5867: D4EArtifact flys = (D4EArtifact)artifact;
raimund@3169:
raimund@3169: CalculationResult res =
raimund@3169: (CalculationResult) flys.compute(context,
raimund@3169: ComputeType.ADVANCE,
raimund@3169: false);
raimund@3169:
sascha@3415: FixAnalysisResult result = (FixAnalysisResult) res.getData();
raimund@3169:
gernotbelger@9360: KMIndex kmReference = result.getFixings();
raimund@3169:
raimund@3169: if (kmReference == null) {
teichmann@8202: log.warn("No references found.");
raimund@3169: return null;
raimund@3169: }
raimund@3169:
raimund@3610: int qwdNdx = index & 255;
gernotbelger@9360:
gernotbelger@9360: final KMIndex resReference = new KMIndex<>();
gernotbelger@9360:
raimund@3610: for (KMIndex.Entry entry: kmReference) {
raimund@3610: QWD[] qwds = entry.getValue();
raimund@3610: for(int i = 0; i < qwds.length; i++) {
gernotbelger@9360: if(qwds[i].getIndex() == qwdNdx && !qwds[i].isOutlier() ) {
raimund@3610: resReference.add(entry.getKm(), qwds[i]);
raimund@3610: }
raimund@3610: }
raimund@3610: }
gernotbelger@9360:
raimund@3610: return resReference;
raimund@3169: }
gernotbelger@9360:
gernotbelger@9360: log.warn("Artifact is no instance of D4EArtifact.");
gernotbelger@9360: return null;
raimund@3169: }
raimund@3169:
raimund@3169: /**
raimund@3169: * Create a deep copy of this Facet.
raimund@3169: * @return a deep copy.
raimund@3169: */
raimund@3169: @Override
raimund@3169: public FixLongitudinalReferenceFacet deepCopy() {
raimund@3169: FixLongitudinalReferenceFacet copy =
raimund@3169: new FixLongitudinalReferenceFacet();
raimund@3169: copy.set(this);
raimund@3169: return copy;
raimund@3169: }
gernotbelger@9360: }