📄 timeseriescollection.java
字号:
* Adds a series to the collection. * <P> * Notifies all registered listeners that the dataset has changed. * * @param series the time series. */ public void addSeries(final TimeSeries series) { // check argument... if (series == null) { throw new IllegalArgumentException( "TimeSeriesDataset.addSeries(...): cannot add null series."); } // add the series... this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Removes the specified series from the collection. * * @param series the series to remove. */ public void removeSeries(final TimeSeries series) { // check argument... if (series == null) { throw new IllegalArgumentException( "TimeSeriesDataset.addSeries(...): cannot remove null series."); } // remove the series... this.data.remove(series); series.removeChangeListener(this); fireDatasetChanged(); } /** * Removes a series from the collection. * * @param index the series index (zero-based). */ public void removeSeries(final int index) { final TimeSeries series = getSeries(index); if (series != null) { removeSeries(series); } } /** * Removes all the series from the collection. A {@link DatasetChangeEvent} is * sent 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. * <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(final 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 getXValue(final int series, final 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 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(final int series, final 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 = getXValue(series, i); final long m = x.longValue(); if (m <= milliseconds) { result[0] = i; } if (m >= milliseconds) { result[1] = i; break; } } return result; } /** * Returns the x-value for a time period. * * @param period the time period. * * @return the x-value. */ private long getX(final 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 starting X value for the specified series and item. */ public Number getStartXValue(final int series, final 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 ending X value for the specified series and item. */ public Number getEndXValue(final int series, final 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 y-value for the specified series and item. */ public Number getYValue(final int series, final int item) { final TimeSeries ts = (TimeSeries) this.data.get(series); final 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 starting Y value for the specified series and item. */ public Number getStartYValue(final int series, final int item) { return getYValue(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 getEndYValue(final int series, final int item) { return getYValue(series, item); } /** * Returns the minimum value in the dataset (or null if all the values in * the domain are null). * * @return the minimum value. */ public Number getMinimumDomainValue() { final Range r = getDomainRange(); return new Double(r.getLowerBound()); } /** * Returns the maximum value in the dataset (or null if all the values in * the domain are null). * * @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(final 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; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -