java/cewolf-1.0/src/main/java/de/laures/cewolf/dp/MovingAverageDatasetProducer.java
changeset 1 639991d0808a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/dp/MovingAverageDatasetProducer.java	Sat Feb 28 21:31:02 2009 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +package de.laures.cewolf.dp;
     1.5 +
     1.6 +import java.io.Serializable;
     1.7 +import java.util.Date;
     1.8 +import java.util.Map;
     1.9 +
    1.10 +import org.apache.commons.logging.Log;
    1.11 +import org.apache.commons.logging.LogFactory;
    1.12 +import org.jfree.data.general.Dataset;
    1.13 +import org.jfree.data.time.MovingAverage;
    1.14 +import org.jfree.data.xy.XYDataset;
    1.15 +
    1.16 +import de.laures.cewolf.DatasetProduceException;
    1.17 +import de.laures.cewolf.DatasetProducer;
    1.18 +
    1.19 +/**
    1.20 + * @author guido
    1.21 + *
    1.22 + * To change this generated comment edit the template variable "typecomment":
    1.23 + * Window>Preferences>Java>Templates.
    1.24 + * To enable and disable the creation of type comments go to
    1.25 + * Window>Preferences>Java>Code Generation.
    1.26 + */
    1.27 +public class MovingAverageDatasetProducer implements DatasetProducer, Serializable {
    1.28 +	
    1.29 +	private static final Log log = LogFactory.getLog(MovingAverageDatasetProducer.class);
    1.30 +
    1.31 +	/**
    1.32 +	 * @see de.laures.cewolf.DatasetProducer#produceDataset(Map)
    1.33 +	 */
    1.34 +	public Object produceDataset(Map params) throws DatasetProduceException {
    1.35 +		log.debug(params);
    1.36 +		DatasetProducer datasetProducer = (DatasetProducer)params.get("producer");
    1.37 +		log.debug(datasetProducer);
    1.38 +		Dataset dataset = (Dataset)datasetProducer.produceDataset(params);
    1.39 +		String suffix = (String)params.get("suffix");
    1.40 +		int period = ((Integer)params.get("period")).intValue();
    1.41 +		int skip = ((Integer)params.get("skip")).intValue();
    1.42 +		if(dataset instanceof XYDataset){
    1.43 +	        return MovingAverage.createMovingAverage((XYDataset)dataset, suffix, period, skip);
    1.44 +		} else {
    1.45 +			throw new DatasetProduceException("moving average only supported for XYDatasets");
    1.46 +		}
    1.47 +	}
    1.48 +
    1.49 +	/**
    1.50 +	 * @see de.laures.cewolf.DatasetProducer#hasExpired(Map, Date)
    1.51 +	 */
    1.52 +	public boolean hasExpired(Map params, Date since) {
    1.53 +		return true;
    1.54 +	}
    1.55 +
    1.56 +	/**
    1.57 +	 * @see de.laures.cewolf.DatasetProducer#getProducerId()
    1.58 +	 */
    1.59 +	public String getProducerId() {
    1.60 +		return getClass().getName();
    1.61 +	}
    1.62 +
    1.63 +}