teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.minfo; ingo@3757: ingo@3757: import org.apache.log4j.Logger; ingo@3757: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; 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.DataFacet; teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; ingo@3757: ingo@3757: ingo@3757: /** ingo@3757: * Facet for serving bedload diameter data. sascha@3772: * ingo@3757: * @author Ingo Weinzierl ingo@3757: */ ingo@3757: public class BedloadDiameterFacet extends DataFacet { ingo@3757: ingo@3757: private static final long serialVersionUID = 1L; sascha@3772: ingo@3757: private static Logger logger = Logger.getLogger(BedloadDiameterFacet.class); ingo@3757: ingo@3757: public BedloadDiameterFacet() { ingo@3757: // required for clone operation deepCopy() ingo@3757: } ingo@3757: ingo@3757: public BedloadDiameterFacet(int idx, String name, String description, ingo@3757: ComputeType type, String stateId, String hash) { ingo@3757: super(idx, name, description, type, hash, stateId); ingo@3757: } ingo@3757: ingo@3757: public Object getData(Artifact artifact, CallContext context) { ingo@3757: logger.debug("Get data for bedload diameter at index: " + index); ingo@3757: teichmann@5867: D4EArtifact flys = (D4EArtifact) artifact; ingo@3757: ingo@3757: CalculationResult res = (CalculationResult) flys.compute(context, hash, ingo@3757: stateId, type, false); ingo@3757: ingo@3784: int ndx = index >> 8; ingo@3784: Object[] data = ingo@3784: ((BedQualityResult[]) res.getData())[ndx].getBedloadResults(); // TODO CAST TO SPECIFIC CLASS ingo@3757: ingo@3784: int ndy = index & 255; ingo@3784: return data != null && data.length > ndy ? data[ndy] : null; ingo@3757: } ingo@3757: ingo@3757: /** Copy deeply. */ ingo@3757: @Override ingo@3757: public Facet deepCopy() { ingo@3757: BedloadDiameterFacet copy = new BedloadDiameterFacet(); ingo@3757: copy.set(this); ingo@3757: copy.type = type; ingo@3757: copy.hash = hash; ingo@3757: copy.stateId = stateId; ingo@3757: return copy; ingo@3757: } ingo@3757: } ingo@3757: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :