Example usage for java.lang Number equals

List of usage examples for java.lang Number equals

Introduction

In this page you can find the example usage for java.lang Number equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.pentaho.chart.plugin.openflashchart.OpenFlashChartFactoryEngine.java

private AxisConfiguration getAxisConfiguration(TwoAxisPlot twoAxisPlot, MultiSeriesDataModel chartTableModel) {
    Number minValue = twoAxisPlot.getRangeAxis().getMinValue();
    Number maxValue = twoAxisPlot.getRangeAxis().getMaxValue();

    boolean calculateMinValue = (minValue == null);
    boolean calculateMaxValue = (maxValue == null);

    boolean hasChartData = false;

    List<SeriesData> seriesList = chartTableModel.getSeriesData();

    if ((twoAxisPlot instanceof BarPlot) && (((BarPlot) twoAxisPlot).getFlavor() == BarPlotFlavor.STACKED)) {
        int numCategories = chartTableModel.getDomainData().size();
        Number[][] stackRanges = new Number[numCategories][];
        for (SeriesData series : seriesList) {
            int index = 0;
            for (NamedValue namedValue : series) {
                Number value = namedValue.getValue();
                hasChartData = hasChartData || (value != null);
                if (value != null) {
                    value = scaleNumber(value, chartTableModel.getScalingFactor());
                    Number[] stackRange = stackRanges[index];
                    if (stackRange == null) {
                        if (value.doubleValue() < 0) {
                            stackRanges[index] = new Number[] { value, 0 };
                        } else {
                            stackRanges[index] = new Number[] { 0, value };
                        }/*  w w w.j a v  a2  s  .c o m*/
                    } else {
                        if (value.doubleValue() < 0) {
                            stackRange[STACK_MIN_INDEX] = stackRange[STACK_MIN_INDEX].doubleValue()
                                    + value.doubleValue();
                        } else {
                            stackRange[STACK_MAX_INDEX] = stackRange[STACK_MAX_INDEX].doubleValue()
                                    + value.doubleValue();
                        }
                    }
                }
                index++;
            }
        }
        if (hasChartData) {
            for (int column = 0; column < numCategories; column++) {
                Number[] stackRange = stackRanges[column];

                if (calculateMaxValue) {
                    if (maxValue == null) {
                        maxValue = stackRange[STACK_MAX_INDEX];
                    } else if (stackRange[STACK_MAX_INDEX] != null) {
                        maxValue = Math.max(maxValue.doubleValue(), stackRange[STACK_MAX_INDEX].doubleValue());
                    }
                }

                if (calculateMinValue) {
                    if (minValue == null) {
                        minValue = stackRange[STACK_MIN_INDEX];
                    } else if (stackRange[STACK_MIN_INDEX] != null) {
                        minValue = Math.min(minValue.doubleValue(), stackRange[STACK_MIN_INDEX].doubleValue());
                    }
                }
            }
        }
    } else {
        for (SeriesData series : seriesList) {
            for (NamedValue namedValue : series) {
                Number value = namedValue.getValue();
                hasChartData = hasChartData || (value != null);
                if (value != null) {
                    value = scaleNumber(value, chartTableModel.getScalingFactor());
                }
                if (calculateMaxValue) {
                    if (maxValue == null) {
                        maxValue = value;
                    } else if (value != null) {
                        maxValue = Math.max(maxValue.doubleValue(), value.doubleValue());
                    }
                }

                if (calculateMinValue) {
                    if (minValue == null) {
                        minValue = value;
                    } else if (value != null) {
                        minValue = Math.min(minValue.doubleValue(), value.doubleValue());
                    }
                }

            }
        }
    }

    AxisConfiguration rangeDescription = null;

    if (hasChartData) {
        if (calculateMinValue) {
            minValue = Math.min(0, minValue.doubleValue());
        }
        minValue = Math.floor(minValue.doubleValue());
        maxValue = Math.ceil(maxValue.doubleValue());

        if (maxValue.equals(minValue)) {
            maxValue = maxValue.intValue() + 1;
        }

        Number spread = maxValue.doubleValue() - minValue.doubleValue();

        int exponent = Integer.toString(Math.abs(spread.intValue())).length() - 1;

        int stepSize = (int) (((long) (spread.intValue() / Math.pow(10, exponent)))
                * Math.pow(10, exponent - 1)) * 2;
        if (stepSize < 1) {
            stepSize = 1;
        }

        if ((maxValue.doubleValue() % stepSize) != 0) {
            maxValue = (maxValue.doubleValue() - (maxValue.doubleValue() % stepSize)) + stepSize;
        }

        rangeDescription = new AxisConfiguration(minValue.intValue(), maxValue.intValue(), stepSize);
    }

    return rangeDescription;
}