001    /*
002     * Copyright (C) 2001 Ciaran Treanor <ciaran@codeloop.com>
003     *
004     * Distributable under GPL license.
005     * See terms of license at gnu.org.
006     *
007     * $Id: DataChunk.java,v 1.3 2006/12/21 18:02:42 tarus Exp $
008     */
009    package org.jrobin.core.jrrd;
010    
011    /**
012     * Models a chunk of result data from an RRDatabase.
013     *
014     * @author <a href="mailto:ciaran@codeloop.com">Ciaran Treanor</a>
015     * @version $Revision: 1.3 $
016     */
017    public class DataChunk {
018    
019            private static final String NEWLINE = System.getProperty("line.separator");
020            long startTime;
021            int start;
022            int end;
023            long step;
024            int dsCount;
025            double[][] data;
026            int rows;
027    
028            DataChunk(long startTime, int start, int end, long step, int dsCount, int rows) {
029                    this.startTime = startTime;
030                    this.start = start;
031                    this.end = end;
032                    this.step = step;
033                    this.dsCount = dsCount;
034                    this.rows = rows;
035                    data = new double[rows][dsCount];
036            }
037    
038            /**
039             * Returns a summary of the contents of this data chunk. The first column is
040             * the time (RRD format) and the following columns are the data source
041             * values.
042             *
043             * @return a summary of the contents of this data chunk.
044             */
045            public String toString() {
046    
047                    StringBuffer sb = new StringBuffer();
048                    long time = startTime;
049    
050                    for (int row = 0; row < rows; row++, time += step) {
051                            sb.append(time);
052                            sb.append(": ");
053    
054                            for (int ds = 0; ds < dsCount; ds++) {
055                                    sb.append(data[row][ds]);
056                                    sb.append(" ");
057                            }
058    
059                            sb.append(NEWLINE);
060                    }
061    
062                    return sb.toString();
063            }
064    }