|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.LiveGraph.dataCache.DataCache
public class DataCache
An instance of this class caches datasets previously read from a data file in memory.
The cache applies a smart procedure to cache just enough data in order to plot a graph
on the screen. Two cache modes are currently possible: CacheTailData
and
CacheAllData
. In the first case the data sets added most recently are
cached (and ultimately displayed bythe plotter). In the latter case all datasets are
cached. If the number of datasets grows too large, the datasets located at odd indices in
the original data file will be deleted from the cache.
After this only datasets located at even indices in the original file will be cached.
If the cache grows too large again, this procedure is re-applied such that only datasets
at indices divisible by 4 in the original file are cached. As more datasets are added to the
cache, this procedure can be re-applied again making sure that at any time the original data
file is sampled at equal intervals.
The maximum cache size is CACHE_SIZE
.
LiveGraph (http://www.live-graph.org).
Copyright (c) 2007 by G. Paperin.
File: DataCache.java
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the LiveGraph project and its web-site, the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
LiveGraph project and its web-site, the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with
the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the LiveGraph project and its
contributors.
(http://www.live-graph.org)
4. All advertising materials distributed in form of HTML pages or any other technology
permitting active hyper-links that mention features or use of this software or any
derived software must display the acknowledgment specified in condition 3 of this
agreement, and in addition, include a visible and working hyper-link to the LiveGraph
homepage (http://www.live-graph.org).
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Nested Class Summary | |
---|---|
static class |
DataCache.CacheMode
Defines possible cache modes. |
private class |
DataCache.DataSeriesLabelIterator
A read-only iterator for data series labels. |
private class |
DataCache.RemoveRangeArrayList<E>
A ArrayList which publicly publishes its removeRangeint method. |
Field Summary | |
---|---|
static int |
CACHE_SIZE
Maximum number if datasets to be held in memory. |
private DataCache.CacheMode |
currentMode
Current operating mode. |
private java.util.List<java.lang.String> |
dataFileInfo
Caches the data file info lines. |
private java.util.List<DataSeries> |
dataSeries
Stores the desctibtion of the data series in this cache. |
private java.util.List<DataSet> |
dataSets
Stores the data in this cache. |
private java.util.Set<CacheObserver.CacheEvent> |
delayedEvents
Stores occured cache events when operating in the delayed mode. |
private boolean |
delayEvents
Whether the cache events are being delayed. |
private int |
dispersalFactor
When working in CacheAllData -mode this value determines which datasets are kept in memory. |
private double |
maxValueCached
Caches the largest data value currently in the cache. |
private double |
minValueCached
Caches the smallest data value currently in the cache. |
private java.util.List<CacheObserver> |
observers
|
static int |
TAIL_BALANCE_SIZE
Number of datasets to always keep in memory when operating in CacheTailData -mode. |
Constructor Summary | |
---|---|
DataCache()
Creates a new data cache in the CacheAllData -mode. |
|
DataCache(DataCache.CacheMode mode)
Creates a new cache in the specified mode. |
|
DataCache(DataCache.CacheMode mode,
java.util.List<java.lang.String> seriesLabels)
Creates a new cache in a specified mode and initilises it for the specified data series. |
|
DataCache(DataCache.CacheMode mode,
java.lang.String[] seriesLabels)
Creates a new cache in a specified mode and initilises it for the specified data series. |
Method Summary | |
---|---|
void |
addDataFileInfo(java.lang.String info)
Caches info on the data file. |
private boolean |
addDataSet_AllDataMode(DataSet ds)
Adds a dataset when cache is in AllDataMode . |
private boolean |
addDataSet_TailDataMode(DataSet ds)
Adds a dataset when cache is in TailDataMode . |
void |
addDataSet(DataSet ds)
Adds a specified dataset to this cache. |
boolean |
addObserver(CacheObserver observer)
Adds an observer to this cache. |
int |
countDataSeries()
|
int |
countDataSets()
|
int |
countObservers()
|
int |
findDataSeriesIndex(java.lang.String label)
|
int |
findDataSeriesIndex(java.lang.String label,
boolean ignoreCase)
|
DataSet |
findDataSet(int dataFileIndex)
|
void |
fireDelayedEvents()
Ends the delayEvents -mode and returns in the normal observable mode;
all events cached while in that mode are fired. |
void |
fireEvent(CacheObserver.CacheEvent event)
Notifies the observers of a specified event. |
DataCache.CacheMode |
getCacheMode()
|
java.lang.String |
getDataFileInfo()
|
DataSeries |
getDataSeries(int index)
|
DataSet |
getDataSet(int cacheIndex)
|
int |
getMaxDataFileIndex()
|
double |
getMaxValueCached()
|
int |
getMinDataFileIndex()
|
double |
getMinValueCached()
|
java.util.List<CacheObserver> |
getObservers()
|
boolean |
hasObserver(CacheObserver observer)
|
private void |
includeExtremeValues(DataSet ds)
Updates the internal state of this cache and its data series to include the min and max values of the specified dataset. |
private void |
increaseDispersalFactor()
Increases the value which must divide datafile indices of all cached datasets without remainder. |
com.softnetConsult.utils.collections.ReadOnlyIterator<DataSeries> |
iterateDataSeries()
|
com.softnetConsult.utils.collections.ReadOnlyIterator<java.lang.String> |
iterateDataSeriesLabels()
|
com.softnetConsult.utils.collections.ReadOnlyIterator<DataSet> |
iterateDataSets()
|
java.util.List<java.lang.String> |
listDataFileInfo()
|
private void |
removeDatalistHead()
Removes the oldest datasets in this cache. |
boolean |
removeObserver(CacheObserver observer)
|
void |
resetCache()
Removes all data from this cache and resets is to the empty state. |
void |
resetCache(DataCache.CacheMode mode)
Removes all data from this cache and resets is to the empty state. |
void |
resetCache(DataCache.CacheMode mode,
java.util.List<java.lang.String> seriesLabels)
Removes all data from this cache and resets is to the empty state. |
void |
resetData()
Resets the cache while keeping the same operating mode. |
void |
resetData(DataCache.CacheMode mode)
Resets the cache to the specified mode. |
void |
resetDataFileInfo()
Delets all data file info strings held by this cache. |
private void |
resetExtremeValues()
Delets the information of min and max values held by this cache and any of its data series. |
void |
resetLabels()
Removes all data series informatioon from the cache without deleting the actual data. |
void |
resetLabels(java.util.List<java.lang.String> seriesLabels)
Removes all data series informatioon from the cache and replaces is with new empty series. |
void |
startDelayEvents()
When this method is invoked the cache enters the delayEvents -mode;
while in this mode events are not supplied to observers, instead they are cached
and fired only when fireDelayedEvents is invoked. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int CACHE_SIZE
public static final int TAIL_BALANCE_SIZE
CacheTailData
-mode.
private java.util.List<CacheObserver> observers
private java.util.List<DataSeries> dataSeries
private java.util.List<DataSet> dataSets
private DataCache.CacheMode currentMode
private int dispersalFactor
CacheAllData
-mode this value determines which datasets are kept in memory.
At any time, exactly the datasets for which DataSet.getDataFileIndex()
returns a value that
can be divided by dispersalFactor
without remainder will be kept in the cache.
private java.util.List<java.lang.String> dataFileInfo
private double minValueCached
private double maxValueCached
private java.util.Set<CacheObserver.CacheEvent> delayedEvents
private boolean delayEvents
Constructor Detail |
---|
public DataCache()
CacheAllData
-mode.
public DataCache(DataCache.CacheMode mode)
mode
- Mode of the new cache.public DataCache(DataCache.CacheMode mode, java.util.List<java.lang.String> seriesLabels)
mode
- Mode to use.seriesLabels
- Names of the data series.public DataCache(DataCache.CacheMode mode, java.lang.String[] seriesLabels)
mode
- Mode to use.seriesLabels
- Names of the data series.Method Detail |
---|
public void resetCache()
public void resetCache(DataCache.CacheMode mode)
mode
- The mode the cache will have after the reset.public void resetCache(DataCache.CacheMode mode, java.util.List<java.lang.String> seriesLabels)
mode
- The mode the cache will have after the reset.seriesLabels
- The data series labels for the reset cachepublic void resetLabels()
public void resetLabels(java.util.List<java.lang.String> seriesLabels)
seriesLabels
- Labels for the new data series.public void resetData()
public void resetData(DataCache.CacheMode mode)
mode
- New operating mode.private void resetExtremeValues()
public void resetDataFileInfo()
public DataCache.CacheMode getCacheMode()
public int countDataSeries()
public com.softnetConsult.utils.collections.ReadOnlyIterator<DataSeries> iterateDataSeries()
public DataSeries getDataSeries(int index)
index
- Data series number (0-based).
public com.softnetConsult.utils.collections.ReadOnlyIterator<java.lang.String> iterateDataSeriesLabels()
public int findDataSeriesIndex(java.lang.String label)
label
- A data series label.
public int findDataSeriesIndex(java.lang.String label, boolean ignoreCase)
label
- A data series label.ignoreCase
- Whether case shuld be ignore in string comparison.
public int countDataSets()
public com.softnetConsult.utils.collections.ReadOnlyIterator<DataSet> iterateDataSets()
public DataSet getDataSet(int cacheIndex)
cacheIndex
- Cache-index of a dataset.
public double getMinValueCached()
Double.NaN
if the cache is empty.public double getMaxValueCached()
Double.NaN
if the cache is empty.public int getMinDataFileIndex()
public int getMaxDataFileIndex()
public DataSet findDataSet(int dataFileIndex)
dataFileIndex
- An index in the original datafile.
null
if there is no such dataset in the cache.public void addDataSet(DataSet ds)
ds
- A dataset.private void includeExtremeValues(DataSet ds)
ds
- A dataset.private boolean addDataSet_AllDataMode(DataSet ds)
AllDataMode
.
ds
- A dataset.
private void increaseDispersalFactor()
AllDataMode
-mode.
private boolean addDataSet_TailDataMode(DataSet ds)
TailDataMode
.
ds
- A dataset.
true
.private void removeDatalistHead()
AllDataMode
-mode.
public void addDataFileInfo(java.lang.String info)
info
- File info.public java.util.List<java.lang.String> listDataFileInfo()
public java.lang.String getDataFileInfo()
public boolean addObserver(CacheObserver observer)
observer
- An observer.
public boolean hasObserver(CacheObserver observer)
observer
- An observer.
public boolean removeObserver(CacheObserver observer)
observer
- An observer to remove.
public int countObservers()
public java.util.List<CacheObserver> getObservers()
public void fireEvent(CacheObserver.CacheEvent event)
delayEvents
mode, the observers are not notyfied and the event is cached.
event
- An event.public void startDelayEvents()
delayEvents
-mode;
while in this mode events are not supplied to observers, instead they are cached
and fired only when fireDelayedEvents
is invoked. This is can be useful
when the cache is modified several times in one go. In such case the notification
of observers can be consolidated which might save processing similar events many times.
fireDelayedEvents()
public void fireDelayedEvents()
delayEvents
-mode and returns in the normal observable mode;
all events cached while in that mode are fired. However, each type of event
is fired at most once. The order in which the events are fires is unspecified
and might not correspond to the order in which the events actually occured.
|
LiveGraph data visualisation and analysis framework |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |