teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * 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.access.FixAnalysisAccess; raimund@3169: 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: raimund@3169: /** House logger. */ raimund@3169: private static Logger logger = Logger.getLogger(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) { raimund@3169: logger.debug("FixLongitudinalReferenceFacet.getData"); raimund@3169: teichmann@5867: if (artifact instanceof D4EArtifact) { teichmann@5867: D4EArtifact flys = (D4EArtifact)artifact; rrenkert@4866: FixAnalysisAccess access = new FixAnalysisAccess(flys, context); 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: raimund@3169: KMIndex kmReference = result.getReferenced(); raimund@3169: raimund@3169: if (kmReference == null) { raimund@3169: logger.warn("No references found."); raimund@3169: return null; raimund@3169: } raimund@3169: raimund@3610: int qwdNdx = index & 255; raimund@3610: KMIndex resReference = raimund@3610: new KMIndex(); raimund@3610: for (KMIndex.Entry entry: kmReference) { raimund@3610: QWD[] qwds = entry.getValue(); raimund@3610: for(int i = 0; i < qwds.length; i++) { raimund@3610: if(qwds[i].getIndex() == qwdNdx) { raimund@3610: resReference.add(entry.getKm(), qwds[i]); raimund@3610: } raimund@3610: } raimund@3610: } raimund@3610: return resReference; raimund@3169: } raimund@3169: else { teichmann@5867: logger.warn("Artifact is no instance of D4EArtifact."); raimund@3169: return null; raimund@3169: } raimund@3169: } 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: } raimund@3169: } raimund@3169: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :