KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  *
3  * RandomDataCollector.java jchart2d
4  * Copyright (C) Achim Westermann, created on 10.12.2004, 15:04:16
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  * <p>
32  * A proof of concept dummy implementation for the supertype. Only collects
33  * random values with timestamp on the x axis. The timestamp is related to the
34  * time when this instance is instantiated to make it a lower value (offset to
35  * start). implementation for exact timestamps that may be formatted with
36  * java.text.DateFormat instances.
37  * </p>
38  *
39  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
40  *
41  * @version $Revision: 1.2 $
42  */

43 public class RandomDataCollectorOffset extends ADataCollector {
44
45   /** The start tiime of this collector. */
46   private long m_starttime = System.currentTimeMillis();
47
48   /** The last y value added. */
49   private double m_y = 0.0;
50
51   /**
52    * Creates a collector that collectes every latency ms a point and adds it to
53    * the trace.
54    * <p>
55    *
56    * @param trace
57    * the trace to add points to.
58    *
59    * @param latency
60    * the interval for collection of points.
61    */

62   public RandomDataCollectorOffset(final ITrace2D trace, final int latency) {
63     super(trace, latency);
64   }
65
66   /**
67    * @see ADataCollector#collectData()
68    */

69   public TracePoint2D collectData() {
70     double rand = Math.random();
71     boolean add = (rand >= 0.5) ? true : false;
72     this.m_y = (add) ? this.m_y + Math.random() : this.m_y - Math.random();
73     return new TracePoint2D(((double) System.currentTimeMillis() - this.m_starttime), this.m_y);
74   }
75 }
76
Popular Tags