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@3035: ingo@3466: import org.apache.log4j.Logger; ingo@3466: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; teichmann@5831: import org.dive4elements.river.utils.KMIndex; raimund@3035: raimund@3035: raimund@3035: /** raimund@3035: * Facet to show W values for Q values at km for a date. raimund@3035: * raimund@3035: * @author Raimund Renkert raimund@3035: */ raimund@3035: public class FixReferenceEventsFacet bjoern@4442: extends FixingsFacet raimund@3035: implements FacetTypes { raimund@3035: raimund@3035: /** House logger. */ raimund@3035: private static Logger logger = Logger.getLogger(FixReferenceEventsFacet.class); raimund@3035: raimund@3035: /** Trivial Constructor. */ raimund@3035: public FixReferenceEventsFacet() { raimund@3035: } raimund@3035: raimund@3035: raimund@3035: /** raimund@3035: * @param name raimund@3035: */ raimund@3043: public FixReferenceEventsFacet(int index, String name, String description) { raimund@3039: super(index, raimund@3043: name, raimund@3039: description, raimund@3039: ComputeType.ADVANCE, raimund@3039: null, raimund@3039: null); raimund@3035: } raimund@3035: raimund@3035: raimund@3035: /** raimund@3035: * Returns the data this facet requires. raimund@3035: * raimund@3035: * @param artifact the owner artifact. raimund@3035: * @param context the CallContext (ignored). raimund@3035: * raimund@3035: * @return the data. raimund@3035: */ raimund@3035: @Override raimund@3035: public Object getData(Artifact artifact, CallContext context) { raimund@3035: logger.debug("FixReferenceEventsFacet.getData"); raimund@3035: teichmann@6868: if (!(artifact instanceof D4EArtifact)) { raimund@3035: logger.debug("Not an instance of FixationArtifact."); raimund@3035: return null; raimund@3035: } teichmann@6868: teichmann@6868: D4EArtifact flys = (D4EArtifact)artifact; teichmann@6868: teichmann@6868: CalculationResult res = teichmann@6868: (CalculationResult) flys.compute(context, teichmann@6868: ComputeType.ADVANCE, teichmann@6868: false); teichmann@6868: teichmann@6868: FixResult result = (FixResult) res.getData(); teichmann@6868: double currentKm = getCurrentKm(context); teichmann@6868: teichmann@6873: if (logger.isDebugEnabled()) { teichmann@6873: logger.debug("current km in FRE: " + currentKm); teichmann@6873: } teichmann@6868: teichmann@6868: KMIndex kmQWs = result.getReferenced(); teichmann@6868: KMIndex.Entry kmQWsEntry = kmQWs.binarySearch(currentKm); teichmann@6873: teichmann@6873: if (kmQWsEntry == null) { teichmann@6873: return null; teichmann@6868: } teichmann@6873: teichmann@6873: // The lower eight bits contain the index of the point. teichmann@6873: int ndx = index & 255; teichmann@6873: QWD [] qwds = kmQWsEntry.getValue(); teichmann@6873: if (ndx >= qwds.length) { teichmann@6873: logger.error("index too large: " + ndx + " " + qwds.length); teichmann@6873: return null; teichmann@6873: } teichmann@6873: return qwds[ndx]; raimund@3035: } raimund@3035: raimund@3035: raimund@3035: /** raimund@3035: * Create a deep copy of this Facet. raimund@3035: * @return a deep copy. raimund@3035: */ raimund@3035: @Override raimund@3035: public FixReferenceEventsFacet deepCopy() { raimund@3035: FixReferenceEventsFacet copy = new FixReferenceEventsFacet(); raimund@3035: copy.set(this); raimund@3035: return copy; raimund@3035: } raimund@3035: } raimund@3035: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :