Class CalculatedValueCache
- All Implemented Interfaces:
ICalculatedValueCache
The CalculatedValueCache uses implementations of
ICalculatedValueCacheKey
as the key for the value cache. Usually the
internal default implementations for column or row position, or the
column-row coordinates should fit most of the use cases.
-
Constructor Summary
ConstructorDescriptionCalculatedValueCache
(ILayer layer, boolean useColumnAsKey, boolean useRowAsKey) Creates a new CalculatedValueCache for the specified layer that performs smooth updates of the calculated values.CalculatedValueCache
(ILayer layer, boolean useColumnAsKey, boolean useRowAsKey, boolean smoothUpdates) Creates a new CalculatedValueCache for the specified layer. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToCache
(ICalculatedValueCacheKey key, Object value) Adds the given value to the cache and the cache-copy.void
Clear the internal cache.void
dispose()
Cleaning up internal resources like shutting down the ExecutorService.getCalculatedValue
(int columnPosition, int rowPosition, boolean calculateInBackground, ICalculator calculator) Returns the calculated value for the specified column and row position.getCalculatedValue
(int columnPosition, int rowPosition, ICalculatedValueCacheKey key, boolean calculateInBackground, ICalculator calculator) Returns the calculated value for the specified column and row position.void
Kills all cached values.void
Set the layer that should be used by this CalculatedValueCache to trigger updates after the calculation processing is done.
-
Constructor Details
-
CalculatedValueCache
Creates a new CalculatedValueCache for the specified layer that performs smooth updates of the calculated values.Setting one or both key flags to
true
will enable automatic cache key resolution dependent on the configuration. Setting both values tofalse
will leave the developer to usegetCalculatedValue(int, int, ICalculatedValueCacheKey, boolean, ICalculator)
as it is not possible to determine the ICalculatedValueCacheKey automatically.- Parameters:
layer
- The layer to which the CalculatedValueCache is connected.useColumnAsKey
- Flag to specify if the column position should be used as cache key.useRowAsKey
- Flag to specify if the row position should be used as cache key.
-
CalculatedValueCache
public CalculatedValueCache(ILayer layer, boolean useColumnAsKey, boolean useRowAsKey, boolean smoothUpdates) Creates a new CalculatedValueCache for the specified layer. This constructor additionally allows to specify if the updates of the calculated values should be performed smoothly or not. That means if a value needs to be recalculated, on smooth updating the old value will be returned until the new value is calculated. Non-smooth updates will returnnull
until the re-calculation is done.Setting one or both key flags to
true
will enable automatic cache key resolution dependent on the configuration. Setting both values tofalse
will leave the developer to usegetCalculatedValue(int, int, ICalculatedValueCacheKey, boolean, ICalculator)
as it is not possible to determine the ICalculatedValueCacheKey automatically.- Parameters:
layer
- The layer to which the CalculatedValueCache is connected.useColumnAsKey
- Flag to specify if the column position should be used as cache key.useRowAsKey
- Flag to specify if the row position should be used as cache key.smoothUpdates
- Flag to specify if the update of the calculated values should be performed smoothly.
-
-
Method Details
-
getCalculatedValue
public Object getCalculatedValue(int columnPosition, int rowPosition, boolean calculateInBackground, ICalculator calculator) Description copied from interface:ICalculatedValueCache
Returns the calculated value for the specified column and row position. If there is no calculated value for that coordinates in the cache or there is a potentially stale value, the re-calculation of the value is executed.This method tries to use a predefined cache key dependent on the configuration of this CalculatedValueCache.
- Specified by:
getCalculatedValue
in interfaceICalculatedValueCache
- Parameters:
columnPosition
- The column position of the requested value.rowPosition
- The row position of the requested value.calculateInBackground
- Flag to specify whether the value calculation should be processed in the background or not. Setting this value tofalse
will cause calculation in the UI thread, which is usually necessary in case of exporting and printing.calculator
- TheICalculator
that is used for calculating the values.- Returns:
- The value for the given coordinates.
-
getCalculatedValue
public Object getCalculatedValue(int columnPosition, int rowPosition, ICalculatedValueCacheKey key, boolean calculateInBackground, ICalculator calculator) Description copied from interface:ICalculatedValueCache
Returns the calculated value for the specified column and row position. If there is no calculated value for that coordinates in the cache or there is a potentially stale value, the re-calculation of the value is executed.This method uses the given ICalculatedValueCacheKey instead of determining the cache key out of the CalculatedValueCache key configuration.
- Specified by:
getCalculatedValue
in interfaceICalculatedValueCache
- Parameters:
columnPosition
- The column position of the requested value.rowPosition
- The row position of the requested value.key
- The key that is used by this CalculatedValueCache.calculateInBackground
- Flag to specify whether the value calculation should be processed in the background or not. Setting this value tofalse
will cause calculation in the UI thread, which is usually necessary in case of exporting and printing.calculator
- TheICalculator
that is used for calculating the values.- Returns:
- The value for the given coordinates.
-
clearCache
public void clearCache()Description copied from interface:ICalculatedValueCache
Clear the internal cache. Doing this will result in triggering new calculations. If the values where calculated before, using the cache copy still the already calculated values will be returned until the new calculation is done.- Specified by:
clearCache
in interfaceICalculatedValueCache
-
killCache
public void killCache()Description copied from interface:ICalculatedValueCache
Kills all cached values. The internal cache aswell as the cache copy to support smooth updates of values. This is necessary because on structural changes, e.g. deleting/adding rows, the cache copy would return false values.- Specified by:
killCache
in interfaceICalculatedValueCache
-
addToCache
Adds the given value to the cache and the cache-copy. This way the new calculated value gets propagated to both cache instances.- Parameters:
key
- The key to which the calculated value belongs to.value
- The value for the given coordinates to be cached.
-
dispose
public void dispose()Description copied from interface:ICalculatedValueCache
Cleaning up internal resources like shutting down the ExecutorService.- Specified by:
dispose
in interfaceICalculatedValueCache
-
setLayer
Description copied from interface:ICalculatedValueCache
Set the layer that should be used by this CalculatedValueCache to trigger updates after the calculation processing is done. Necessary if the caching is connected to a data provider for example, which is not able to fire events itself.- Specified by:
setLayer
in interfaceICalculatedValueCache
- Parameters:
layer
- The ILayer that should be used to fire the CellVisualChangeEvent after the background calculation process is done.
-