📄 timeseriescollection.java
字号:
* <P>
* This method is provided for convenience.
*
* @param series The index of the series (zero-based).
*
* @return the name of a series.
*/
public String getSeriesName(int series) {
// check arguments...delegated
// fetch the series name...
return getSeries(series).getName();
}
/**
* Adds a series to the collection.
* <P>
* Notifies all registered listeners that the dataset has changed.
*
* @param series the time series.
*/
public void addSeries(TimeSeries series) {
// check argument...
if (series == null) {
throw new IllegalArgumentException(
"TimeSeriesDataset.addSeries(...): cannot add null series.");
}
// add the series...
data.add(series);
series.addChangeListener(this);
fireDatasetChanged();
}
/**
* Removes the specified series from the collection.
*
* @param series the series to remove.
*/
public void removeSeries(TimeSeries series) {
// check argument...
if (series == null) {
throw new IllegalArgumentException(
"TimeSeriesDataset.addSeries(...): cannot remove null series.");
}
// remove the series...
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);
}
}
/**
* 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(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(int series, int item) {
TimeSeries ts = (TimeSeries) data.get(series);
TimeSeriesDataItem dp = ts.getDataItem(item);
RegularTimePeriod period = dp.getPeriod();
return new Long(getX(period));
}
/**
* Returns the indices of the two observations 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 = getXValue(series, i);
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(RegularTimePeriod period) {
long result = 0L;
if (this.xPosition == TimePeriodAnchor.START) {
result = period.getFirstMillisecond(workingCalendar);
}
else if (this.xPosition == TimePeriodAnchor.MIDDLE) {
result = period.getMiddleMillisecond(workingCalendar);
}
else if (this.xPosition == TimePeriodAnchor.END) {
result = period.getLastMillisecond(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(int series, int item) {
TimeSeries ts = (TimeSeries) data.get(series);
TimeSeriesDataItem dp = ts.getDataItem(item);
return new Long(dp.getPeriod().getFirstMillisecond(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(int series, int item) {
TimeSeries ts = (TimeSeries) data.get(series);
TimeSeriesDataItem dp = ts.getDataItem(item);
return new Long(dp.getPeriod().getLastMillisecond(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(int series, int item) {
TimeSeries ts = (TimeSeries) data.get(series);
TimeSeriesDataItem dp = (TimeSeriesDataItem) 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(int series, 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(int series, 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() {
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() {
Range r = getDomainRange();
return new Double(r.getUpperBound());
}
/**
* Returns the range of the values in the series domain.
*
* @return the range.
*/
public Range getDomainRange() {
Range result = null;
Range temp = null;
Iterator iterator = 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);
if (this.domainIsPointsInTime) {
temp = new Range(getX(start), getX(end));
}
else {
temp = new Range(start.getFirstMillisecond(workingCalendar),
end.getLastMillisecond(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) {
TimeSeriesCollection tsc = (TimeSeriesCollection) obj;
boolean b0 = ObjectUtils.equal(this.data, tsc.data);
boolean b1 = (this.xPosition == tsc.xPosition);
boolean b2 = (this.domainIsPointsInTime == tsc.domainIsPointsInTime);
return b0 && b1 && b2;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -