## org.jrobin.core
Class FetchData

    java.lang.Object
      org.jrobin.core.FetchData

All Implemented Interfaces:
  RrdDataSet

public class FetchData
extends java.lang.Object
implements RrdDataSet

Class used to represent data fetched from the RRD. Object of this class is created when the method `fetchData()` is called on a `FetchRequest` object.

Data returned from the RRD is, simply, just one big table filled with timestamps and corresponding datasource values. Use `getRowCount()` method to count the number of returned timestamps (table rows).

The first table column is filled with timestamps. Time intervals between consecutive timestamps are guaranteed to be equal. Use `getTimestamps()` method to get an array of timestamps returned.

Remaining columns are filled with datasource values for the whole timestamp range, on a column-per-datasource basis. Use `getColumnCount()` to find the number of datasources and `getValues(i)` method to obtain all values for the i-th datasource. Returned datasource values correspond to the values returned with `getTimestamps()` method.

Method Summary
`void` `dump()` Dumps the content of the whole FetchData object to stdout.
`java.lang.String` `exportXml()` Dumps fetch data in XML format.
`void` `exportXml(java.io.OutputStream outputStream)` Dumps fetch data to output stream in XML format.
`void` `exportXml(java.lang.String filepath)` Dumps fetch data to file in XML format.
`double` `getAggregate(java.lang.String dsName, java.lang.String consolFun)` Returns aggregated value from the fetched data for a single datasource.
`double` `getAggregate(java.lang.String dsName, java.lang.String consolFun, java.lang.String rpnExpression)` Returns aggregated value from the fetched data for a single datasource.
`int` `getColumnCount()` Returns the number of columns fetched from the corresponding RRD.
`int` `getDsIndex(java.lang.String dsName)` Retrieve the table index number of a datasource by name.
`java.lang.String[]` `getDsNames()` Returns array of datasource names found in the corresponding RRD.
`long` `getFirstTimestamp()` Returns the first timestamp in this FetchData object.
`long` `getLastTimestamp()` Returns the last timestamp in this FecthData object.
`Archive` `getMatchingArchive()` Returns Archive object which is determined to be the best match for the timestamps specified in the fetch request.
`FetchRequest` `getRequest()` Returns `FetchRequest` object used to create this FetchData object.
`FetchPoint` `getRow(int rowIndex)` Returns the number of rows fetched from the corresponding RRD.
`int` `getRowCount()` Returns the number of rows fetched from the corresponding RRD.
`long` `getStep()` Returns the step with which this data was fetched.
`long[]` `getTimestamps()` Returns an array of timestamps covering the whole range specified in the `FetchReguest` object.
`double[][]` `getValues()` Returns all archived values for all datasources.
`double[]` `getValues(int dsIndex)` Returns all archived values for a single datasource.
`double[]` `getValues(java.lang.String dsName)` Returns all archived values for a single datasource.
`java.lang.String` `toString()` Returns string representing fetched data in a RRDTool-like form.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Method Detail

### getRowCount

    public int getRowCount()

  Returns the number of rows fetched from the corresponding RRD. Each row represents datasource values for the specific timestamp.

  Specified by:
    `getRowCount` in interface `RrdDataSet`
  Returns:
    Number of rows.

### getColumnCount

    public int getColumnCount()

  Returns the number of columns fetched from the corresponding RRD. This number is always equal to the number of datasources defined in the RRD. Each column represents values of a single datasource.

  Specified by:
    `getColumnCount` in interface `RrdDataSet`
  Returns:
    Number of columns (datasources).

### getRow

    public FetchPoint getRow(int rowIndex)

  Returns the number of rows fetched from the corresponding RRD. Each row represents datasource values for the specific timestamp.

  Parameters:
    `rowIndex` - Row index.
  Returns:
    FetchPoint object which represents datasource values for the specific timestamp.

### getTimestamps

    public long[] getTimestamps()

  Returns an array of timestamps covering the whole range specified in the `FetchReguest` object.

  Specified by:
    `getTimestamps` in interface `RrdDataSet`
  Returns:
    Array of equidistant timestamps.

### getStep

    public long getStep()

  Returns the step with which this data was fetched.

  Specified by:
    `getStep` in interface `RrdDataSet`
  Returns:
    Step as long.

### getValues

    public double[] getValues(int dsIndex)

  Returns all archived values for a single datasource. Returned values correspond to timestamps returned with `getTimestamps()` method.

  Specified by:
    `getValues` in interface `RrdDataSet`
  Parameters:
    `dsIndex` - Datasource index.
  Returns:
    Array of single datasource values.

### getValues

    public double[][] getValues()

  Returns all archived values for all datasources. Returned values correspond to timestamps returned with `getTimestamps()` method.

  Specified by:
    `getValues` in interface `RrdDataSet`
  Returns:
    Two-dimensional aray of all datasource values.

### getValues

    public double[] getValues(java.lang.String dsName)
                       throws RrdException

  Returns all archived values for a single datasource. Returned values correspond to timestamps returned with `getTimestamps()` method.

  Specified by:
    `getValues` in interface `RrdDataSet`
  Parameters:
    `dsName` - Datasource name.
  Returns:
    Array of single datasource values.
  Throws:
    `RrdException` - Thrown if no matching datasource name is found.

### getRequest

    public FetchRequest getRequest()

  Returns `FetchRequest` object used to create this FetchData object.

  Returns:
    Fetch request object.

### getFirstTimestamp

    public long getFirstTimestamp()

  Returns the first timestamp in this FetchData object.

  Specified by:
    `getFirstTimestamp` in interface `RrdDataSet`
  Returns:
    The smallest timestamp.

### getLastTimestamp

    public long getLastTimestamp()

  Returns the last timestamp in this FecthData object.

  Specified by:
    `getLastTimestamp` in interface `RrdDataSet`
  Returns:
    The biggest timestamp.

### getMatchingArchive

    public Archive getMatchingArchive()

  Returns Archive object which is determined to be the best match for the timestamps specified in the fetch request. All datasource values are obtained from round robin archives belonging to this archive.

  Returns:
    Matching archive.

### getDsNames

    public java.lang.String[] getDsNames()

  Returns array of datasource names found in the corresponding RRD. If the request was filtered (data was fetched only for selected datasources), only datasources selected for fetching are returned.

  Specified by:
    `getDsNames` in interface `RrdDataSet`
  Returns:
    Array of datasource names.

### getDsIndex

    public int getDsIndex(java.lang.String dsName)

  Retrieve the table index number of a datasource by name. Names are case sensitive.

  Specified by:
    `getDsIndex` in interface `RrdDataSet`
  Parameters:
    `dsName` - Name of the datasource for which to find the index.
  Returns:
    Index number of the datasources in the value table.

### dump

    public void dump()

  Dumps the content of the whole FetchData object to stdout. Useful for debugging.

### toString

    public java.lang.String toString()

  Returns string representing fetched data in a RRDTool-like form.

  Returns:
    Fetched data as a string in a rrdfetch-like output form.

### getAggregate

    public double getAggregate(java.lang.String dsName,
                               java.lang.String consolFun)
                        throws RrdException

  Returns aggregated value from the fetched data for a single datasource.

  Specified by:
    `getAggregate` in interface `RrdDataSet`
  Parameters:
    `dsName` - Datasource name
    `consolFun` - Consolidation function to be applied to fetched datasource values. Valid consolidation functions are MIN, MAX, LAST and AVERAGE
  Returns:
    MIN, MAX, LAST or AVERAGE value calculated from the fetched data for the given datasource name
  Throws:
    `RrdException` - Thrown if the given datasource name cannot be found in fetched data.

### getAggregate

    public double getAggregate(java.lang.String dsName,
                               java.lang.String consolFun,
                               java.lang.String rpnExpression)
                        throws RrdException

  Returns aggregated value from the fetched data for a single datasource. Before applying aggrregation functions, specified RPN expression is applied to fetched data. For example, if you have a gauge datasource named 'foots' but you wont to find the maximum fetched value in meters use something like: `getAggregate("foots", "MAX", "value,0.3048,*");` Note that 'value' in the RPN expression is a reserved word and stands for the original value (value fetched from RRD)

  Parameters:
    `dsName` - Datasource name
    `consolFun` - Consolidation function to be applied to fetched datasource values. Valid consolidation functions are MIN, MAX, LAST and AVERAGE
  Returns:
    MIN, MAX, LAST or AVERAGE value calculated from the fetched data for the given datasource name
  Throws:
    `RrdException` - Thrown if the given datasource name cannot be found in fetched data.

### exportXml

    public void exportXml(java.io.OutputStream outputStream)
                   throws java.io.IOException

  Dumps fetch data to output stream in XML format.

  Specified by:
    `exportXml` in interface `RrdDataSet`
  Parameters:
    `outputStream` - Output stream to dump fetch data to
  Throws:
    `java.io.IOException` - Thrown in case of I/O error

### exportXml

    public void exportXml(java.lang.String filepath)
                   throws java.io.IOException

  Dumps fetch data to file in XML format.

  Specified by:
    `exportXml` in interface `RrdDataSet`
  Parameters:
    `filepath` - Path to destination file
  Throws:
    `java.io.IOException` - Thrown in case of I/O error

### exportXml

    public java.lang.String exportXml()
                               throws java.io.IOException

  Dumps fetch data in XML format.

  Specified by:
    `exportXml` in interface `RrdDataSet`
  Returns:
    String containing XML formatted fetch data
  Throws:
    `java.io.IOException` - Thrown in case of I/O error