KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > laures > cewolf > dp > MovingAverageDatasetProducer


1 package de.laures.cewolf.dp;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Date JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 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, Serializable JavaDoc {
25     
26     private static final Log log = LogFactory.getLog(MovingAverageDatasetProducer.class);
27
28     /**
29      * @see de.laures.cewolf.DatasetProducer#produceDataset(Map)
30      */

31     public Object JavaDoc produceDataset(Map JavaDoc params) throws DatasetProduceException {
32         log.debug(params);
33         DatasetProducer datasetProducer = (DatasetProducer)params.get("producer");
34         log.debug(datasetProducer);
35         Dataset dataset = (Dataset)datasetProducer.produceDataset(params);
36         String JavaDoc suffix = (String JavaDoc)params.get("suffix");
37         int period = ((Integer JavaDoc)params.get("period")).intValue();
38         int skip = ((Integer JavaDoc)params.get("skip")).intValue();
39         if(dataset instanceof XYDataset){
40             return MovingAverage.createMovingAverage((XYDataset)dataset, suffix, period, skip);
41         } else {
42             throw new DatasetProduceException("moving average only supported for XYDatasets");
43         }
44     }
45
46     /**
47      * @see de.laures.cewolf.DatasetProducer#hasExpired(Map, Date)
48      */

49     public boolean hasExpired(Map JavaDoc params, Date JavaDoc since) {
50         return true;
51     }
52
53     /**
54      * @see de.laures.cewolf.DatasetProducer#getProducerId()
55      */

56     public String JavaDoc getProducerId() {
57         return getClass().getName();
58     }
59
60 }
61
Popular Tags