raimund@3028: package de.intevation.flys.artifacts.model.fixings;
raimund@3028:
raimund@3028: import org.apache.log4j.Logger;
raimund@3028:
raimund@3028: import de.intevation.artifacts.Artifact;
raimund@3028: import de.intevation.artifacts.CallContext;
raimund@3028:
raimund@3028: import de.intevation.flys.artifacts.FLYSArtifact;
raimund@3028: import de.intevation.flys.artifacts.FixationArtifactAccess;
raimund@3028:
raimund@3028: import de.intevation.flys.artifacts.model.FacetTypes;
raimund@3028: import de.intevation.flys.artifacts.model.DataFacet;
raimund@3028: import de.intevation.flys.artifacts.model.CalculationResult;
raimund@3028:
raimund@3028: import de.intevation.flys.utils.KMIndex;
raimund@3028:
raimund@3028: import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
raimund@3028:
raimund@3028:
raimund@3028: /**
raimund@3028: * Facet to show average W values for Q sectors.
raimund@3028: *
raimund@3028: * @author Raimund Renkert
raimund@3028: */
raimund@3028: public class FixAvSectorFacet
raimund@3028: extends DataFacet
raimund@3028: implements FacetTypes {
raimund@3028:
raimund@3028: /** House logger. */
raimund@3028: private static Logger logger = Logger.getLogger(FixAvSectorFacet.class);
raimund@3028:
raimund@3028: /** Trivial Constructor. */
raimund@3028: public FixAvSectorFacet() {
raimund@3028: }
raimund@3028:
raimund@3028:
raimund@3043: public FixAvSectorFacet(int ndx, String name, String description) {
raimund@3028: super(
raimund@3028: ndx,
raimund@3043: name,
raimund@3028: description,
raimund@3028: ComputeType.ADVANCE,
raimund@3028: null,
raimund@3028: null);
raimund@3028: }
raimund@3028:
raimund@3028:
raimund@3028: /**
raimund@3028: * Returns the data this facet requires.
raimund@3028: *
raimund@3028: * @param artifact the owner artifact.
raimund@3028: * @param context the CallContext.
raimund@3028: *
raimund@3028: * @return the data as QWD array (QWD[]).
raimund@3028: */
raimund@3028: @Override
raimund@3028: public Object getData(Artifact artifact, CallContext context) {
raimund@3028: logger.debug("FixAvSectorFacet.getData");
raimund@3028:
raimund@3028: if (artifact instanceof FLYSArtifact) {
raimund@3028: FLYSArtifact flys = (FLYSArtifact)artifact;
raimund@3028: FixationArtifactAccess access = new FixationArtifactAccess(flys);
raimund@3028:
raimund@3028: CalculationResult res =
raimund@3028: (CalculationResult) flys.compute(context,
raimund@3028: ComputeType.ADVANCE,
raimund@3028: false);
raimund@3028:
raimund@3028: FixResult result = (FixResult) res.getData();
raimund@3028:
raimund@3028: double km = access.getCurrentKm();
raimund@3028:
raimund@3028: KMIndex kmPeriods = result.getAnalysisPeriods();
raimund@3028: AnalysisPeriod[] periods = kmPeriods.binarySearch(km).getValue();
raimund@3028:
raimund@3028: if (periods == null) {
raimund@3028: return null;
raimund@3028: }
raimund@3028: QWD[] qwdData = periods[index].getQSectorAverages();
raimund@3035: return qwdData;
raimund@3028: }
raimund@3028: else {
raimund@3028: logger.debug("Not an instance of FixationArtifact.");
raimund@3028: return null;
raimund@3028: }
raimund@3028: }
raimund@3028:
raimund@3028:
raimund@3028: /**
raimund@3028: * Create a deep copy of this Facet.
raimund@3028: * @return a deep copy.
raimund@3028: */
raimund@3028: @Override
raimund@3028: public FixAvSectorFacet deepCopy() {
raimund@3028: FixAvSectorFacet copy = new FixAvSectorFacet();
raimund@3028: copy.set(this);
raimund@3028: return copy;
raimund@3028: }
raimund@3028: }
raimund@3028: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :