1 22 23 package de.laures.cewolf.example; 24 25 import java.io.Serializable ; 26 import java.util.Date ; 27 import java.util.Map ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.jfree.data.xy.XYSeries; 32 import org.jfree.data.xy.XYSeriesCollection; 33 34 import de.laures.cewolf.DatasetProduceException; 35 import de.laures.cewolf.DatasetProducer; 36 37 41 public class RandomXYData implements DatasetProducer, Serializable { 42 43 private static final Log log = LogFactory.getLog(RandomXYData.class); 44 45 49 public Object produceDataset(Map params) throws DatasetProduceException { 50 log.debug("prodcing data."); 51 XYSeries xys = new XYSeries("Example XY Dataset"); 52 int maxVal = 100; 53 if (params.containsKey("maxVal")) { 54 maxVal = ((Integer )params.get("maxVal")).intValue(); 55 } 56 int minVal = -100; 57 if (params.containsKey("minVal")) { 58 minVal = ((Integer )params.get("minVal")).intValue(); 59 } 60 final int inset = (maxVal - minVal) / 2; 61 double last = maxVal - inset; 62 for (int i = -10; i <= 10; i++) { 63 final double y = Math.max(Math.min(last + ((Math.random() * inset) - inset / 2), maxVal), minVal); 64 xys.add(i, y); 65 last = y; 66 } 67 return new XYSeriesCollection(xys); 68 } 69 70 73 public boolean hasExpired(Map params, Date since) { 74 log.debug(this + ".hasExpired()"); 75 return false; 76 } 77 78 public String getProducerId(){ 79 return "RandomXYData DatsetProducer"; 80 } 81 82 } 83 | Popular Tags |