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: gernotbelger@9415: import org.apache.commons.lang.math.DoubleRange; ingo@3466: import org.apache.log4j.Logger; 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; 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: */ gernotbelger@9415: public class FixReferenceEventsFacet extends FixingsEventFacet implements FacetTypes { gernotbelger@9415: gernotbelger@9415: private static final long serialVersionUID = 1L; raimund@3035: teichmann@8202: /** House log. */ teichmann@8202: private static Logger log = Logger.getLogger(FixReferenceEventsFacet.class); raimund@3035: gernotbelger@9415: private int columnId; gernotbelger@9415: raimund@3035: /** Trivial Constructor. */ raimund@3035: public FixReferenceEventsFacet() { raimund@3035: } raimund@3035: gernotbelger@9415: public FixReferenceEventsFacet(final int facetIndex, final int columnId, final String name, final String description, final DoubleRange stationRange) { gernotbelger@9415: super(facetIndex, name, description, ComputeType.ADVANCE, null, null, stationRange); gernotbelger@9415: gernotbelger@9415: this.columnId = columnId; raimund@3035: } raimund@3035: raimund@3035: /** raimund@3035: * Returns the data this facet requires. raimund@3035: * gernotbelger@9348: * @param artifact gernotbelger@9348: * the owner artifact. gernotbelger@9348: * @param context gernotbelger@9348: * the CallContext (ignored). raimund@3035: * raimund@3035: * @return the data. raimund@3035: */ raimund@3035: @Override gernotbelger@9348: public Object getData(final Artifact artifact, final 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: gernotbelger@9348: final D4EArtifact flys = (D4EArtifact) artifact; teichmann@6868: gernotbelger@9348: final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); teichmann@6868: gernotbelger@9348: final FixResult result = (FixResult) res.getData(); gernotbelger@9348: final double currentKm = getCurrentKm(context); teichmann@6868: gernotbelger@9360: if (log.isDebugEnabled()) teichmann@8202: log.debug("current km in FRE: " + currentKm); teichmann@6868: gernotbelger@9415: final FixResultColumns resultColumns = result.getFixResultColumns(); gernotbelger@9415: final FixResultColumn event = resultColumns.getColumn(this.columnId); gernotbelger@9415: if (event == null) { gernotbelger@9415: log.error("Missing event with columnId: " + this.columnId); gernotbelger@9415: return null; gernotbelger@9348: } gernotbelger@9348: gernotbelger@9415: return event.getQWD(currentKm); gernotbelger@9348: } raimund@3035: raimund@3035: /** raimund@3035: * Create a deep copy of this Facet. gernotbelger@9348: * raimund@3035: * @return a deep copy. raimund@3035: */ raimund@3035: @Override raimund@3035: public FixReferenceEventsFacet deepCopy() { gernotbelger@9348: final FixReferenceEventsFacet copy = new FixReferenceEventsFacet(); raimund@3035: copy.set(this); gernotbelger@9415: copy.columnId = this.columnId; raimund@3035: return copy; raimund@3035: } gernotbelger@9348: }