📄 dynamictimeseriescollection.java
字号:
* Returns the index of the newest data item.
*
* @return The index.
*/
public int getNewestIndex() {
return this.newestAt;
}
// appendData() writes new data at the index position given by newestAt/
// When adding new data dynamically, use advanceTime(), followed by this:
/**
* Appends new data.
*
* @param newData the data.
*/
public void appendData(float[] newData) {
int nDataPoints = newData.length;
if (nDataPoints > this.valueHistory.length) {
throw new IllegalArgumentException(
"More data than series to put them in"
);
}
int s; // index to select the "series"
for (s = 0; s < nDataPoints; s++) {
// check whether the "valueHistory" array member exists; if not,
// create them:
if (this.valueHistory[s] == null) {
this.valueHistory[s] = new ValueSequence(this.historyCount);
}
this.valueHistory[s].enterData(this.newestAt, newData[s]);
}
fireSeriesChanged();
}
/**
* Appends data at specified index, for loading up with data from file(s).
*
* @param newData the data
* @param insertionIndex the index value at which to put it
* @param refresh value of n in "refresh the display on every nth call"
* (ignored if <= 0 )
*/
public void appendData(float[] newData, int insertionIndex, int refresh) {
int nDataPoints = newData.length;
if (nDataPoints > this.valueHistory.length) {
throw new IllegalArgumentException(
"More data than series to put them " + "in"
);
}
for (int s = 0; s < nDataPoints; s++) {
if (this.valueHistory[s] == null) {
this.valueHistory[s] = new ValueSequence(this.historyCount);
}
this.valueHistory[s].enterData(insertionIndex, newData[s]);
}
if (refresh > 0) {
insertionIndex++;
if (insertionIndex % refresh == 0) {
fireSeriesChanged();
}
}
}
/**
* Returns the newest time.
*
* @return The newest time.
*/
public RegularTimePeriod getNewestTime() {
return this.pointsInTime[this.newestAt];
}
/**
* Returns the oldest time.
*
* @return The oldest time.
*/
public RegularTimePeriod getOldestTime() {
return this.pointsInTime[this.oldestAt];
}
/**
* Returns the x-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
// getXxx() ftns can ignore the "series" argument:
// Don't synchronize this!! Instead, synchronize the loop that calls it.
public Number getX(int series, int item) {
RegularTimePeriod tp = this.pointsInTime[translateGet(item)];
return new Long(getX(tp));
}
/**
* Returns the y-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public double getYValue(int series, int item) {
// Don't synchronize this!!
// Instead, synchronize the loop that calls it.
ValueSequence values = this.valueHistory[series];
return values.getData(translateGet(item));
}
/**
* Returns the y-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getY(int series, int item) {
return new Float(getYValue(series, item));
}
/**
* Returns the start x-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getStartX(int series, int item) {
RegularTimePeriod tp = this.pointsInTime[translateGet(item)];
return new Long(tp.getFirstMillisecond(this.workingCalendar));
}
/**
* Returns the end x-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getEndX(int series, int item) {
RegularTimePeriod tp = this.pointsInTime[translateGet(item)];
return new Long(tp.getLastMillisecond(this.workingCalendar));
}
/**
* Returns the start y-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getStartY(int series, int item) {
return getY(series, item);
}
/**
* Returns the end y-value.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getEndY(int series, int item) {
return getY(series, item);
}
/* // "Extras" found useful when analyzing/verifying class behavior:
public Number getUntranslatedXValue(int series, int item)
{
return super.getXValue(series, item);
}
public float getUntranslatedY(int series, int item)
{
return super.getY(series, item);
} */
/**
* Returns the key for a series.
*
* @param series the series index (zero-based).
*
* @return The key.
*/
public Comparable getSeriesKey(int series) {
return this.seriesKeys[series];
}
/**
* Sends a {@link SeriesChangeEvent} to all registered listeners.
*/
protected void fireSeriesChanged() {
seriesChanged(new SeriesChangeEvent(this));
}
// The next 3 functions override the base-class implementation of
// the DomainInfo interface. Using saved limits (updated by
// each updateTime() call), improves performance.
//
/**
* 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) {
return this.domainStart.doubleValue();
// a Long kept updated by advanceTime()
}
/**
* 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) {
return this.domainEnd.doubleValue();
// a Long kept updated by advanceTime()
}
/**
* 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) {
if (this.domainRange == null) {
findDomainLimits();
}
return this.domainRange;
}
/**
* Returns the x-value for a time period.
*
* @param period the period.
*
* @return The x-value.
*/
private long getX(RegularTimePeriod period) {
switch (this.position) {
case (START) :
return period.getFirstMillisecond(this.workingCalendar);
case (MIDDLE) :
return period.getMiddleMillisecond(this.workingCalendar);
case (END) :
return period.getLastMillisecond(this.workingCalendar);
default:
return period.getMiddleMillisecond(this.workingCalendar);
}
}
// The next 3 functions implement the RangeInfo interface.
// Using saved limits (updated by each updateTime() call) significantly
// improves performance. WARNING: this code makes the simplifying
// assumption that data is never negative. Expand as needed for the
// general case.
/**
* Returns the minimum range value.
*
* @param includeInterval a flag that determines whether or not the
* y-interval is taken into account.
*
* @return The minimum range value.
*/
public double getRangeLowerBound(boolean includeInterval) {
double result = Double.NaN;
if (this.minValue != null) {
result = this.minValue.doubleValue();
}
return result;
}
/**
* Returns the maximum range value.
*
* @param includeInterval a flag that determines whether or not the
* y-interval is taken into account.
*
* @return The maximum range value.
*/
public double getRangeUpperBound(boolean includeInterval) {
double result = Double.NaN;
if (this.maxValue != null) {
result = this.maxValue.doubleValue();
}
return result;
}
/**
* Returns the value range.
*
* @param includeInterval a flag that determines whether or not the
* y-interval is taken into account.
*
* @return The range.
*/
public Range getRangeBounds(boolean includeInterval) {
if (this.valueRange == null) {
double max = getRangeUpperBound(includeInterval);
this.valueRange = new Range(0.0, max);
}
return this.valueRange;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -