java/cewolf-1.0/src/main/java/de/laures/cewolf/dp/MovingAverageDatasetProducer.java
author František Kučera <franta-hg@frantovo.cz>
Sat Feb 28 21:31:02 2009 +0100 (2009-02-28)
changeset 1 639991d0808a
permissions -rw-r--r--
Rozbalená knihovna verze 1.0
franta-hg@1
     1
package de.laures.cewolf.dp;
franta-hg@1
     2
franta-hg@1
     3
import java.io.Serializable;
franta-hg@1
     4
import java.util.Date;
franta-hg@1
     5
import java.util.Map;
franta-hg@1
     6
franta-hg@1
     7
import org.apache.commons.logging.Log;
franta-hg@1
     8
import org.apache.commons.logging.LogFactory;
franta-hg@1
     9
import org.jfree.data.general.Dataset;
franta-hg@1
    10
import org.jfree.data.time.MovingAverage;
franta-hg@1
    11
import org.jfree.data.xy.XYDataset;
franta-hg@1
    12
franta-hg@1
    13
import de.laures.cewolf.DatasetProduceException;
franta-hg@1
    14
import de.laures.cewolf.DatasetProducer;
franta-hg@1
    15
franta-hg@1
    16
/**
franta-hg@1
    17
 * @author guido
franta-hg@1
    18
 *
franta-hg@1
    19
 * To change this generated comment edit the template variable "typecomment":
franta-hg@1
    20
 * Window>Preferences>Java>Templates.
franta-hg@1
    21
 * To enable and disable the creation of type comments go to
franta-hg@1
    22
 * Window>Preferences>Java>Code Generation.
franta-hg@1
    23
 */
franta-hg@1
    24
public class MovingAverageDatasetProducer implements DatasetProducer, Serializable {
franta-hg@1
    25
	
franta-hg@1
    26
	private static final Log log = LogFactory.getLog(MovingAverageDatasetProducer.class);
franta-hg@1
    27
franta-hg@1
    28
	/**
franta-hg@1
    29
	 * @see de.laures.cewolf.DatasetProducer#produceDataset(Map)
franta-hg@1
    30
	 */
franta-hg@1
    31
	public Object produceDataset(Map params) throws DatasetProduceException {
franta-hg@1
    32
		log.debug(params);
franta-hg@1
    33
		DatasetProducer datasetProducer = (DatasetProducer)params.get("producer");
franta-hg@1
    34
		log.debug(datasetProducer);
franta-hg@1
    35
		Dataset dataset = (Dataset)datasetProducer.produceDataset(params);
franta-hg@1
    36
		String suffix = (String)params.get("suffix");
franta-hg@1
    37
		int period = ((Integer)params.get("period")).intValue();
franta-hg@1
    38
		int skip = ((Integer)params.get("skip")).intValue();
franta-hg@1
    39
		if(dataset instanceof XYDataset){
franta-hg@1
    40
	        return MovingAverage.createMovingAverage((XYDataset)dataset, suffix, period, skip);
franta-hg@1
    41
		} else {
franta-hg@1
    42
			throw new DatasetProduceException("moving average only supported for XYDatasets");
franta-hg@1
    43
		}
franta-hg@1
    44
	}
franta-hg@1
    45
franta-hg@1
    46
	/**
franta-hg@1
    47
	 * @see de.laures.cewolf.DatasetProducer#hasExpired(Map, Date)
franta-hg@1
    48
	 */
franta-hg@1
    49
	public boolean hasExpired(Map params, Date since) {
franta-hg@1
    50
		return true;
franta-hg@1
    51
	}
franta-hg@1
    52
franta-hg@1
    53
	/**
franta-hg@1
    54
	 * @see de.laures.cewolf.DatasetProducer#getProducerId()
franta-hg@1
    55
	 */
franta-hg@1
    56
	public String getProducerId() {
franta-hg@1
    57
		return getClass().getName();
franta-hg@1
    58
	}
franta-hg@1
    59
franta-hg@1
    60
}