Gets a list of Datasets from a self-contained source Data object. @param source the self-contained Data @return a list of Datasets
(Data source)
| 1682 | * @return a list of Datasets |
| 1683 | */ |
| 1684 | public static ArrayList<Dataset> getDatasets(Data source) { |
| 1685 | // if the source supplies datasets, return them |
| 1686 | ArrayList<Dataset> datasets = (source instanceof DatasetManager ? |
| 1687 | ((DatasetManager)source).getDatasetsRaw() : source.getDatasets()); |
| 1688 | if (datasets != null) { |
| 1689 | return datasets; |
| 1690 | } |
| 1691 | // else create an empty dataset list and populate it from data2D |
| 1692 | datasets = new ArrayList<Dataset>(); |
| 1693 | double[][] data2D = source.getData2D(); |
| 1694 | if ((data2D == null) || (data2D.length == 0) || (data2D[0] == null)) { |
| 1695 | return datasets; // return empty list |
| 1696 | } |
| 1697 | // get column names--minimum 2 |
| 1698 | // colNames[0] will be x-column name |
| 1699 | // colNames[1] and up will be y-column names |
| 1700 | String[] colNames = source.getColumnNames(); |
| 1701 | // if colNames is null, create colNames |
| 1702 | if (colNames == null) { |
| 1703 | colNames = new String[2]; |
| 1704 | // if only one point set in data2D, then first column is named "n" |
| 1705 | if (data2D.length == 1) { |
| 1706 | colNames[0] = "n"; //$NON-NLS-1$ |
| 1707 | } |
| 1708 | } |
| 1709 | int n = Math.max(2, data2D.length); // number of columns |
| 1710 | if (colNames.length > n) { |
| 1711 | n++; |
| 1712 | } |
| 1713 | colNames = getColumnNames(colNames, n); |
| 1714 | // create datasets for double[] columns |
| 1715 | // if more names than double[] columns, then first double[] is row numbers |
| 1716 | boolean xPointsAreRowNumbers = colNames.length > data2D.length; |
| 1717 | double[] xPoints = xPointsAreRowNumbers ? getRowArray(data2D[0].length) : data2D[0]; |
| 1718 | for (int i = 1; i < colNames.length; i++) { |
| 1719 | double[] yPoints = xPointsAreRowNumbers ? data2D[i - 1] : data2D[i]; |
| 1720 | Dataset dataset = createDataset(xPoints, yPoints, colNames[0], colNames[i], i, source); |
| 1721 | if (dataset != null) { |
| 1722 | datasets.add(dataset); |
| 1723 | } |
| 1724 | } |
| 1725 | return datasets; |
| 1726 | } |
| 1727 | |
| 1728 | /** |
| 1729 | * Gets a list of all Datasets from any Data object. |
no test coverage detected