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

📄 timeseriescollection.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }

    /**
     * Removes all the series from the collection and sends a {@link DatasetChangeEvent}  
     * to all registered listeners.
     */
    public void removeAllSeries() {

        // deregister the collection as a change listener to each series in the collection
        for (int i = 0; i < this.data.size(); i++) {
          final TimeSeries series = (TimeSeries) this.data.get(i);
          series.removeChangeListener(this);
        }

        // remove all the series from the collection and notify listeners.
        this.data.clear();
        fireDatasetChanged();

    }

    /**
     * Returns the number of items in the specified series.  This method is provided for 
     * convenience.
     *
     * @param series  the series index (zero-based).
     *
     * @return The item count.
     */
    public int getItemCount(int series) {
        return getSeries(series).getItemCount();
    }
    
    /**
     * Returns the x-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 x-value.
     */
    public double getXValue(int series, int item) {
        TimeSeries s = (TimeSeries) this.data.get(series);
        TimeSeriesDataItem i = s.getDataItem(item);
        RegularTimePeriod period = i.getPeriod();
        return getX(period);
    }

    /**
     * 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 value.
     */
    public Number getX(int series, int item) {
        final TimeSeries ts = (TimeSeries) this.data.get(series);
        final TimeSeriesDataItem dp = ts.getDataItem(item);
        final RegularTimePeriod 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.
     */
    protected long getX(RegularTimePeriod period) {

        long result = 0L;
        if (this.xPosition == TimePeriodAnchor.START) {
            result = period.getFirstMillisecond(this.workingCalendar);
        }
        else if (this.xPosition == TimePeriodAnchor.MIDDLE) {
            result = period.getMiddleMillisecond(this.workingCalendar);
        }
        else if (this.xPosition == TimePeriodAnchor.END) {
            result = period.getLastMillisecond(this.workingCalendar); 
        }
        return result;

    }

    /**
     * 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 value.
     */
    public Number getStartX(int series, int item) {
        final TimeSeries ts = (TimeSeries) this.data.get(series);
        final TimeSeriesDataItem dp = ts.getDataItem(item);
        return new Long(dp.getPeriod().getFirstMillisecond(this.workingCalendar));
    }

    /**
     * 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 value.
     */
    public Number getEndX(int series, int item) {

        final TimeSeries ts = (TimeSeries) this.data.get(series);
        final TimeSeriesDataItem dp = ts.getDataItem(item);
        return new Long(dp.getPeriod().getLastMillisecond(this.workingCalendar));

    }

    /**
     * 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 value (possibly <code>null</code>).
     */
    public Number getY(int series, int item) {

        TimeSeries ts = (TimeSeries) this.data.get(series);
        TimeSeriesDataItem 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 value (possibly <code>null</code>).
     */
    public Number getStartY(int series, int item) {
        return getY(series, item);
    }

    /**
     * Returns the ending Y value for the specified series and item.
     *
     * @param series  te series (zero-based index).
     * @param item  the item (zero-based index).
     *
     * @return The value (possibly <code>null</code>).
     */
    public Number getEndY(int series, int item) {
        return getY(series, item);
    }


    /**
     * Returns the indices of the two data items surrounding a particular millisecond value.  
     * 
     * @param series  the series index.
     * @param milliseconds  the time.
     * 
     * @return An array containing the (two) indices of the items surrounding the time.
     */
    public int[] getSurroundingItems(int series, long milliseconds) {
        final int[] result = new int[] {-1, -1};
        final TimeSeries timeSeries = getSeries(series);
        for (int i = 0; i < timeSeries.getItemCount(); i++) {
            final Number x = getX(series, i);
            final long m = x.longValue();
            if (m <= milliseconds) {
                result[0] = i;
            }
            if (m >= milliseconds) {
                result[1] = i;
                break;
            }
        }
        return result;
    }
    
    /**
     * Returns the minimum value in the dataset (or <code>null</code> if all the values in
     * the domain are <code>null</code>).
     *
     * @return The minimum value.
     */
    public Number getMinimumDomainValue() {
        final Range r = getDomainRange();
        return new Double(r.getLowerBound());
    }

    /**
     * Returns the maximum value in the dataset (or <code>null</code> if all the values in
     * the domain are <code>null</code>).
     *
     * @return The maximum value.
     */
    public Number getMaximumDomainValue() {
        final Range r = getDomainRange();
        return new Double(r.getUpperBound());
    }

    /**
     * Returns the range of the values in the series domain.
     *
     * @return The range (possibly <code>null</code>).
     */
    public Range getDomainRange() {
        Range result = null;
        final Iterator iterator = this.data.iterator();
        while (iterator.hasNext()) {
            final TimeSeries series = (TimeSeries) iterator.next();
            final int count = series.getItemCount();
            if (count > 0) {
                final RegularTimePeriod start = series.getTimePeriod(0);
                final RegularTimePeriod end = series.getTimePeriod(count - 1);
                final Range temp;
                if (this.domainIsPointsInTime) {
                    temp = new Range(getX(start), getX(end));
                }
                else {
                    temp = new Range(
                        start.getFirstMillisecond(this.workingCalendar),
                        end.getLastMillisecond(this.workingCalendar)
                    );
                }
                result = Range.combine(result, temp);
            }
        }
        return result;
    }

    /**
     * Tests this time series collection for equality with another object.
     *
     * @param obj  the other object.
     *
     * @return A boolean.
     */
    public boolean equals(Object obj) {

        if (obj == null) {
            return false;
        }

        if (obj == this) {
            return true;
        }

        if ((obj instanceof TimeSeriesCollection) == false) {
            return false;
        }
        final TimeSeriesCollection tsc = (TimeSeriesCollection) obj;

        if (ObjectUtils.equal(this.data, tsc.data) == false) {
            return false;
        }

        if (this.xPosition != tsc.xPosition) {
            return false;
        }

        if (this.domainIsPointsInTime != tsc.domainIsPointsInTime) {
            return false;
        }
        return true;
    }

    /**
     * Returns a hash code value for the object.
     *
     * @return the hashcode
     */
    public int hashCode() {
        int result;
        result = this.data.hashCode();
        result = 29 * result + (this.workingCalendar != null ? this.workingCalendar.hashCode() : 0);
        result = 29 * result + (this.xPosition != null ? this.xPosition.hashCode() : 0);
        result = 29 * result + (this.domainIsPointsInTime ? 1 : 0);
        return result;
    }
    
    //// DEPRECATED CODE /////////////////////////////////////////////////////////////////////////
    
    /**
     * Returns the position of the x-value returned for a time period (START,
     * MIDDLE, or END).
     *
     * @return The position.
     * @deprecated Use getXPosition().
     */
    public int getPosition() {
        int result = MIDDLE;
        final TimePeriodAnchor anchor = getXPosition();
        if (anchor == TimePeriodAnchor.START) {
            result = START;
        }
        else if (anchor == TimePeriodAnchor.MIDDLE) {
            result = MIDDLE;
        }
        else if (anchor == TimePeriodAnchor.END) {
            result = END;
        }
        return result;
    }
    
    /**
     * Sets the position - this controls the x-value that is returned for a
     * particular time period.
     * <P>
     * Use the constants <code>START</code>, <code>MIDDLE</code> and <code>END</code>.
     *
     * @param position the position.
     * @deprecated Use setXPosition(...).
     */
    public void setPosition(final int position) {
        if (position == START) {
            setXPosition(TimePeriodAnchor.START);
        }
        else if (position == MIDDLE) {
            setXPosition(TimePeriodAnchor.MIDDLE);
        } 
        else if (position == END) {
            setXPosition(TimePeriodAnchor.END);
        }
    }

}

⌨️ 快捷键说明

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