1 package de.laures.cewolf.dp; 2 3 import java.io.Serializable ; 4 import java.util.Date ; 5 import java.util.Map ; 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 24 public class MovingAverageDatasetProducer implements DatasetProducer, Serializable { 25 26 private static final Log log = LogFactory.getLog(MovingAverageDatasetProducer.class); 27 28 31 public Object produceDataset(Map 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 suffix = (String )params.get("suffix"); 37 int period = ((Integer )params.get("period")).intValue(); 38 int skip = ((Integer )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 49 public boolean hasExpired(Map params, Date since) { 50 return true; 51 } 52 53 56 public String getProducerId() { 57 return getClass().getName(); 58 } 59 60 } 61 | Popular Tags |