📄 dynamictimeseriescollection.valuesequence.html
字号:
<FONT color="green">586</FONT> } /*** If data can be < 0, add code here to check the minimum **/<a name="line.586"></a><FONT color="green">587</FONT> if (extremaChanged) {<a name="line.587"></a><FONT color="green">588</FONT> invalidateRangeInfo();<a name="line.588"></a><FONT color="green">589</FONT> }<a name="line.589"></a><FONT color="green">590</FONT> // wipe the next (about to be used) set of data slots<a name="line.590"></a><FONT color="green">591</FONT> float wiper = (float) 0.0;<a name="line.591"></a><FONT color="green">592</FONT> for (int s = 0; s < getSeriesCount(); s++) {<a name="line.592"></a><FONT color="green">593</FONT> this.valueHistory[s].enterData(this.newestAt, wiper);<a name="line.593"></a><FONT color="green">594</FONT> }<a name="line.594"></a><FONT color="green">595</FONT> // Update the array of TimePeriods:<a name="line.595"></a><FONT color="green">596</FONT> this.pointsInTime[this.newestAt] = nextInstant;<a name="line.596"></a><FONT color="green">597</FONT> // Now advance "oldestAt", wrapping at end of the array<a name="line.597"></a><FONT color="green">598</FONT> this.oldestAt++;<a name="line.598"></a><FONT color="green">599</FONT> if (this.oldestAt >= this.historyCount) {<a name="line.599"></a><FONT color="green">600</FONT> this.oldestAt = 0;<a name="line.600"></a><FONT color="green">601</FONT> }<a name="line.601"></a><FONT color="green">602</FONT> // Update the domain limits:<a name="line.602"></a><FONT color="green">603</FONT> long startL = this.domainStart.longValue(); //(time is kept in msec)<a name="line.603"></a><FONT color="green">604</FONT> this.domainStart = new Long(startL + this.deltaTime);<a name="line.604"></a><FONT color="green">605</FONT> long endL = this.domainEnd.longValue();<a name="line.605"></a><FONT color="green">606</FONT> this.domainEnd = new Long(endL + this.deltaTime);<a name="line.606"></a><FONT color="green">607</FONT> this.domainRange = new Range(startL, endL);<a name="line.607"></a><FONT color="green">608</FONT> fireSeriesChanged();<a name="line.608"></a><FONT color="green">609</FONT> return nextInstant;<a name="line.609"></a><FONT color="green">610</FONT> }<a name="line.610"></a><FONT color="green">611</FONT> <a name="line.611"></a><FONT color="green">612</FONT> // If data can be < 0, the next 2 methods should be modified<a name="line.612"></a><FONT color="green">613</FONT> <a name="line.613"></a><FONT color="green">614</FONT> /**<a name="line.614"></a><FONT color="green">615</FONT> * Invalidates the range info.<a name="line.615"></a><FONT color="green">616</FONT> */<a name="line.616"></a><FONT color="green">617</FONT> public void invalidateRangeInfo() {<a name="line.617"></a><FONT color="green">618</FONT> this.maxValue = null;<a name="line.618"></a><FONT color="green">619</FONT> this.valueRange = null;<a name="line.619"></a><FONT color="green">620</FONT> }<a name="line.620"></a><FONT color="green">621</FONT> <a name="line.621"></a><FONT color="green">622</FONT> /**<a name="line.622"></a><FONT color="green">623</FONT> * Returns the maximum value.<a name="line.623"></a><FONT color="green">624</FONT> *<a name="line.624"></a><FONT color="green">625</FONT> * @return The maximum value.<a name="line.625"></a><FONT color="green">626</FONT> */<a name="line.626"></a><FONT color="green">627</FONT> protected double findMaxValue() {<a name="line.627"></a><FONT color="green">628</FONT> double max = 0.0f;<a name="line.628"></a><FONT color="green">629</FONT> for (int s = 0; s < getSeriesCount(); s++) {<a name="line.629"></a><FONT color="green">630</FONT> for (int i = 0; i < this.historyCount; i++) {<a name="line.630"></a><FONT color="green">631</FONT> double tmp = getYValue(s, i);<a name="line.631"></a><FONT color="green">632</FONT> if (tmp > max) {<a name="line.632"></a><FONT color="green">633</FONT> max = tmp;<a name="line.633"></a><FONT color="green">634</FONT> }<a name="line.634"></a><FONT color="green">635</FONT> }<a name="line.635"></a><FONT color="green">636</FONT> }<a name="line.636"></a><FONT color="green">637</FONT> return max;<a name="line.637"></a><FONT color="green">638</FONT> }<a name="line.638"></a><FONT color="green">639</FONT> <a name="line.639"></a><FONT color="green">640</FONT> /** End, positive-data-only code **/<a name="line.640"></a><FONT color="green">641</FONT> <a name="line.641"></a><FONT color="green">642</FONT> /**<a name="line.642"></a><FONT color="green">643</FONT> * Returns the index of the oldest data item.<a name="line.643"></a><FONT color="green">644</FONT> *<a name="line.644"></a><FONT color="green">645</FONT> * @return The index.<a name="line.645"></a><FONT color="green">646</FONT> */<a name="line.646"></a><FONT color="green">647</FONT> public int getOldestIndex() {<a name="line.647"></a><FONT color="green">648</FONT> return this.oldestAt;<a name="line.648"></a><FONT color="green">649</FONT> }<a name="line.649"></a><FONT color="green">650</FONT> <a name="line.650"></a><FONT color="green">651</FONT> /**<a name="line.651"></a><FONT color="green">652</FONT> * Returns the index of the newest data item.<a name="line.652"></a><FONT color="green">653</FONT> *<a name="line.653"></a><FONT color="green">654</FONT> * @return The index.<a name="line.654"></a><FONT color="green">655</FONT> */<a name="line.655"></a><FONT color="green">656</FONT> public int getNewestIndex() {<a name="line.656"></a><FONT color="green">657</FONT> return this.newestAt;<a name="line.657"></a><FONT color="green">658</FONT> }<a name="line.658"></a><FONT color="green">659</FONT> <a name="line.659"></a><FONT color="green">660</FONT> // appendData() writes new data at the index position given by newestAt/<a name="line.660"></a><FONT color="green">661</FONT> // When adding new data dynamically, use advanceTime(), followed by this:<a name="line.661"></a><FONT color="green">662</FONT> /**<a name="line.662"></a><FONT color="green">663</FONT> * Appends new data.<a name="line.663"></a><FONT color="green">664</FONT> *<a name="line.664"></a><FONT color="green">665</FONT> * @param newData the data.<a name="line.665"></a><FONT color="green">666</FONT> */<a name="line.666"></a><FONT color="green">667</FONT> public void appendData(float[] newData) {<a name="line.667"></a><FONT color="green">668</FONT> int nDataPoints = newData.length;<a name="line.668"></a><FONT color="green">669</FONT> if (nDataPoints > this.valueHistory.length) {<a name="line.669"></a><FONT color="green">670</FONT> throw new IllegalArgumentException(<a name="line.670"></a><FONT color="green">671</FONT> "More data than series to put them in"<a name="line.671"></a><FONT color="green">672</FONT> );<a name="line.672"></a><FONT color="green">673</FONT> }<a name="line.673"></a><FONT color="green">674</FONT> int s; // index to select the "series"<a name="line.674"></a><FONT color="green">675</FONT> for (s = 0; s < nDataPoints; s++) {<a name="line.675"></a><FONT color="green">676</FONT> // check whether the "valueHistory" array member exists; if not, <a name="line.676"></a><FONT color="green">677</FONT> // create them:<a name="line.677"></a><FONT color="green">678</FONT> if (this.valueHistory[s] == null) {<a name="line.678"></a><FONT color="green">679</FONT> this.valueHistory[s] = new ValueSequence(this.historyCount);<a name="line.679"></a><FONT color="green">680</FONT> }<a name="line.680"></a><FONT color="green">681</FONT> this.valueHistory[s].enterData(this.newestAt, newData[s]);<a name="line.681"></a><FONT color="green">682</FONT> }<a name="line.682"></a><FONT color="green">683</FONT> fireSeriesChanged();<a name="line.683"></a><FONT color="green">684</FONT> }<a name="line.684"></a><FONT color="green">685</FONT> <a name="line.685"></a><FONT color="green">686</FONT> /**<a name="line.686"></a><FONT color="green">687</FONT> * Appends data at specified index, for loading up with data from file(s).<a name="line.687"></a><FONT color="green">688</FONT> *<a name="line.688"></a><FONT color="green">689</FONT> * @param newData the data<a name="line.689"></a><FONT color="green">690</FONT> * @param insertionIndex the index value at which to put it<a name="line.690"></a><FONT color="green">691</FONT> * @param refresh value of n in "refresh the display on every nth call"<a name="line.691"></a><FONT color="green">692</FONT> * (ignored if <= 0 )<a name="line.692"></a><FONT color="green">693</FONT> */<a name="line.693"></a><FONT color="green">694</FONT> public void appendData(float[] newData, int insertionIndex, int refresh) {<a name="line.694"></a><FONT color="green">695</FONT> int nDataPoints = newData.length;<a name="line.695"></a><FONT color="green">696</FONT> if (nDataPoints > this.valueHistory.length) {<a name="line.696"></a><FONT color="green">697</FONT> throw new IllegalArgumentException(<a name="line.697"></a><FONT color="green">698</FONT> "More data than series to put them " + "in"<a name="line.698"></a><FONT color="green">699</FONT> );<a name="line.699"></a><FONT color="green">700</FONT> }<a name="line.700"></a><FONT color="green">701</FONT> for (int s = 0; s < nDataPoints; s++) {<a name="line.701"></a><FONT color="green">702</FONT> if (this.valueHistory[s] == null) {<a name="line.702"></a><FONT color="green">703</FONT> this.valueHistory[s] = new ValueSequence(this.historyCount);<a name="line.703"></a><FONT color="green">704</FONT> }<a name="line.704"></a><FONT color="green">705</FONT> this.valueHistory[s].enterData(insertionIndex, newData[s]);<a name="line.705"></a><FONT color="green">706</FONT> }<a name="line.706"></a><FONT color="green">707</FONT> if (refresh > 0) {<a name="line.707"></a><FONT color="green">708</FONT> insertionIndex++;<a name="line.708"></a><FONT color="green">709</FONT> if (insertionIndex % refresh == 0) {<a name="line.709"></a><FONT color="green">710</FONT> fireSeriesChanged();<a name="line.710"></a><FONT color="green">711</FONT> }<a name="line.711"></a><FONT color="green">712</FONT> }<a name="line.712"></a><FONT color="green">713</FONT> }<a name="line.713"></a><FONT color="green">714</FONT> <a name="line.714"></a><FONT color="green">715</FONT> /**<a name="line.715"></a><FONT color="green">716</FONT> * Returns the newest time.<a name="line.716"></a><FONT color="green">717</FONT> *<a name="line.717"></a><FONT color="green">718</FONT> * @return The newest time.<a name="line.718"></a><FONT color="green">719</FONT> */<a name="line.719"></a><FONT color="green">720</FONT> public RegularTimePeriod getNewestTime() {<a name="line.720"></a><FONT color="green">721</FONT> return this.pointsInTime[this.newestAt];<a name="line.721"></a><FONT color="green">722</FONT> }<a name="line.722"></a><FONT color="green">723</FONT> <a name="line.723"></a><FONT color="green">724</FONT> /**<a name="line.724"></a><FONT color="green">725</FONT> * Returns the oldest time.<a name="line.725"></a><FONT color="green">726</FONT> *<a name="line.726"></a><FONT color="green">727</FONT> * @return The oldest time.<a name="line.727"></a><FONT color="green">728</FONT> */<a name="line.728"></a><FONT color="green">729</FONT> public RegularTimePeriod getOldestTime() {<a name="line.729"></a><FONT color="green">730</F
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -