public class DynamicTimeSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, DomainInfo, RangeInfo
Like FastTimeSeriesCollection, this class is a functional replacement for JFreeChart's TimeSeriesCollection _and_ TimeSeries classes. FastTimeSeriesCollection is appropriate for a fixed time range; for real-time applications this subclass adds the ability to append new data and discard the oldest. In this class, the arrays used in FastTimeSeriesCollection become FIFO's. NOTE:As presented here, all data is assumed >= 0, an assumption which is embodied only in methods associated with interface RangeInfo.
| Modifier and Type | Class and Description |
|---|---|
protected class |
DynamicTimeSeriesCollection.ValueSequence
A wrapper for a fixed array of float values.
|
| Modifier and Type | Field and Description |
|---|---|
private long |
deltaTime
the # of msec by which time advances.
|
private java.lang.Long |
domainEnd
Cached domain end (for use by DomainInfo).
|
private boolean |
domainIsPointsInTime
A flag that indicates that the domain is 'points in time'.
|
private Range |
domainRange
Cached domain range (for use by DomainInfo).
|
private java.lang.Long |
domainStart
Cached domain start (for use by DomainInfo).
|
static int |
END
Useful constant for controlling the x-value returned for a time period.
|
protected int |
historyCount
The history count.
|
private int |
maximumItemCount
The maximum number of items for each series (can be overridden).
|
private java.lang.Float |
maxValue
The maximum value.
|
static int |
MIDDLE
Useful constant for controlling the x-value returned for a time period.
|
private java.lang.Float |
minValue
The minimum value.
|
private int |
newestAt
Index of the newest data item.
|
private int |
oldestAt
index for mapping: points to the oldest valid time and data.
|
protected RegularTimePeriod[] |
pointsInTime
Storage for the x-values.
|
private int |
position
The position within a time period to return as the x-value (START,
MIDDLE or END).
|
private int |
seriesCount
The number of series.
|
private java.lang.Comparable[] |
seriesKeys
Storage for the series keys.
|
static int |
START
Useful constant for controlling the x-value returned for a time
period.
|
private java.lang.Class |
timePeriodClass
The time period class - barely used, and could be removed (DG).
|
protected DynamicTimeSeriesCollection.ValueSequence[] |
valueHistory
An array for storing the objects that represent each series.
|
private Range |
valueRange
The value range.
|
protected java.util.Calendar |
workingCalendar
A working calendar (to recycle)
|
| Constructor and Description |
|---|
DynamicTimeSeriesCollection(int nSeries,
int nMoments)
Constructs a dataset with capacity for N series, tied to default
timezone.
|
DynamicTimeSeriesCollection(int nSeries,
int nMoments,
RegularTimePeriod timeSample)
Creates a new dataset.
|
DynamicTimeSeriesCollection(int nSeries,
int nMoments,
RegularTimePeriod timeSample,
java.util.TimeZone zone)
Creates a new dataset.
|
DynamicTimeSeriesCollection(int nSeries,
int nMoments,
java.util.TimeZone zone)
Constructs an empty dataset, tied to a specific timezone.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSeries(float[] values,
int seriesNumber,
java.lang.Comparable seriesKey)
Adds a series to the dataset.
|
void |
addValue(int seriesNumber,
int index,
float value)
Adds a value to a series.
|
RegularTimePeriod |
advanceTime()
Adjust the array offset as needed when a new time-period is added:
Increments the indices "oldestAt" and "newestAt", mod(array length),
zeroes the series values at newestAt, returns the new TimePeriod.
|
void |
appendData(float[] newData)
Appends new data.
|
void |
appendData(float[] newData,
int insertionIndex,
int refresh)
Appends data at specified index, for loading up with data from file(s).
|
protected void |
findDomainLimits()
Finds the domain limits.
|
protected double |
findMaxValue()
Returns the maximum value.
|
protected void |
fireSeriesChanged()
Sends a
SeriesChangeEvent to all registered listeners. |
Range |
getDomainBounds(boolean includeInterval)
Returns the range of the values in this dataset's domain.
|
double |
getDomainLowerBound(boolean includeInterval)
Returns the minimum x-value in the dataset.
|
double |
getDomainUpperBound(boolean includeInterval)
Returns the maximum x-value in the dataset.
|
java.lang.Number |
getEndX(int series,
int item)
Returns the end x-value.
|
java.lang.Number |
getEndY(int series,
int item)
Returns the end y-value.
|
int |
getItemCount(int series)
Returns the number of items in a series.
|
int |
getNewestIndex()
Returns the index of the newest data item.
|
RegularTimePeriod |
getNewestTime()
Returns the newest time.
|
int |
getOldestIndex()
Returns the index of the oldest data item.
|
RegularTimePeriod |
getOldestTime()
Returns the oldest time.
|
int |
getPosition()
Returns the x position type (START, MIDDLE or END).
|
Range |
getRangeBounds(boolean includeInterval)
Returns the value range.
|
double |
getRangeLowerBound(boolean includeInterval)
Returns the minimum range value.
|
double |
getRangeUpperBound(boolean includeInterval)
Returns the maximum range value.
|
int |
getSeriesCount()
Returns the number of series in the collection.
|
java.lang.Comparable |
getSeriesKey(int series)
Returns the key for a series.
|
java.lang.Number |
getStartX(int series,
int item)
Returns the start x-value.
|
java.lang.Number |
getStartY(int series,
int item)
Returns the start y-value.
|
java.lang.Number |
getX(int series,
int item)
Returns the x-value.
|
private long |
getX(RegularTimePeriod period)
Returns the x-value for a time period.
|
java.lang.Number |
getY(int series,
int item)
Returns the y-value.
|
double |
getYValue(int series,
int item)
Returns the y-value.
|
void |
invalidateRangeInfo()
Invalidates the range info.
|
int |
offsetFromNewest(int delta)
Returns the actual index to a time offset by "delta" from newestAt.
|
int |
offsetFromOldest(int delta)
??
|
void |
setPosition(int position)
Sets the x position type (START, MIDDLE or END).
|
void |
setSeriesKey(int seriesNumber,
java.lang.Comparable key)
Sets the name of a series.
|
long |
setTimeBase(RegularTimePeriod start)
Fill the pointsInTime with times using TimePeriod.next():
Will silently return if the time array was already populated.
|
protected int |
translateGet(int toFetch)
Re-map an index, for use in retrieving data.
|
protected int |
wrapOffset(int protoIndex)
??
|
getEndXValue, getEndYValue, getStartXValue, getStartYValuegetDomainOrder, getXValueindexOf, seriesChangedaddChangeListener, clone, fireDatasetChanged, getGroup, getNotify, hasListener, notifyListeners, removeChangeListener, setGroup, setNotify, validateObjectequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetEndXValue, getEndYValue, getStartXValue, getStartYValuegetDomainOrder, getXValueindexOfaddChangeListener, getGroup, removeChangeListener, setGrouppublic static final int START
public static final int MIDDLE
public static final int END
private int maximumItemCount
protected int historyCount
private java.lang.Comparable[] seriesKeys
private java.lang.Class timePeriodClass
protected RegularTimePeriod[] pointsInTime
private int seriesCount
protected DynamicTimeSeriesCollection.ValueSequence[] valueHistory
protected java.util.Calendar workingCalendar
private int position
private boolean domainIsPointsInTime
private int oldestAt
private int newestAt
private long deltaTime
private java.lang.Long domainStart
private java.lang.Long domainEnd
private Range domainRange
private java.lang.Float minValue
private java.lang.Float maxValue
private Range valueRange
public DynamicTimeSeriesCollection(int nSeries,
int nMoments)
nSeries - the number of series to be accommodated.nMoments - the number of TimePeriods to be spanned.public DynamicTimeSeriesCollection(int nSeries,
int nMoments,
java.util.TimeZone zone)
nSeries - the number of series to be accommodatednMoments - the number of TimePeriods to be spannedzone - the timezone.public DynamicTimeSeriesCollection(int nSeries,
int nMoments,
RegularTimePeriod timeSample)
nSeries - the number of series.nMoments - the number of items per series.timeSample - a time period sample.public DynamicTimeSeriesCollection(int nSeries,
int nMoments,
RegularTimePeriod timeSample,
java.util.TimeZone zone)
nSeries - the number of series.nMoments - the number of items per series.timeSample - a time period sample.zone - the time zone.public long setTimeBase(RegularTimePeriod start)
start - the start.protected void findDomainLimits()
public int getPosition()
public void setPosition(int position)
position - The x position type.public void addSeries(float[] values,
int seriesNumber,
java.lang.Comparable seriesKey)
values - the y-values.seriesNumber - the series index (zero-based).seriesKey - the series key.
Use this as-is during setup only, or add the synchronized keyword around
the copy loop.public void setSeriesKey(int seriesNumber,
java.lang.Comparable key)
seriesNumber - the series.key - the new key.public void addValue(int seriesNumber,
int index,
float value)
seriesNumber - the series index.index - ??.value - the value.public int getSeriesCount()
getSeriesCount in interface SeriesDatasetgetSeriesCount in class AbstractSeriesDatasetpublic int getItemCount(int series)
For this implementation, all series have the same number of items.
getItemCount in interface XYDatasetseries - the series index (zero-based).protected int translateGet(int toFetch)
toFetch - the index.public int offsetFromNewest(int delta)
delta - the delta.public int offsetFromOldest(int delta)
delta - ??protected int wrapOffset(int protoIndex)
protoIndex - the index.public RegularTimePeriod advanceTime()
public void invalidateRangeInfo()
protected double findMaxValue()
public int getOldestIndex()
public int getNewestIndex()
public void appendData(float[] newData)
newData - the data.public void appendData(float[] newData,
int insertionIndex,
int refresh)
newData - the datainsertionIndex - the index value at which to put itrefresh - value of n in "refresh the display on every nth call"
(ignored if <= 0 )public RegularTimePeriod getNewestTime()
public RegularTimePeriod getOldestTime()
public java.lang.Number getX(int series,
int item)
public double getYValue(int series,
int item)
getYValue in interface XYDatasetgetYValue in class AbstractXYDatasetseries - the series index (zero-based).item - the item index (zero-based).public java.lang.Number getY(int series,
int item)
public java.lang.Number getStartX(int series,
int item)
getStartX in interface IntervalXYDatasetseries - the series index (zero-based).item - the item index (zero-based).public java.lang.Number getEndX(int series,
int item)
getEndX in interface IntervalXYDatasetseries - the series index (zero-based).item - the item index (zero-based).public java.lang.Number getStartY(int series,
int item)
getStartY in interface IntervalXYDatasetseries - the series index (zero-based).item - the item index (zero-based).public java.lang.Number getEndY(int series,
int item)
getEndY in interface IntervalXYDatasetseries - the series index (zero-based).item - the item index (zero-based).public java.lang.Comparable getSeriesKey(int series)
getSeriesKey in interface SeriesDatasetgetSeriesKey in class AbstractSeriesDatasetseries - the series index (zero-based).protected void fireSeriesChanged()
SeriesChangeEvent to all registered listeners.public double getDomainLowerBound(boolean includeInterval)
getDomainLowerBound in interface DomainInfoincludeInterval - a flag that determines whether or not the
x-interval is taken into account.public double getDomainUpperBound(boolean includeInterval)
getDomainUpperBound in interface DomainInfoincludeInterval - a flag that determines whether or not the
x-interval is taken into account.public Range getDomainBounds(boolean includeInterval)
getDomainBounds in interface DomainInfoincludeInterval - a flag that determines whether or not the
x-interval is taken into account.private long getX(RegularTimePeriod period)
period - the period.public double getRangeLowerBound(boolean includeInterval)
getRangeLowerBound in interface RangeInfoincludeInterval - a flag that determines whether or not the
y-interval is taken into account.public double getRangeUpperBound(boolean includeInterval)
getRangeUpperBound in interface RangeInfoincludeInterval - a flag that determines whether or not the
y-interval is taken into account.public Range getRangeBounds(boolean includeInterval)
getRangeBounds in interface RangeInfoincludeInterval - a flag that determines whether or not the
y-interval is taken into account.