⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datasetutilities.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if (positive > maximum) {
                maximum = positive;
            } 
            if (negative < minimum) {
                minimum = negative;
            } 
        }
        return new Range(minimum, maximum);
    }

    /**
     * Calculates the range of values for a dataset where each item is the running total of 
     * the items for the current series.
     * 
     * @param dataset  the dataset.
     * 
     * @return The range.
     */
    public static Range findCumulativeRangeExtent(CategoryDataset dataset) {
        

        if (dataset == null) {
            throw new IllegalArgumentException("Null 'dataset' argument.");
        }
        
        boolean allItemsNull = true; // we'll set this to false if there is at least one
                                     // non-null data item... 
        double minimum = 0.0;
        double maximum = 0.0;
        for (int row = 0; row < dataset.getRowCount(); row++) {
            double runningTotal = 0.0;
            for (int column = 0; column < dataset.getColumnCount() - 1; column++) {
                Number n = dataset.getValue(row, column);
                if (n != null) {
                    allItemsNull = false;
                    double value = n.doubleValue();
                    runningTotal = runningTotal + value;
                    minimum = Math.min(minimum, runningTotal);
                    maximum = Math.max(maximum, runningTotal);
                }
            }    
        }
        if (!allItemsNull) {
            return new Range(minimum, maximum);
        }
        else {
            return null;
        }
        
    }
    
    //// DEPRECATED CODE ///////////////////////////////////////////////////////////////////////////
    
    /**
     * Returns the range of values in the domain for the dataset.  If the supplied dataset 
     * is <code>null</code>, the range returned is <code>null</code>.
     *
     * @param dataset  the dataset (<code>null</code> permitted).
     *
     * @return The range of values (possibly <code>null</code>).
     * 
     * @deprecated Use findDomainExtent().
     */
    public static Range getDomainExtent(Dataset dataset) {
        return findDomainExtent(dataset);
    }
    
    /**
     * Returns the range of values in the range for the dataset.  This method
     * is the partner for the getDomainExtent method.
     *
     * @param dataset  the dataset.
     *
     * @return The range of values in the range for the dataset.
     * 
     * @deprecated Use findRangeExtent().
     */
    public static Range getRangeExtent(Dataset dataset) {
        return findRangeExtent(dataset);
    }
    
    /**
     * Returns the maximum domain value for the specified dataset.
     * <P>
     * 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.
     * <p>
     * Returns null if all the data values in the dataset are null.
     *
     * @param dataset  the dataset.
     *
     * @return The maximum value (possibly <code>null</code>).
     * 
     * @deprecated Use findMaximumDomainValue();
     */
    public static Number getMaximumDomainValue(Dataset dataset) {
        return findMaximumDomainValue(dataset);
    }
    
    /**
     * Returns the minimum range value for the specified dataset.  This is easy if the 
     * dataset implements the {@link 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 <code>null</code> if all the data values in the 
     * dataset are <code>null</code>.
     *
     * @param dataset  the dataset (<code>null</code> not permitted).
     *
     * @return The minimum value (possibly <code>null</code>).
     * 
     * @deprecated Use findMinimumRangeValue().
     */
    public static Number getMinimumRangeValue(Dataset dataset) {
        return findMinimumRangeValue(dataset);
    }

    /**
     * Returns the maximum range value for the specified dataset.  This is easy if the 
     * dataset implements the {@link 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 <code>null</code> if all the data values are 
     * <code>null</code>.
     *
     * @param dataset  the dataset.
     *
     * @return The maximum value (possibly <code>null</code>).
     * 
     * @deprecated Use findMaximumRangeValue().
     */
    public static Number getMaximumRangeValue(Dataset dataset) {
        return findMaximumRangeValue(dataset);
    }
    
    /**
     * Returns the range of values in the domain for the dataset.  If the supplied dataset 
     * is <code>null</code>, the range returned is <code>null</code>.
     *
     * @param dataset  the dataset (<code>null</code> permitted).
     *
     * @return The range of values (possibly <code>null</code>).
     * 
     * @deprecated Use findDomainExtent(XYDataset) instead.
     */
    public static Range findDomainExtent(Dataset dataset) {
        
        // check parameters...
        if (dataset == null) {
            return null;
        }
        if ((dataset instanceof CategoryDataset) && !(dataset instanceof XYDataset)) {
            throw new IllegalArgumentException(
                "The dataset does not have a numerical domain."
            );
        }

        // work out the minimum value...
        if (dataset instanceof DomainInfo) {
            DomainInfo info = (DomainInfo) dataset;
            return info.getDomainRange();
        }

        // hasn't implemented DomainInfo, so iterate...
        else if (dataset instanceof XYDataset) {
            return iterateDomainExtent((XYDataset) dataset);
        }
        else {
            return null; // unrecognised dataset...how should this be handled?
        }
    }
    
    /**
     * Returns the range of values in the range for the dataset.  This method
     * is the partner for the getDomainExtent method.
     *
     * @param dataset  the dataset.
     *
     * @return The range of values in the range for the dataset.
     * 
     * @deprecated Use findRangeExtent(CategoryDataset) or findRangeExtent(XYDataset).
     */
    public static Range findRangeExtent(Dataset dataset) {

        // check parameters...
        if (dataset == null) {
            return null;
        }
        
        // work out the minimum value...
        if (dataset instanceof RangeInfo) {
            RangeInfo info = (RangeInfo) dataset;
            return info.getValueRange();
        }

        // hasn't implemented RangeInfo, so we'll have to iterate...
        else if (dataset instanceof CategoryDataset) {
            return iterateCategoryRangeExtent((CategoryDataset) dataset);
        }
        // hasn't implemented RangeInfo, so we'll have to iterate...
        else if (dataset instanceof XYDataset) {
            return iterateXYRangeExtent((XYDataset) dataset);
        }
        else {
            return null;
        }
    }

    /**
     * Finds the minimum domain (or X) value for the specified dataset.  This is easy if 
     * the dataset implements the {@link 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.
     * <p>
     * Returns <code>null</code> if all the data values in the dataset are <code>null</code>.
     *
     * @param dataset  the dataset (<code>null</code> not permitted).
     *
     * @return The minimum value (possibly <code>null</code>).
     * 
     * @deprecated Use findMinimumDomainValue(XYDataset).
     */
    public static Number findMinimumDomainValue(Dataset dataset) {

        if (dataset == null) {
            throw new IllegalArgumentException("Null 'dataset' argument.");
        }

        if ((dataset instanceof CategoryDataset) && !(dataset instanceof XYDataset)) {
            throw new IllegalArgumentException(
                "CategoryDataset does not have a numerical domain."
            );
        }

        // work out the minimum value...
        if (dataset instanceof DomainInfo) {
            DomainInfo info = (DomainInfo) dataset;
            return info.getMinimumDomainValue();
        }

        // hasn't implemented DomainInfo, so iterate...
        else if (dataset instanceof XYDataset) {
            double minimum = Double.POSITIVE_INFINITY;
            XYDataset xyData = (XYDataset) dataset;
            int seriesCount = xyData.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = xyData.getItemCount(series);
                for (int item = 0; item < itemCount; item++) {

                    double value;
                    if (dataset instanceof IntervalXYDataset) {
                        IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
                        value = intervalXYData.getStartXValue(series, item);
                    }
                    else {
                        value = xyData.getXValue(series, item);
                    }
                    if (!Double.isNaN(value)) {
                        minimum = Math.min(minimum, value);
                    }

                }
            }
            if (minimum == Double.POSITIVE_INFINITY) {
                return null;
            }
            else {
                return new Double(minimum);
            }
        }

        else {
            return null; // unrecognised dataset...how should this be handled?
        }

    }

    /**
     * Returns the maximum domain value for the specified dataset.  This is easy if the 
     * dataset implements the {@link 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 <code>null</code> if all the data values in the dataset 
     * are <code>null</code>.
     *
     * @param dataset  the dataset.
     *
     * @return The maximum value (possibly <code>null</code>).
     * 
     * @deprecated Use findMaximumDomainValue(XYDataset).
     */
    public static Number findMaximumDomainValue(Dataset dataset) {
        // check parameters...
        if (dataset == null) {
            throw new IllegalArgumentException("Null 'dataset' argument.");
        }

        if ((dataset instanceof CategoryDataset) && !(dataset instanceof XYDataset)) {
            throw new IllegalArgumentException("Datasets.getMaximumDomainValue(...): "
                + "CategoryDataset does not have numerical domain.");
        }

        // work out the maximum value...
        if (dataset instanceof DomainInfo) {
            DomainInfo info = (DomainInfo) dataset;
            return info.getMaximumDomainValue();
        }

        // hasn't implemented DomainInfo, so iterate...
        else if (dataset instanceof XYDataset) {
            XYDataset xyData = (XYDataset) dataset;
            double maximum = Double.NEGATIVE_INFINITY;
            int seriesCount = xyData.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = xyData.getItemCount(series);
                for (int item = 0; item < itemCount; item++) {

                    double value;
                    if (dataset instanceof IntervalXYDataset) {
                        IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
                        value = intervalXYData.getEndXValue(series, item);
                    }
                    else {
                        value = xyData.getXValue(series, item);
                    }
                    if (!Double.isNaN(value)) {
                        maximum = Math.max(maximum, value);
                    }
                }
            }
            if (maximum == Double.NEGATIVE_INFINITY) {
                return null;
            }
            else {
                return new Double(maximum);
            }

        }
        else {
            return null; // unrecognised dataset...how should this b

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -