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:
teichmann@5831: import org.dive4elements.artifacts.Artifact;
teichmann@5831: import org.dive4elements.artifacts.CallContext;
raimund@3035:
teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact;
raimund@3035:
teichmann@5831: import org.dive4elements.river.artifacts.model.CalculationResult;
teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes;
raimund@3035:
teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
teichmann@5831:
teichmann@5831: import org.dive4elements.river.utils.KMIndex;
sascha@3203:
sascha@3203: import org.apache.log4j.Logger;
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 FixAnalysisEventsFacet
bjoern@4442: extends FixingsFacet
raimund@3035: implements FacetTypes {
raimund@3035:
teichmann@8202: /** House log. */
teichmann@8202: private static Logger log = Logger.getLogger(FixAnalysisEventsFacet.class);
raimund@3035:
raimund@3035: /** Trivial Constructor. */
raimund@3035: public FixAnalysisEventsFacet() {
raimund@3035: }
raimund@3035:
raimund@3035:
raimund@3035: /**
raimund@3035: * @param name
raimund@3035: */
raimund@3043: public FixAnalysisEventsFacet(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("FixAnalysisEventsFacet.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: 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: FixAnalysisResult result = (FixAnalysisResult) res.getData();
teichmann@6868: double currentKm = getCurrentKm(context);
teichmann@6868:
teichmann@6868: KMIndex kmPeriods = result.getAnalysisPeriods();
teichmann@6868: KMIndex.Entry kmPeriodsEntry =
teichmann@6868: kmPeriods.binarySearch(currentKm);
teichmann@6868:
teichmann@6868: if (kmPeriodsEntry == null) {
teichmann@8202: log.debug("getData: kmPeriodsEntry == null");
teichmann@6868: return null;
teichmann@6868: }
teichmann@6868:
teichmann@6868: AnalysisPeriod[] periods = kmPeriodsEntry.getValue();
teichmann@6868: if (periods == null) {
teichmann@8202: log.debug("getData: periods == null");
teichmann@6868: return null;
teichmann@6868: }
teichmann@6868: int ndx = index >> 8;
teichmann@6868: QWD[] qwdData = periods[ndx].getQWDs();
teichmann@6868: if (qwdData == null) {
teichmann@6868: return null;
teichmann@6868: }
teichmann@6868: int ndy = index & 255;
teichmann@6868:
teichmann@6868: for (QWD qwd: qwdData) {
teichmann@6868: if (qwd.getIndex() == ndy) {
teichmann@6868: return qwd;
teichmann@6868: }
teichmann@6868: }
teichmann@6868: 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 FixAnalysisEventsFacet deepCopy() {
raimund@3035: FixAnalysisEventsFacet copy = new FixAnalysisEventsFacet();
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 :