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:
tom@9726: import org.apache.logging.log4j.Logger;
tom@9726: import org.apache.logging.log4j.LogManager;
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:
teichmann@8202: /** House log. */
tom@9726: private static Logger log = LogManager.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) {
teichmann@8202: log.debug("FixReferenceEventsFacet.getData");
raimund@3035:
teichmann@6868: if (!(artifact instanceof D4EArtifact)) {
teichmann@8202: log.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@8202: if (log.isDebugEnabled()) {
teichmann@8202: log.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@6875: if (kmQWsEntry != null) {
teichmann@6875: int ndx = index & 255;
teichmann@6875: for (QWD qwd: kmQWsEntry.getValue()) {
teichmann@6875: if (qwd.getIndex() == ndx) {
teichmann@6875: return qwd;
teichmann@6875: }
teichmann@6875: }
teichmann@6868: }
teichmann@6875: return null;
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 :