org.jfree.data
Class DatasetUtilities

java.lang.Object
  |
  +--org.jfree.data.DatasetUtilities

public class DatasetUtilities
extends java.lang.Object

A collection of useful static methods relating to datasets.

Author:
David Gilbert

Constructor Summary
DatasetUtilities()
           
 
Method Summary
static CategoryDataset createCategoryDataset(java.lang.String rowKey, KeyedValues rowData)
          Creates a CategoryDataset by copying the data from the supplied KeyedValues instance.
static CategoryDataset createCategoryDataset(java.lang.String rowKeyPrefix, java.lang.String columnKeyPrefix, double[][] data)
          Creates a CategoryDataset that contains a copy of the data in an array (instances of Double are created to represent the data items).
static CategoryDataset createCategoryDataset(java.lang.String rowKeyPrefix, java.lang.String columnKeyPrefix, java.lang.Number[][] data)
          Creates a CategoryDataset that contains a copy of the data in an array.
static java.lang.Number[] createNumberArray(double[] data)
          Constructs an array of Number objects from an array of double primitives.
static java.lang.Number[][] createNumberArray2D(double[][] data)
          Constructs an array of arrays of Number objects from a corresponding structure containing double primitives.
static PieDataset createPieDatasetForColumn(CategoryDataset data, java.lang.Comparable columnKey)
          Creates a pie dataset from a table dataset by taking all the values for a single column.
static PieDataset createPieDatasetForColumn(CategoryDataset data, int column)
          Creates a pie dataset from a table dataset by taking all the values for a single column.
static PieDataset createPieDatasetForRow(CategoryDataset data, java.lang.Comparable rowKey)
          Creates a pie dataset from a table dataset by taking all the values for a single row.
static PieDataset createPieDatasetForRow(CategoryDataset data, int row)
          Creates a pie dataset from a table dataset by taking all the values for a single row.
static Range getDomainExtent(Dataset data)
          Returns the range of values in the domain for the dataset.
static java.lang.Number getMaximumDomainValue(Dataset data)
          Returns the maximum domain value for the specified dataset.
static java.lang.Number getMaximumRangeValue(Dataset data)
          Returns the maximum range value for the specified dataset.
static java.lang.Number getMaximumStackedRangeValue(CategoryDataset data)
          Returns the maximum value in the dataset range, assuming that values in each category are "stacked".
static java.lang.Number getMinimumDomainValue(Dataset data)
          Returns the minimum domain value for the specified dataset.
static java.lang.Number getMinimumRangeValue(Dataset data)
          Returns the minimum range value for the specified dataset.
static java.lang.Number getMinimumStackedRangeValue(CategoryDataset data)
          Returns the minimum value in the dataset range, assuming that values in each category are "stacked".
static double getPieDatasetTotal(PieDataset data)
          Calculates the total of all the values in a PieDataset.
static Range getRangeExtent(Dataset data)
          Returns the range of values in the range for the dataset.
static Range getStackedRangeExtent(CategoryDataset data)
          Returns the minimum and maximum values for the dataset's range (as in domain/range), assuming that the series in one category are stacked.
static boolean isEmpty(XYDataset data)
          Returns true if the dataset is empty, and false otherwise.
static XYDataset sampleFunction2D(Function2D f, double start, double end, int samples, java.lang.String seriesName)
          Creates an XYDataset by sampling the specified function over a fixed range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatasetUtilities

public DatasetUtilities()
Method Detail

createNumberArray

public static java.lang.Number[] createNumberArray(double[] data)
Constructs an array of Number objects from an array of double primitives.

Parameters:
data - the data.
Returns:
an array of Double.

createNumberArray2D

public static java.lang.Number[][] createNumberArray2D(double[][] data)
Constructs an array of arrays of Number objects from a corresponding structure containing double primitives.

Parameters:
data - the data.
Returns:
an array of Double.

getDomainExtent

public static Range getDomainExtent(Dataset data)
Returns the range of values in the domain for the dataset.

Parameters:
data - the dataset.
Returns:
the range of values.

getRangeExtent

public static Range getRangeExtent(Dataset data)
Returns the range of values in the range for the dataset. This method is the partner for the getDomainExtent method.

Parameters:
data - the dataset.
Returns:
the range of values in the range for the dataset.

getMinimumDomainValue

public static java.lang.Number getMinimumDomainValue(Dataset data)
Returns the minimum domain value for the specified dataset.

This is easy if the dataset implements the DomainInfo interface (a good idea if there is an efficient way to determine the minimum value). Otherwise, it involves iterating over the entire data-set.

Returns null if all the data values in the dataset are null.

Parameters:
data - the dataset.
Returns:
the minimum domain value in the dataset (or null).

getMaximumDomainValue

public static java.lang.Number getMaximumDomainValue(Dataset data)
Returns the maximum domain value for the specified dataset.

This is easy if the dataset implements the DomainInfo interface (a good idea if there is an efficient way to determine the maximum value). Otherwise, it involves iterating over the entire data-set.

Returns null if all the data values in the dataset are null.

Parameters:
data - the dataset.
Returns:
the maximum domain value in the dataset (or null).

getMinimumRangeValue

public static java.lang.Number getMinimumRangeValue(Dataset data)
Returns the minimum range value for the specified dataset.

This is easy if the dataset implements the RangeInfo interface (a good idea if there is an efficient way to determine the minimum value). Otherwise, it involves iterating over the entire data-set.

Returns null if all the data values in the dataset are null.

Parameters:
data - the dataset.
Returns:
the minimum range value in the dataset (or null).

getMaximumRangeValue

public static java.lang.Number getMaximumRangeValue(Dataset data)
Returns the maximum range value for the specified dataset.

This is easy if the dataset implements the RangeInfo interface (a good idea if there is an efficient way to determine the maximum value). Otherwise, it involves iterating over the entire data-set.

Returns null if all the data values are null.

Parameters:
data - the dataset.
Returns:
the maximum range value in the dataset (or null).

createPieDatasetForRow

public static PieDataset createPieDatasetForRow(CategoryDataset data,
                                                java.lang.Comparable rowKey)
Creates a pie dataset from a table dataset by taking all the values for a single row.

Parameters:
data - the data.
rowKey - the row key.
Returns:
a pie dataset.

createPieDatasetForRow

public static PieDataset createPieDatasetForRow(CategoryDataset data,
                                                int row)
Creates a pie dataset from a table dataset by taking all the values for a single row.

Parameters:
data - the data.
row - the row (zero-based index).
Returns:
a pie dataset.

createPieDatasetForColumn

public static PieDataset createPieDatasetForColumn(CategoryDataset data,
                                                   java.lang.Comparable columnKey)
Creates a pie dataset from a table dataset by taking all the values for a single column.

Parameters:
data - the data.
columnKey - the column key.
Returns:
a pie dataset.

createPieDatasetForColumn

public static PieDataset createPieDatasetForColumn(CategoryDataset data,
                                                   int column)
Creates a pie dataset from a table dataset by taking all the values for a single column.

Parameters:
data - the data.
column - the column (zero-based index).
Returns:
a pie dataset.

getPieDatasetTotal

public static double getPieDatasetTotal(PieDataset data)
Calculates the total of all the values in a PieDataset.

Parameters:
data - the dataset.
Returns:
the total.

getStackedRangeExtent

public static Range getStackedRangeExtent(CategoryDataset data)
Returns the minimum and maximum values for the dataset's range (as in domain/range), assuming that the series in one category are stacked.

Parameters:
data - the dataset.
Returns:
the value range.

getMinimumStackedRangeValue

public static java.lang.Number getMinimumStackedRangeValue(CategoryDataset data)
Returns the minimum value in the dataset range, assuming that values in each category are "stacked".

Parameters:
data - the dataset.
Returns:
the minimum value.

getMaximumStackedRangeValue

public static java.lang.Number getMaximumStackedRangeValue(CategoryDataset data)
Returns the maximum value in the dataset range, assuming that values in each category are "stacked".

Parameters:
data - the dataset.
Returns:
the maximum value.

sampleFunction2D

public static XYDataset sampleFunction2D(Function2D f,
                                         double start,
                                         double end,
                                         int samples,
                                         java.lang.String seriesName)
Creates an XYDataset by sampling the specified function over a fixed range.

Parameters:
f - the function.
start - the start value for the range.
end - the end value for the range.
samples - the number of samples (must be > 1).
seriesName - the name to give the resulting series.
Returns:
the dataset.

createCategoryDataset

public static CategoryDataset createCategoryDataset(java.lang.String rowKeyPrefix,
                                                    java.lang.String columnKeyPrefix,
                                                    double[][] data)
Creates a CategoryDataset that contains a copy of the data in an array (instances of Double are created to represent the data items).

Row and column keys are created by appending 0, 1, 2, ... to the supplied prefixes.

Parameters:
rowKeyPrefix - the row key prefix.
columnKeyPrefix - the column key prefix.
data - the data.
Returns:
the dataset.

createCategoryDataset

public static CategoryDataset createCategoryDataset(java.lang.String rowKeyPrefix,
                                                    java.lang.String columnKeyPrefix,
                                                    java.lang.Number[][] data)
Creates a CategoryDataset that contains a copy of the data in an array.

Row and column keys are created by appending 0, 1, 2, ... to the supplied prefixes.

Parameters:
rowKeyPrefix - the row key prefix.
columnKeyPrefix - the column key prefix.
data - the data.
Returns:
the dataset.

createCategoryDataset

public static CategoryDataset createCategoryDataset(java.lang.String rowKey,
                                                    KeyedValues rowData)
Creates a CategoryDataset by copying the data from the supplied KeyedValues instance.

Parameters:
rowKey - the row key.
rowData - the row data.
Returns:
A dataset.

isEmpty

public static boolean isEmpty(XYDataset data)
Returns true if the dataset is empty, and false otherwise.

If the dataset is null, it is considered to be empty.

Parameters:
data - the dataset (null permitted).
Returns:
A boolean.