timeseriescollection.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 635 行 · 第 1/2 页
JAVA
635 行
* @param series the series (<code>null</code> not permitted). */ public void removeSeries(TimeSeries series) { if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } this.data.remove(series); series.removeChangeListener(this); fireDatasetChanged(); } /** * Removes a series from the collection. * * @param index the series index (zero-based). */ public void removeSeries(int index) { TimeSeries series = getSeries(index); if (series != null) { removeSeries(series); } } /** * 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++) { 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) { TimeSeries ts = (TimeSeries) this.data.get(series); TimeSeriesDataItem dp = ts.getDataItem(item); 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 synchronized 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 synchronized Number getStartX(int series, int item) { TimeSeries ts = (TimeSeries) this.data.get(series); 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 synchronized Number getEndX(int series, int item) { TimeSeries ts = (TimeSeries) this.data.get(series); 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) { int[] result = new int[] {-1, -1}; TimeSeries timeSeries = getSeries(series); for (int i = 0; i < timeSeries.getItemCount(); i++) { Number x = getX(series, i); long m = x.longValue(); if (m <= milliseconds) { result[0] = i; } if (m >= milliseconds) { result[1] = i; break; } } return result; } /** * 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; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { TimeSeries series = (TimeSeries) iterator.next(); int count = series.getItemCount(); if (count > 0) { RegularTimePeriod start = series.getTimePeriod(0); RegularTimePeriod end = series.getTimePeriod(count - 1); Range temp; if (!includeInterval || 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 == this) { return true; } if (!(obj instanceof TimeSeriesCollection)) { return false; } TimeSeriesCollection that = (TimeSeriesCollection) obj; if (this.xPosition != that.xPosition) { return false; } if (this.domainIsPointsInTime != that.domainIsPointsInTime) { return false; } if (!ObjectUtilities.equal(this.data, that.data)) { 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; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?