01: package de.laures.cewolf.dp;
02:
03: import java.io.Serializable;
04: import java.util.Date;
05: import java.util.Map;
06:
07: import org.apache.commons.logging.Log;
08: import org.apache.commons.logging.LogFactory;
09: import org.jfree.data.general.Dataset;
10: import org.jfree.data.time.MovingAverage;
11: import org.jfree.data.xy.XYDataset;
12:
13: import de.laures.cewolf.DatasetProduceException;
14: import de.laures.cewolf.DatasetProducer;
15:
16: /**
17: * @author guido
18: *
19: * To change this generated comment edit the template variable "typecomment":
20: * Window>Preferences>Java>Templates.
21: * To enable and disable the creation of type comments go to
22: * Window>Preferences>Java>Code Generation.
23: */
24: public class MovingAverageDatasetProducer implements DatasetProducer,
25: Serializable {
26:
27: private static final Log log = LogFactory
28: .getLog(MovingAverageDatasetProducer.class);
29:
30: /**
31: * @see de.laures.cewolf.DatasetProducer#produceDataset(Map)
32: */
33: public Object produceDataset(Map params)
34: throws DatasetProduceException {
35: log.debug(params);
36: DatasetProducer datasetProducer = (DatasetProducer) params
37: .get("producer");
38: log.debug(datasetProducer);
39: Dataset dataset = (Dataset) datasetProducer
40: .produceDataset(params);
41: String suffix = (String) params.get("suffix");
42: int period = ((Integer) params.get("period")).intValue();
43: int skip = ((Integer) params.get("skip")).intValue();
44: if (dataset instanceof XYDataset) {
45: return MovingAverage.createMovingAverage(
46: (XYDataset) dataset, suffix, period, skip);
47: } else {
48: throw new DatasetProduceException(
49: "moving average only supported for XYDatasets");
50: }
51: }
52:
53: /**
54: * @see de.laures.cewolf.DatasetProducer#hasExpired(Map, Date)
55: */
56: public boolean hasExpired(Map params, Date since) {
57: return true;
58: }
59:
60: /**
61: * @see de.laures.cewolf.DatasetProducer#getProducerId()
62: */
63: public String getProducerId() {
64: return getClass().getName();
65: }
66:
67: }
|