timeperiodvaluescollection.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 488 行 · 第 1/2 页

JAVA
488
字号
     * <P>     * This method is provided for convenience.     *     * @param series  the index of the series of interest (zero-based).     *     * @return The number of items in the specified series.     */    public int getItemCount(int series) {        return getSeries(series).getItemCount();    }    /**     * Returns the x-value for the specified series and item.     *     * @param series  the series (zero-based index).     * @param item  the item (zero-based index).     *     * @return The x-value for the specified series and item.     */    public Number getX(int series, int item) {        TimePeriodValues ts = (TimePeriodValues) this.data.get(series);        TimePeriodValue dp = ts.getDataItem(item);        TimePeriod period = dp.getPeriod();        return new Long(getX(period));    }    /**     * Returns the x-value for a time period.     *     * @param period  the time period.     *     * @return The x-value.     */    private long getX(TimePeriod period) {        if (this.xPosition == TimePeriodAnchor.START) {            return period.getStart().getTime();        }        else if (this.xPosition == TimePeriodAnchor.MIDDLE) {            return period.getStart().getTime()                 / 2 + period.getEnd().getTime() / 2;        }        else if (this.xPosition == TimePeriodAnchor.END) {            return period.getEnd().getTime();        }        else {            throw new IllegalStateException("TimePeriodAnchor unknown.");        }    }    /**     * Returns the starting X value for the specified series and item.     *     * @param series  the series (zero-based index).     * @param item  the item (zero-based index).     *     * @return The starting X value for the specified series and item.     */    public Number getStartX(int series, int item) {        TimePeriodValues ts = (TimePeriodValues) this.data.get(series);        TimePeriodValue dp = ts.getDataItem(item);        return new Long(dp.getPeriod().getStart().getTime());    }    /**     * Returns the ending X value for the specified series and item.     *     * @param series  the series (zero-based index).     * @param item  the item (zero-based index).     *     * @return The ending X value for the specified series and item.     */    public Number getEndX(int series, int item) {        TimePeriodValues ts = (TimePeriodValues) this.data.get(series);        TimePeriodValue dp = ts.getDataItem(item);        return new Long(dp.getPeriod().getEnd().getTime());    }    /**     * Returns the y-value for the specified series and item.     *     * @param series  the series (zero-based index).     * @param item  the item (zero-based index).     *     * @return The y-value for the specified series and item.     */    public Number getY(int series, int item) {        TimePeriodValues ts = (TimePeriodValues) this.data.get(series);        TimePeriodValue dp = ts.getDataItem(item);        return dp.getValue();    }    /**     * Returns the starting Y value for the specified series and item.     *     * @param series  the series (zero-based index).     * @param item  the item (zero-based index).     *     * @return The starting Y value for the specified series and item.     */    public Number getStartY(int series, int item) {        return getY(series, item);    }    /**     * Returns the ending Y value for the specified series and item.     *     * @param series  the series (zero-based index).     * @param item  the item (zero-based index).     *     * @return The ending Y value for the specified series and item.     */    public Number getEndY(int series, int item) {        return getY(series, item);    }    /**     * Returns the minimum x-value in the dataset.     *     * @param includeInterval  a flag that determines whether or not the     *                         x-interval is taken into account.     *      * @return The minimum value.     */    public double getDomainLowerBound(boolean includeInterval) {        double result = Double.NaN;        Range r = getDomainBounds(includeInterval);        if (r != null) {            result = r.getLowerBound();        }        return result;    }    /**     * Returns the maximum x-value in the dataset.     *     * @param includeInterval  a flag that determines whether or not the     *                         x-interval is taken into account.     *      * @return The maximum value.     */    public double getDomainUpperBound(boolean includeInterval) {        double result = Double.NaN;        Range r = getDomainBounds(includeInterval);        if (r != null) {            result = r.getUpperBound();        }        return result;    }    /**     * Returns the range of the values in this dataset's domain.     *     * @param includeInterval  a flag that determines whether or not the     *                         x-interval is taken into account.     *      * @return The range.     */    public Range getDomainBounds(boolean includeInterval) {        Range result = null;        Range temp = null;        Iterator iterator = this.data.iterator();        while (iterator.hasNext()) {            TimePeriodValues series = (TimePeriodValues) iterator.next();            int count = series.getItemCount();            if (count > 0) {                TimePeriod start = series.getTimePeriod(                    series.getMinStartIndex()                );                TimePeriod end = series.getTimePeriod(series.getMaxEndIndex());                if (this.domainIsPointsInTime) {                    if (this.xPosition == TimePeriodAnchor.START) {                        TimePeriod maxStart = series.getTimePeriod(                            series.getMaxStartIndex()                        );                        temp = new Range(                            start.getStart().getTime(),                             maxStart.getStart().getTime()                        );                    }                    else if (this.xPosition == TimePeriodAnchor.MIDDLE) {                        TimePeriod minMiddle = series.getTimePeriod(                            series.getMinMiddleIndex()                        );                        long s1 = minMiddle.getStart().getTime();                        long e1 = minMiddle.getEnd().getTime();                        TimePeriod maxMiddle = series.getTimePeriod(                            series.getMaxMiddleIndex()                        );                        long s2 = maxMiddle.getStart().getTime();                        long e2 = maxMiddle.getEnd().getTime();                        temp = new Range(                            s1 + (e1 - s1) / 2, s2 + (e2 - s2) / 2                        );                    }                    else if (this.xPosition == TimePeriodAnchor.END) {                        TimePeriod minEnd = series.getTimePeriod(                            series.getMinEndIndex()                        );                        temp = new Range(                            minEnd.getEnd().getTime(), end.getEnd().getTime()                        );                    }                }                else {                    temp = new Range(                        start.getStart().getTime(), end.getEnd().getTime()                    );                }                result = Range.combine(result, temp);            }        }        return result;    }    /**     * Tests this instance for equality with an arbitrary object.     *      * @param obj  the object (<code>null</code> permitted).     *      * @return A boolean.     */    public boolean equals(Object obj) {        if (obj == this) {            return true;        }        if (!(obj instanceof TimePeriodValuesCollection)) {            return false;           }        TimePeriodValuesCollection that = (TimePeriodValuesCollection) obj;        if (this.domainIsPointsInTime != that.domainIsPointsInTime) {            return false;           }        if (this.xPosition != that.xPosition) {            return false;           }        if (!ObjectUtilities.equal(this.data, that.data)) {            return false;        }        return true;       }}

⌨️ 快捷键说明

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