S
- result-typeT
- feature input-typeU
- key-typeE
- an exception thrown if something goes wrong during the calculationpublic abstract class CalculationPartMap<S,T extends FeatureInput,U,E extends Exception> extends Object implements ResettableCalculation
CalculationPart
but stores several evaluation results, differentiated by a
key.Modifier | Constructor and Description |
---|---|
protected |
CalculationPartMap(int cacheSize)
Creates for a particular cache-size.
|
Modifier and Type | Method and Description |
---|---|
abstract boolean |
equals(Object other) |
protected abstract S |
execute(T input,
U key)
Calculates a result for a particular input and key.
|
S |
getOrCalculate(T input,
U key)
Executes the operation and returns a result, either by doing the calculation, or retrieving a
cached-result from a previous execution.
|
protected S |
getOrNull(U key)
Gets an existing result for the current input from the cache.
|
abstract int |
hashCode() |
protected boolean |
hasKey(U key)
Does a result exist for the current input, and a particular key?
|
void |
invalidate()
Invalidates the cache, removing any items already stored.
|
int |
numberItemsCurrentlyStored()
Number of items currently stored in cache.
|
protected void |
put(U key,
S result)
Assigns a evaluation result to the cache for a particular key.
|
protected CalculationPartMap(int cacheSize)
cacheSize
- cache-size to use for the keys.public S getOrCalculate(T input, U key) throws E extends Exception
input
- used to calculate a result, if there is no value already cached. Ignored if a
result already exists.key
- the key, which determines if a result already exists or not.E
- if the calculation cannot finish, for whatever reason.E extends Exception
public int numberItemsCurrentlyStored()
public void invalidate()
invalidate
in interface ResettableCalculation
protected S getOrNull(U key)
key
- the key that identifies the existing result.protected boolean hasKey(U key)
key
- the key.protected void put(U key, S result)
key
- the key.result
- the result to assign.Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.