|
From: <sa...@us...> - 2003-10-09 08:48:28
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv866/jrobin/core
Modified Files:
Sample.java
Log Message:
Minor changes... added some shortcut methods
Index: Sample.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Sample.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Sample.java 4 Sep 2003 13:26:41 -0000 1.1
--- Sample.java 9 Oct 2003 08:48:23 -0000 1.2
***************
*** 24,27 ****
--- 24,28 ----
import java.io.IOException;
+ import java.util.StringTokenizer;
/**
***************
*** 57,63 ****
this.time = time;
this.dsNames = parentDb.getDsNames();
! int n = dsNames.length;
! values = new double[n];
! for(int i = 0; i < n; i++) {
values[i] = Double.NaN;
}
--- 58,67 ----
this.time = time;
this.dsNames = parentDb.getDsNames();
! values = new double[dsNames.length];
! clearCurrentValues();
! }
!
! private void clearCurrentValues() {
! for(int i = 0; i < values.length; i++) {
values[i] = Double.NaN;
}
***************
*** 71,75 ****
*/
public void setValue(String dsName, double value) throws RrdException {
! for(int i = 0; i < dsNames.length; i++) {
if(dsNames[i].equals(dsName)) {
values[i] = value;
--- 75,79 ----
*/
public void setValue(String dsName, double value) throws RrdException {
! for(int i = 0; i < values.length; i++) {
if(dsNames[i].equals(dsName)) {
values[i] = value;
***************
*** 88,92 ****
*/
public void setValue(int i, double value) throws RrdException {
! if(i < dsNames.length) {
values[i] = value;
return;
--- 92,96 ----
*/
public void setValue(int i, double value) throws RrdException {
! if(i < values.length) {
values[i] = value;
return;
***************
*** 96,116 ****
/**
! * Sets all data source values. You must supply values for all data sources defined in
! * a RRD file.
* @param values Data source values.
! * @throws RrdException Thrown if number of supplied values is different from number of
! * data sources defined in a RRD file.
*/
public void setValues(double[] values) throws RrdException {
! if(values.length == dsNames.length) {
! this.values = values;
! return;
}
- throw new RrdException("Invalid number of values specified (found " + values.length +
- ", exactly " + dsNames.length + " needed");
}
/**
! * Returns all data source values in the sample.
* @return Data source values.
*/
--- 100,124 ----
/**
! * Sets some (possibly all) data source values in bulk. Data source values are
! * assigned in the order of their definition inside the RRD file.
! *
* @param values Data source values.
! * @throws RrdException Thrown if the number of supplied values is zero or greater
! * than the number of data sources defined in the RRD file.
*/
public void setValues(double[] values) throws RrdException {
! if(values.length <= this.values.length) {
! for(int i = 0; i < values.length; i++) {
! this.values[i] = values[i];
! }
! }
! else {
! throw new RrdException("Invalid number of values specified (found " +
! values.length + ", only " + dsNames.length + " allowed)");
}
}
/**
! * Returns all current data source values in the sample.
* @return Data source values.
*/
***************
*** 145,149 ****
/**
! * Stores sample in the corresponding RRD file.
* @throws IOException Thrown in case of I/O error.
* @throws RrdException Thrown in case of JRobin related error.
--- 153,193 ----
/**
! * <p>Sets sample timestamp and data source values in a fashion similar to RRDTool.
! * Argument string should be composed in the following way:
! * <code>timestamp:value1:value2:...:valueN</code>.</p>
! *
! * <p>You don't have to supply all datasource values. Unspecified values will be treated
! * as unknowns. To specify unknown value in the argument string, use letter 'U'
! *
! * @param timeAndValues String made by concatenating sample timestamp with corresponding
! * data source values delmited with colons. For example:
! * <code>1005234132:12.2:35.6:U:24.5</code>
! * @throws RrdException Thrown if too many datasource values are supplied
! */
! public void set(String timeAndValues) throws RrdException {
! StringTokenizer st = new StringTokenizer(timeAndValues, ":", false);
! int numTokens = st.countTokens();
! String[] tokens = new String[numTokens];
! for(int i = 0; i < numTokens; i++) {
! tokens[i] = st.nextToken();
! }
! long time = Long.parseLong(tokens[0]);
! double[] values = new double[numTokens - 1];
! for(int i = 0; i < numTokens - 1; i++) {
! try {
! values[i] = Double.parseDouble(tokens[i + 1]);
! }
! catch(NumberFormatException nfe) {
! values[i] = Double.NaN;
! }
! }
! setTime(time);
! setValues(values);
! }
!
! /**
! * Stores sample in the corresponding RRD file. If the update operation succeedes,
! * all datasource values in the sample will be set to Double.NaN (unknown) values.
! *
* @throws IOException Thrown in case of I/O error.
* @throws RrdException Thrown in case of JRobin related error.
***************
*** 151,154 ****
--- 195,219 ----
public void update() throws IOException, RrdException {
parentDb.store(this);
+ clearCurrentValues();
+ }
+
+ /**
+ * <p>Creates sample with the timestamp and data source values supplied
+ * in the argument string and stores sample in the corresponding RRD file.
+ * This method is just a shortcut for:</p>
+ * <pre>
+ * set(timeAndValues);
+ * update();
+ * </pre>
+ * @param timeAndValues String made by concatenating sample timestamp with corresponding
+ * data source values delmited with colons. For example:
+ * <code>1005234132:12.2:35.6:U:24.5</code>
+ *
+ * @throws IOException Thrown in case of I/O error.
+ * @throws RrdException Thrown in case of JRobin related error.
+ */
+ public void setAndUpdate(String timeAndValues) throws IOException, RrdException {
+ set(timeAndValues);
+ update();
}
|