Package org.jfree.data.time
Class DynamicTimeSeriesCollection
- java.lang.Object
-
- org.jfree.data.general.AbstractDataset
-
- org.jfree.data.general.AbstractSeriesDataset
-
- org.jfree.data.xy.AbstractXYDataset
-
- org.jfree.data.xy.AbstractIntervalXYDataset
-
- org.jfree.data.time.DynamicTimeSeriesCollection
-
- All Implemented Interfaces:
java.io.ObjectInputValidation
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,DomainInfo
,Dataset
,SeriesChangeListener
,SeriesDataset
,RangeInfo
,IntervalXYDataset
,XYDataset
public class DynamicTimeSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, DomainInfo, RangeInfo
A dynamic dataset.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.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DynamicTimeSeriesCollection.ValueSequence
A wrapper for a fixed array of float values.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description DynamicTimeSeriesCollection(int nSeries, int nMoments)
Constructs a dataset with capacity for N series, tied to default timezone.DynamicTimeSeriesCollection(int nSeries, int nMoments, java.util.TimeZone zone)
Constructs an empty dataset, tied to a specific 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 aSeriesChangeEvent
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)
??-
Methods inherited from class org.jfree.data.xy.AbstractIntervalXYDataset
getEndXValue, getEndYValue, getStartXValue, getStartYValue
-
Methods inherited from class org.jfree.data.xy.AbstractXYDataset
getDomainOrder, getXValue
-
Methods inherited from class org.jfree.data.general.AbstractSeriesDataset
indexOf, seriesChanged
-
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, canEqual, clone, equals, fireDatasetChanged, getGroup, getNotify, hashCode, hasListener, notifyListeners, removeChangeListener, setGroup, setNotify, validateObject
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jfree.data.general.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
-
Methods inherited from interface org.jfree.data.xy.IntervalXYDataset
getEndXValue, getEndYValue, getStartXValue, getStartYValue
-
Methods inherited from interface org.jfree.data.general.SeriesDataset
indexOf
-
Methods inherited from interface org.jfree.data.xy.XYDataset
getDomainOrder, getXValue
-
-
-
-
Field Detail
-
START
public static final int START
Useful constant for controlling the x-value returned for a time period.- See Also:
- Constant Field Values
-
MIDDLE
public static final int MIDDLE
Useful constant for controlling the x-value returned for a time period.- See Also:
- Constant Field Values
-
END
public static final int END
Useful constant for controlling the x-value returned for a time period.- See Also:
- Constant Field Values
-
maximumItemCount
private int maximumItemCount
The maximum number of items for each series (can be overridden).
-
historyCount
protected int historyCount
The history count.
-
seriesKeys
private java.lang.Comparable[] seriesKeys
Storage for the series keys.
-
timePeriodClass
private java.lang.Class timePeriodClass
The time period class - barely used, and could be removed (DG).
-
pointsInTime
protected RegularTimePeriod[] pointsInTime
Storage for the x-values.
-
seriesCount
private int seriesCount
The number of series.
-
valueHistory
protected DynamicTimeSeriesCollection.ValueSequence[] valueHistory
An array for storing the objects that represent each series.
-
workingCalendar
protected java.util.Calendar workingCalendar
A working calendar (to recycle)
-
position
private int position
The position within a time period to return as the x-value (START, MIDDLE or END).
-
domainIsPointsInTime
private boolean domainIsPointsInTime
A flag that indicates that the domain is 'points in time'. If this flag is true, only the x-value is used to determine the range of values in the domain, the start and end x-values are ignored.
-
oldestAt
private int oldestAt
index for mapping: points to the oldest valid time and data.
-
newestAt
private int newestAt
Index of the newest data item.
-
deltaTime
private long deltaTime
the # of msec by which time advances.
-
domainStart
private java.lang.Long domainStart
Cached domain start (for use by DomainInfo).
-
domainEnd
private java.lang.Long domainEnd
Cached domain end (for use by DomainInfo).
-
domainRange
private Range domainRange
Cached domain range (for use by DomainInfo).
-
minValue
private java.lang.Float minValue
The minimum value.
-
maxValue
private java.lang.Float maxValue
The maximum value.
-
valueRange
private Range valueRange
The value range.
-
-
Constructor Detail
-
DynamicTimeSeriesCollection
public DynamicTimeSeriesCollection(int nSeries, int nMoments)
Constructs a dataset with capacity for N series, tied to default timezone.- Parameters:
nSeries
- the number of series to be accommodated.nMoments
- the number of TimePeriods to be spanned.
-
DynamicTimeSeriesCollection
public DynamicTimeSeriesCollection(int nSeries, int nMoments, java.util.TimeZone zone)
Constructs an empty dataset, tied to a specific timezone.- Parameters:
nSeries
- the number of series to be accommodatednMoments
- the number of TimePeriods to be spannedzone
- the timezone.
-
DynamicTimeSeriesCollection
public DynamicTimeSeriesCollection(int nSeries, int nMoments, RegularTimePeriod timeSample)
Creates a new dataset.- Parameters:
nSeries
- the number of series.nMoments
- the number of items per series.timeSample
- a time period sample.
-
DynamicTimeSeriesCollection
public DynamicTimeSeriesCollection(int nSeries, int nMoments, RegularTimePeriod timeSample, java.util.TimeZone zone)
Creates a new dataset.- Parameters:
nSeries
- the number of series.nMoments
- the number of items per series.timeSample
- a time period sample.zone
- the time zone.
-
-
Method Detail
-
setTimeBase
public long setTimeBase(RegularTimePeriod start)
Fill the pointsInTime with times using TimePeriod.next(): Will silently return if the time array was already populated. Also computes the data cached for later use by methods implementing the DomainInfo interface:- Parameters:
start
- the start.- Returns:
- ??.
-
findDomainLimits
protected void findDomainLimits()
Finds the domain limits. Note: this doesn't need to be synchronized because it's called from within another method that already is.
-
getPosition
public int getPosition()
Returns the x position type (START, MIDDLE or END).- Returns:
- The x position type.
-
setPosition
public void setPosition(int position)
Sets the x position type (START, MIDDLE or END).- Parameters:
position
- The x position type.
-
addSeries
public void addSeries(float[] values, int seriesNumber, java.lang.Comparable seriesKey)
Adds a series to the dataset. Only the y-values are supplied, the x-values are specified elsewhere.- Parameters:
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.
-
setSeriesKey
public void setSeriesKey(int seriesNumber, java.lang.Comparable key)
Sets the name of a series. If planning to add values individually.- Parameters:
seriesNumber
- the series.key
- the new key.
-
addValue
public void addValue(int seriesNumber, int index, float value)
Adds a value to a series.- Parameters:
seriesNumber
- the series index.index
- ??.value
- the value.
-
getSeriesCount
public int getSeriesCount()
Returns the number of series in the collection.- Specified by:
getSeriesCount
in interfaceSeriesDataset
- Specified by:
getSeriesCount
in classAbstractSeriesDataset
- Returns:
- The series count.
-
getItemCount
public int getItemCount(int series)
Returns the number of items in a series.For this implementation, all series have the same number of items.
- Specified by:
getItemCount
in interfaceXYDataset
- Parameters:
series
- the series index (zero-based).- Returns:
- The item count.
-
translateGet
protected int translateGet(int toFetch)
Re-map an index, for use in retrieving data.- Parameters:
toFetch
- the index.- Returns:
- The translated index.
-
offsetFromNewest
public int offsetFromNewest(int delta)
Returns the actual index to a time offset by "delta" from newestAt.- Parameters:
delta
- the delta.- Returns:
- The offset.
-
offsetFromOldest
public int offsetFromOldest(int delta)
??- Parameters:
delta
- ??- Returns:
- The offset.
-
wrapOffset
protected int wrapOffset(int protoIndex)
??- Parameters:
protoIndex
- the index.- Returns:
- The offset.
-
advanceTime
public 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.- Returns:
- The new time period.
-
invalidateRangeInfo
public void invalidateRangeInfo()
Invalidates the range info.
-
findMaxValue
protected double findMaxValue()
Returns the maximum value.- Returns:
- The maximum value.
-
getOldestIndex
public int getOldestIndex()
Returns the index of the oldest data item.- Returns:
- The index.
-
getNewestIndex
public int getNewestIndex()
Returns the index of the newest data item.- Returns:
- The index.
-
appendData
public void appendData(float[] newData)
Appends new data.- Parameters:
newData
- the data.
-
appendData
public void appendData(float[] newData, int insertionIndex, int refresh)
Appends data at specified index, for loading up with data from file(s).- Parameters:
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 )
-
getNewestTime
public RegularTimePeriod getNewestTime()
Returns the newest time.- Returns:
- The newest time.
-
getOldestTime
public RegularTimePeriod getOldestTime()
Returns the oldest time.- Returns:
- The oldest time.
-
getX
public java.lang.Number getX(int series, int item)
Returns the x-value.
-
getYValue
public double getYValue(int series, int item)
Returns the y-value.- Specified by:
getYValue
in interfaceXYDataset
- Overrides:
getYValue
in classAbstractXYDataset
- Parameters:
series
- the series index (zero-based).item
- the item index (zero-based).- Returns:
- The value.
-
getY
public java.lang.Number getY(int series, int item)
Returns the y-value.
-
getStartX
public java.lang.Number getStartX(int series, int item)
Returns the start x-value.- Specified by:
getStartX
in interfaceIntervalXYDataset
- Parameters:
series
- the series index (zero-based).item
- the item index (zero-based).- Returns:
- The value.
-
getEndX
public java.lang.Number getEndX(int series, int item)
Returns the end x-value.- Specified by:
getEndX
in interfaceIntervalXYDataset
- Parameters:
series
- the series index (zero-based).item
- the item index (zero-based).- Returns:
- The value.
-
getStartY
public java.lang.Number getStartY(int series, int item)
Returns the start y-value.- Specified by:
getStartY
in interfaceIntervalXYDataset
- Parameters:
series
- the series index (zero-based).item
- the item index (zero-based).- Returns:
- The value.
-
getEndY
public java.lang.Number getEndY(int series, int item)
Returns the end y-value.- Specified by:
getEndY
in interfaceIntervalXYDataset
- Parameters:
series
- the series index (zero-based).item
- the item index (zero-based).- Returns:
- The value.
-
getSeriesKey
public java.lang.Comparable getSeriesKey(int series)
Returns the key for a series.- Specified by:
getSeriesKey
in interfaceSeriesDataset
- Specified by:
getSeriesKey
in classAbstractSeriesDataset
- Parameters:
series
- the series index (zero-based).- Returns:
- The key.
-
fireSeriesChanged
protected void fireSeriesChanged()
Sends aSeriesChangeEvent
to all registered listeners.
-
getDomainLowerBound
public double getDomainLowerBound(boolean includeInterval)
Returns the minimum x-value in the dataset.- Specified by:
getDomainLowerBound
in interfaceDomainInfo
- Parameters:
includeInterval
- a flag that determines whether or not the x-interval is taken into account.- Returns:
- The minimum value.
-
getDomainUpperBound
public double getDomainUpperBound(boolean includeInterval)
Returns the maximum x-value in the dataset.- Specified by:
getDomainUpperBound
in interfaceDomainInfo
- Parameters:
includeInterval
- a flag that determines whether or not the x-interval is taken into account.- Returns:
- The maximum value.
-
getDomainBounds
public Range getDomainBounds(boolean includeInterval)
Returns the range of the values in this dataset's domain.- Specified by:
getDomainBounds
in interfaceDomainInfo
- Parameters:
includeInterval
- a flag that determines whether or not the x-interval is taken into account.- Returns:
- The range.
-
getX
private long getX(RegularTimePeriod period)
Returns the x-value for a time period.- Parameters:
period
- the period.- Returns:
- The x-value.
-
getRangeLowerBound
public double getRangeLowerBound(boolean includeInterval)
Returns the minimum range value.- Specified by:
getRangeLowerBound
in interfaceRangeInfo
- Parameters:
includeInterval
- a flag that determines whether or not the y-interval is taken into account.- Returns:
- The minimum range value.
-
getRangeUpperBound
public double getRangeUpperBound(boolean includeInterval)
Returns the maximum range value.- Specified by:
getRangeUpperBound
in interfaceRangeInfo
- Parameters:
includeInterval
- a flag that determines whether or not the y-interval is taken into account.- Returns:
- The maximum range value.
-
getRangeBounds
public Range getRangeBounds(boolean includeInterval)
Returns the value range.- Specified by:
getRangeBounds
in interfaceRangeInfo
- Parameters:
includeInterval
- a flag that determines whether or not the y-interval is taken into account.- Returns:
- The range.
-
-