List of usage examples for org.jfree.chart.util ArrayUtils hasDuplicateItems
public static boolean hasDuplicateItems(Object[] array)
true
if any two items in the array are equal to one another. From source file:org.jfree.data.general.DatasetUtils.java
/** * Creates a {@link CategoryDataset} that contains a copy of the data in * an array (instances of {@code double} are created to represent the * data items)./* ww w .ja v a2 s . com*/ * <p> * Row and column keys are taken from the supplied arrays. * * @param rowKeys the row keys ({@code null} not permitted). * @param columnKeys the column keys ({@code null} not permitted). * @param data the data. * * @return The dataset. */ public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, Comparable[] columnKeys, double[][] data) { Args.nullNotPermitted(rowKeys, "rowKeys"); Args.nullNotPermitted(columnKeys, "columnKeys"); if (ArrayUtils.hasDuplicateItems(rowKeys)) { throw new IllegalArgumentException("Duplicate items in 'rowKeys'."); } if (ArrayUtils.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; }