View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.beans.stats.providers;
12  
13  import java.util.List;
14  
15  import org.jfree.data.xy.XYDataItem;
16  import org.jfree.data.xy.XYSeries;
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  
20  /**
21   * The Class AbstractSeriesProvider.
22   */
23  public abstract class AbstractSeriesProvider implements SeriesProvider {
24  
25    /** The logger. */
26    protected final Logger logger = LoggerFactory.getLogger(getClass());
27  
28    /** The lock. */
29    private final Object lockObj = new Object();
30  
31    /**
32     * To series.
33     *
34     * @param legend the legend
35     * @param stats the stats
36     *
37     * @return the XY series
38     */
39    protected XYSeries toSeries(String legend, List<XYDataItem> stats) {
40      XYSeries xySeries = new XYSeries(legend, true, false);
41      synchronized (lockObj) {
42        for (XYDataItem item : stats) {
43          xySeries.addOrUpdate(item.getX(), item.getY());
44        }
45      }
46      return xySeries;
47    }
48  
49  }