view artifacts/src/main/java/org/dive4elements/river/artifacts/FixationArtifact.java @ 9425:3f49835a00c3

Extended CrossSectionFacet so it may fetch different data from within the artifact result. Also allows to have acces to the potentially already computed artifact result via its normal computation cache.
author gernotbelger
date Fri, 17 Aug 2018 15:31:02 +0200
parents 5e38e2924c07
children 8d6e56e57c4a
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts;

import java.io.Serializable;

import org.apache.log4j.Logger;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.WKms;
import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;

/**
 * The default fixation analysis artifact.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class FixationArtifact extends D4EArtifact implements WaterLineArtifact {

    private static final long serialVersionUID = 1L;

    /** The log for this class. */
    private static Logger log = Logger.getLogger(FixationArtifact.class);

    /** The name of the artifact. */
    private static final String ARTIFACT_NAME = "fixanalysis";

    /* FacetActivity for this artifact is registered in FixAnalysisCompute . */

    /**
     * The default constructor.
     */
    public FixationArtifact() {
        log.debug("ctor()");
    }

    /**
     * Returns the name of the concrete artifact.
     *
     * @return the name of the concrete artifact.
     */
    @Override
    public String getName() {
        return ARTIFACT_NAME;
    }

    /** Calculate waterlines against a cross section. */
    @Override
    public double getWaterLevel(final ComputeType type, final String hash, final String stateId, final double currentKm, final Serializable waterLineIndex,
            final double nextKm, final double prevKm, final CallContext context) {
        final FixRealizingResult result = (FixRealizingResult) ((CalculationResult) this.compute(context, ComputeType.ADVANCE, false)).getData();

        final int wstIndex = (Integer) waterLineIndex;

        final WKms wkms = result.getWQKms()[wstIndex];

        // Find W at km.
        final double wAtKm = StaticWKmsArtifact.getWAtKm(wkms, currentKm);

        if (wAtKm == -1 || Double.isNaN(wAtKm)) {
            log.warn("Waterlevel at km " + currentKm + " unknown.");
            return Double.NaN;
        }

        return wAtKm;
    }
}

http://dive4elements.wald.intevation.org