Example usage for org.jfree.util ArrayUtilities hasDuplicateItems

List of usage examples for org.jfree.util ArrayUtilities hasDuplicateItems

Introduction

In this page you can find the example usage for org.jfree.util ArrayUtilities hasDuplicateItems.

Prototype

public static boolean hasDuplicateItems(final Object[] array) 

Source Link

Document

Returns true if any two items in the array are equal to one another.

Usage

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates a {@link CategoryDataset} that contains a copy of the data in
 * an array (instances of <code>Double</code> are created to represent the
 * data items)./*www .  j  a va  2s .  com*/
 * <p>
 * Row and column keys are taken from the supplied arrays.
 *
 * @param rowKeys  the row keys (<code>null</code> not permitted).
 * @param columnKeys  the column keys (<code>null</code> not permitted).
 * @param data  the data.
 *
 * @return The dataset.
 */
public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, Comparable[] columnKeys,
        double[][] data) {

    ParamChecks.nullNotPermitted(rowKeys, "rowKeys");
    ParamChecks.nullNotPermitted(columnKeys, "columnKeys");
    if (ArrayUtilities.hasDuplicateItems(rowKeys)) {
        throw new IllegalArgumentException("Duplicate items in 'rowKeys'.");
    }
    if (ArrayUtilities.hasDuplicateItems(columnKeys)) {
        throw new IllegalArgumentException("Duplicate items in 'columnKeys'.");
    }
    if (rowKeys.length != data.length) {
        throw new IllegalArgumentException(
                "The number of row keys does not match the number of rows in " + "the data array.");
    }
    int columnCount = 0;
    for (int r = 0; r < data.length; r++) {
        columnCount = Math.max(columnCount, data[r].length);
    }
    if (columnKeys.length != columnCount) {
        throw new IllegalArgumentException(
                "The number of column keys does not match the number of " + "columns in the data array.");
    }

    // now do the work...
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    for (int r = 0; r < data.length; r++) {
        Comparable rowKey = rowKeys[r];
        for (int c = 0; c < data[r].length; c++) {
            Comparable columnKey = columnKeys[c];
            result.addValue(new Double(data[r][c]), rowKey, columnKey);
        }
    }
    return result;

}