KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jrobin > core > jrrd > DataChunk


1 /*
2  * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
3  *
4  * Distributable under GPL license.
5  * See terms of license at gnu.org.
6  *
7  * $Id: DataChunk.java,v 1.1 2004/07/22 09:34:10 saxon64 Exp $
8  */

9 package org.jrobin.core.jrrd;
10
11 /**
12  * Models a chunk of result data from an RRDatabase.
13  *
14  * @author <a HREF="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
15  * @version $Revision: 1.1 $
16  */

17 public class DataChunk {
18
19     private static final String JavaDoc NEWLINE = System.getProperty("line.separator");
20     long startTime;
21     int start;
22     int end;
23     long step;
24     int dsCount;
25     double[][] data;
26     int rows;
27
28     DataChunk(long startTime, int start, int end, long step, int dsCount, int rows) {
29         this.startTime = startTime;
30         this.start = start;
31         this.end = end;
32         this.step = step;
33         this.dsCount = dsCount;
34         this.rows = rows;
35         data = new double[rows][dsCount];
36     }
37
38     /**
39      * Returns a summary of the contents of this data chunk. The first column is
40      * the time (RRD format) and the following columns are the data source
41      * values.
42      *
43      * @return a summary of the contents of this data chunk.
44      */

45     public String JavaDoc toString() {
46
47         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
48         long time = startTime;
49
50         for (int row = 0; row < rows; row++, time += step) {
51             sb.append(time);
52             sb.append(": ");
53
54             for (int ds = 0; ds < dsCount; ds++) {
55                 sb.append(data[row][ds]);
56                 sb.append(" ");
57             }
58
59             sb.append(NEWLINE);
60         }
61
62         return sb.toString();
63     }
64 }
65
Popular Tags