KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > io > RandomDataCollectorTimeStamped


1 /*
2  *
3  * RandomDataCollectorTimeStamped.java jchart2d
4  * Copyright (C) Achim Westermann, created on 20.03.2005, 16:59:10
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  *
23  */

24 package info.monitorenter.gui.chart.io;
25
26 import info.monitorenter.gui.chart.ITrace2D;
27 import info.monitorenter.gui.chart.TracePoint2D;
28
29
30 /**
31  * Data collector that collects values with an absolute timestamp as x value and
32  * a random jumping y value.
33  * <p>
34  *
35  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
36  *
37  * @version $Revision: 1.2 $
38  */

39 public class RandomDataCollectorTimeStamped extends ADataCollector {
40
41   /** The last collected y value. */
42   private double m_y = 0.0;
43
44   /**
45    * Creates an instance that will collect every latency ms a point and add it
46    * to the trace.
47    * <p>
48    *
49    * @param trace
50    * the trace to add collected points to.
51    *
52    * @param latency
53    * the interval in ms for collecting points.
54    */

55   public RandomDataCollectorTimeStamped(final ITrace2D trace, final int latency) {
56     super(trace, latency);
57   }
58
59   /**
60    * @see ADataCollector#collectData()
61    */

62   public TracePoint2D collectData() {
63     double rand = Math.random();
64     boolean add = (rand >= 0.5) ? true : false;
65     this.m_y = (add) ? this.m_y + Math.random() : this.m_y - Math.random();
66     return new TracePoint2D((double) System.currentTimeMillis(), this.m_y);
67   }
68 }
69
Popular Tags