combineddataset.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 631 行 · 第 1/2 页
JAVA
631 行
* * @return The open-value. */ public double getOpenValue(int series, int item) { double result = Double.NaN; Number open = getOpen(series, item); if (open != null) { result = open.doubleValue(); } return result; } /** * Returns the close-value for the specified series and item. * <P> * Note: throws <code>ClassCastException</code> if the series is not from a * {@link OHLCDataset}. * * @param series the index of the series of interest (zero-based). * @param item the index of the item of interest (zero-based). * * @return The close-value for the specified series and item. */ public Number getClose(int series, int item) { DatasetInfo di = getDatasetInfo(series); return ((OHLCDataset) di.data).getClose(di.series, item); } /** * Returns the close-value (as a double primitive) for an item within a * series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The close-value. */ public double getCloseValue(int series, int item) { double result = Double.NaN; Number close = getClose(series, item); if (close != null) { result = close.doubleValue(); } return result; } /** * Returns the volume value for the specified series and item. * <P> * Note: throws <code>ClassCastException</code> if the series is not from a * {@link OHLCDataset}. * * @param series the index of the series of interest (zero-based). * @param item the index of the item of interest (zero-based). * * @return The volume value for the specified series and item. */ public Number getVolume(int series, int item) { DatasetInfo di = getDatasetInfo(series); return ((OHLCDataset) di.data).getVolume(di.series, item); } /** * Returns the volume-value (as a double primitive) for an item within a * series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The volume-value. */ public double getVolumeValue(int series, int item) { double result = Double.NaN; Number volume = getVolume(series, item); if (volume != null) { result = volume.doubleValue(); } return result; } /////////////////////////////////////////////////////////////////////////// // From IntervalXYDataset /////////////////////////////////////////////////////////////////////////// /** * Returns the starting X value for the specified series and item. * * @param series the index of the series of interest (zero-based). * @param item the index of the item of interest (zero-based). * * @return The value. */ public Number getStartX(int series, int item) { DatasetInfo di = getDatasetInfo(series); if (di.data instanceof IntervalXYDataset) { return ((IntervalXYDataset) di.data).getStartX(di.series, item); } else { return getX(series, item); } } /** * Returns the ending X value for the specified series and item. * * @param series the index of the series of interest (zero-based). * @param item the index of the item of interest (zero-based). * * @return The value. */ public Number getEndX(int series, int item) { DatasetInfo di = getDatasetInfo(series); if (di.data instanceof IntervalXYDataset) { return ((IntervalXYDataset) di.data).getEndX(di.series, item); } else { return getX(series, item); } } /** * Returns the starting Y value for the specified series and item. * * @param series the index of the series of interest (zero-based). * @param item the index of the item of interest (zero-based). * * @return The starting Y value for the specified series and item. */ public Number getStartY(int series, int item) { DatasetInfo di = getDatasetInfo(series); if (di.data instanceof IntervalXYDataset) { return ((IntervalXYDataset) di.data).getStartY(di.series, item); } else { return getY(series, item); } } /** * Returns the ending Y value for the specified series and item. * * @param series the index of the series of interest (zero-based). * @param item the index of the item of interest (zero-based). * * @return The ending Y value for the specified series and item. */ public Number getEndY(int series, int item) { DatasetInfo di = getDatasetInfo(series); if (di.data instanceof IntervalXYDataset) { return ((IntervalXYDataset) di.data).getEndY(di.series, item); } else { return getY(series, item); } } /////////////////////////////////////////////////////////////////////////// // New methods from CombinationDataset /////////////////////////////////////////////////////////////////////////// /** * Returns the parent Dataset of this combination. If there is more than * one parent, or a child is found that is not a CombinationDataset, then * returns <code>null</code>. * * @return The parent Dataset of this combination or <code>null</code>. */ public SeriesDataset getParent() { SeriesDataset parent = null; for (int i = 0; i < this.datasetInfo.size(); i++) { SeriesDataset child = getDatasetInfo(i).data; if (child instanceof CombinationDataset) { SeriesDataset childParent = ((CombinationDataset) child).getParent(); if (parent == null) { parent = childParent; } else if (parent != childParent) { return null; } } else { return null; } } return parent; } /** * Returns a map or indirect indexing form our series into parent's series. * Prior to calling this method, the client should check getParent() to make * sure the CombinationDataset uses the same parent. If not, the map * returned by this method will be invalid or null. * * @return A map or indirect indexing form our series into parent's series. * * @see #getParent() */ public int[] getMap() { int[] map = null; for (int i = 0; i < this.datasetInfo.size(); i++) { SeriesDataset child = getDatasetInfo(i).data; if (child instanceof CombinationDataset) { int[] childMap = ((CombinationDataset) child).getMap(); if (childMap == null) { return null; } map = joinMap(map, childMap); } else { return null; } } return map; } /////////////////////////////////////////////////////////////////////////// // New Methods /////////////////////////////////////////////////////////////////////////// /** * Returns the child position. * * @param child the child dataset. * * @return The position. */ public int getChildPosition(Dataset child) { int n = 0; for (int i = 0; i < this.datasetInfo.size(); i++) { SeriesDataset childDataset = getDatasetInfo(i).data; if (childDataset instanceof CombinedDataset) { int m = ((CombinedDataset) childDataset) .getChildPosition(child); if (m >= 0) { return n + m; } n++; } else { if (child == childDataset) { return n; } n++; } } return -1; } /////////////////////////////////////////////////////////////////////////// // Private /////////////////////////////////////////////////////////////////////////// /** * Returns the DatasetInfo object associated with the series. * * @param series the index of the series. * * @return The DatasetInfo object associated with the series. */ private DatasetInfo getDatasetInfo(int series) { return (DatasetInfo) this.datasetInfo.get(series); } /** * Joins two map arrays (int[]) together. * * @param a the first array. * @param b the second array. * * @return A copy of { a[], b[] }. */ private int[] joinMap(int[] a, int[] b) { if (a == null) { return b; } if (b == null) { return a; } int[] result = new int[a.length + b.length]; System.arraycopy(a, 0, result, 0, a.length); System.arraycopy(b, 0, result, a.length, b.length); return result; } /** * Private class to store as pairs (SeriesDataset, series) for all combined * series. */ private class DatasetInfo { /** The dataset. */ private SeriesDataset data; /** The series. */ private int series; /** * Creates a new dataset info record. * * @param data the dataset. * @param series the series. */ DatasetInfo(SeriesDataset data, int series) { this.data = data; this.series = series; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?