public interface IDataProvider
An API like
public ISample[] getSamples()
would be much easier to use by the XY Graph, but it forces the data
provider to copy its samples into an array, which might be a performance and
memory problem if considerable amounts of data are held in some other data
structure that is more suitable to the application.
The API is therefore based on single-sample access, allowing the application to store the samples in arbitrary data structures.
Synchronization
Since the application data might change dynamically, the XY Graph
synchronizes
on the IDataProvider
like this to
assert that the sample count does not change while accessing individual
samples:
IDataProvider data = ...; synchronized (data) { int count = data.getSize(); ... ... getSample(i) ... }Implementations of the
IDataProvider
should likewise synchronize
on it whenever the data is changed, and other methods like
getXDataMinMax
should probably be synchronized implementations.Modifier and Type | Method and Description |
---|---|
void |
addDataProviderListener(IDataProviderListener listener) |
ISample |
getSample(int index)
Get sample by index
|
int |
getSize()
Total number of samples.
|
Range |
getXDataMinMax()
Get the minimum and maximum xdata.
|
Range |
getXDataMinMax(boolean positiveOnly)
Get the minimum and maximum xdata.
|
Range |
getYDataMinMax()
Get the minimum and maximum ydata.
|
Range |
getYDataMinMax(boolean positiveOnly)
Get the minimum and maximum ydata.
|
default boolean |
hasErrors()
This method is optional to implement.
|
boolean |
isChronological() |
boolean |
removeDataProviderListener(IDataProviderListener listener) |
int getSize()
getSample(int)
ISample getSample(int index)
Synchronization: Since the data might change dynamically,
synchronize
on the IDataProvider
around calls
to getSize()
and getSample()
.
index
- Sample index, 0...getSize()-1
Range getXDataMinMax()
Range getYDataMinMax()
Range getXDataMinMax(boolean positiveOnly)
positiveOnly
- if true, return values greater than zeroRange getYDataMinMax(boolean positiveOnly)
positiveOnly
- if true, return values greater than zeroboolean isChronological()
true
if data is ascending sorted on X axis; false otherwisevoid addDataProviderListener(IDataProviderListener listener)
listener
- New listener to notify when data changesboolean removeDataProviderListener(IDataProviderListener listener)
listener
- Listener to no longer notify when data changestrue
if listener was known and removeddefault boolean hasErrors()
ISample
has errors or not.true
if the ISample have error information.