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  import java.util.concurrent.locks.ReentrantLock;
15  
16  import org.jfree.data.xy.XYDataItem;
17  import org.jfree.data.xy.XYSeries;
18  import org.slf4j.Logger;
19  import org.slf4j.LoggerFactory;
20  
21  /**
22   * The Class AbstractSeriesProvider.
23   */
24  public abstract class AbstractSeriesProvider implements SeriesProvider {
25  
26    /** The logger. */
27    protected final Logger logger = LoggerFactory.getLogger(getClass());
28  
29    /** The lock. */
30    private final ReentrantLock lockObj = new ReentrantLock();
31  
32    /**
33     * To series.
34     *
35     * @param legend the legend
36     * @param stats the stats
37     *
38     * @return the XY series
39     */
40    protected XYSeries toSeries(String legend, List<XYDataItem> stats) {
41      XYSeries xySeries = new XYSeries(legend, true, false);
42      lockObj.lock();
43      try {
44        for (XYDataItem item : stats) {
45          xySeries.addOrUpdate(item.getX(), item.getY());
46        }
47      } finally {
48        lockObj.unlock();
49      }
50      return xySeries;
51    }
52  
53  }