KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > core > FetchPoint


1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info: http://www.jrobin.org
6  * Project Lead: Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003, by Sasa Markovic.
9  *
10  * Developers: Sasa Markovic (saxon@jrobin.org)
11  * Arne Vandamme (cobralord@jrobin.org)
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25
26 package org.jrobin.core;
27
28 /**
29  * Class to represent data source values for the specific timestamp. Objects of this class
30  * are created during the fetching process. See {@link org.jrobin.core.FetchRequest#fetch() fetch()}
31  * method of the {@link org.jrobin.core.FetchRequest FetchRequest} class.
32  *
33  * @author <a HREF="mailto:saxon@jrobin.org">Sasa Markovic</a>
34  * @deprecated This class is deprecated since 1.2.0 and might be removed from future releases
35  * of JRobin. You don't need this class if you fetch RRD data with the
36  * {@link org.jrobin.core.FetchRequest#fetchData() fetchData()} method from the
37  * {@link org.jrobin.core.FetchRequest FetchRequest} class
38  */

39 public class FetchPoint {
40
41     private long time;
42     private double[] values;
43
44     FetchPoint(long time, int size) {
45         this.time = time;
46         values = new double[size];
47         for(int i = 0; i < size; i++) {
48             values[i] = Double.NaN;
49         }
50     }
51
52     /**
53      * Returns timestamp associated with this fetch point.
54      * @return Timestamp in seconds.
55      */

56     public long getTime() {
57         return time;
58     }
59
60     /**
61      * Returns array of data source values for the associated timestamp. Data source values
62      * are returned in the order of their definition.
63      *
64      * @return Array of data source values.
65      */

66     public double[] getValues() {
67         return values;
68     }
69
70     /**
71      * Returns number of data source values (same as number od data sources defined in RRD).
72      * @return Number of data source values.
73      */

74     public int getSize() {
75         return values.length;
76     }
77
78     /**
79      * Returns the i-th data source value. Data source values follow the order of
80      * data sources definition.
81      * @param i Data source index.
82      * @return Value of the i-th data source.
83      */

84     public double getValue(int i) {
85         return values[i];
86     }
87
88     void setValue(int index, double value) {
89         values[index] = value;
90     }
91
92     /**
93      * Returns string representing timestamp and all data source values.
94      * @return Fetch point dump.
95      */

96     public String JavaDoc dump() {
97         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(time + ": ");
98         for(int i = 0; i < values.length; i++) {
99             buffer.append(Util.formatDouble(values[i], true));
100             buffer.append(" ");
101         }
102         return buffer.toString();
103     }
104
105     /**
106      * Returns string representing timestamp and all data source values.
107      * @return Fetch point dump.
108      */

109     public String JavaDoc toString() {
110         return dump();
111     }
112 }
113
Popular Tags