view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents cdbc457e23e2
children 6bfed02f025f
line wrap: on
line source
package de.intevation.flys.artifacts.states;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import de.intevation.artifacts.CallContext;

import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.access.BedHeightAccess;
import de.intevation.flys.artifacts.model.CalculationResult;
import de.intevation.flys.artifacts.model.DataFacet;
import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.model.MiddleBedHeightData;
import de.intevation.flys.artifacts.model.MiddleBedHeightFacet;
import de.intevation.flys.artifacts.model.MiddleBedHeightCalculation;


public class MiddleBedHeight extends DefaultState implements FacetTypes {

    private static final Logger logger = Logger.getLogger(MiddleBedHeight.class);


    @Override
    public Object computeAdvance(
        FLYSArtifact artifact,
        String       hash,
        CallContext  context,
        List<Facet>  facets,
        Object       old
    ) {
        logger.debug("MiddleBedHeight.computeAdvance");

        List<Facet> newFacets = new ArrayList<Facet>();

        BedHeightAccess access = new BedHeightAccess(artifact);

        CalculationResult res = old instanceof CalculationResult
            ? (CalculationResult) old
            : new MiddleBedHeightCalculation().calculate(access);

        if (facets == null || res == null) {
            return res;
        }

        MiddleBedHeightData[] data = (MiddleBedHeightData[]) res.getData();

        logger.debug("Calculated " + data.length + " MiddleBedHeightData objects");

        String id  = getID();
        int    idx = 0;

        for (MiddleBedHeightData d: data) {
            if (d.getStartYear() == d.getEndYear()) {
                newFacets.add(new MiddleBedHeightFacet(
                    idx,
                    MIDDLE_BED_HEIGHT_SINGLE,
                    d.getSoundingName(context),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
            }
            else {
                newFacets.add(new MiddleBedHeightFacet(
                    idx,
                    MIDDLE_BED_HEIGHT_EPOCH,
                    d.getSoundingName(context),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
            }

            idx++;
        }

        Facet csv = new DataFacet(
            CSV, "CSV data", ComputeType.ADVANCE, hash, id);

        // TODO ADD PDF FACET

        newFacets.add(csv);

        logger.debug("Created " + newFacets.size() + " new Facets.");

        facets.addAll(newFacets);

        return res;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org