Class CalculationPart<S,T extends FeatureInput>
Object
CalculationPart<S,T>
- Type Parameters:
S
- result-type of the calculationT
- feature input-type
- All Implemented Interfaces:
ResettableCalculation
- Direct Known Subclasses:
CalculateDeriveObjectInput
,CalculateDeriveSingleMemoFromPair
,CalculateEllipseLeastSquares
,CalculateEllipsoidLeastSquares
,CalculateHistogram
,CalculateHistogramMasked
,CalculateInputFromDelegate
,CalculateInputFromPair
,CalculateNumberVoxels
,CalculateObjectMask
,CalculateShellObjectMask
public abstract class CalculationPart<S,T extends FeatureInput>
extends Object
implements ResettableCalculation
A sub-part of the calculation of a feature, that can be cached, and reused by other features.
As many features repeat the same calculation partially to determine a result, this provides a
mechanism to avoid repeating the same calculation, internally within a Feature
.
The result value is cached, until invalidate()
is called.
All sub-classes must implements an equivalence-relation via equals()
that checks if
two feature-calculations are identical. This allows the user to search through a collection of
CalculationPart
s to find one with identical parameters and re-use it.
Important note: It is therefore absolutely necessary to make sure every class has a
well-defined equals()
and hashCode()
that covers all relevant parameterization.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
protected abstract S
This performs the actual calculation when needed.getOrCalculate
(T input) Executes the operation and returns a result, either by doing the calculation, or retrieving a cached-result from previously.boolean
Has the calculation already been executed, with a cached result existing?abstract int
hashCode()
void
Resets the cached-calculation, so the next call to doOperationWithParameters() is guaranteed to calculation the operation, and store the value in the cache.
-
Constructor Details
-
CalculationPart
public CalculationPart()
-
-
Method Details
-
getOrCalculate
Executes the operation and returns a result, either by doing the calculation, or retrieving a cached-result from previously.- Parameters:
input
- If there is no cached-value, and the calculation occurs, this input is used. Otherwise ignored.- Returns:
- the result of the calculation.
- Throws:
FeatureCalculationException
- if the calculation cannot finish for whatever reason.
-
equals
-
hashCode
public abstract int hashCode() -
hasCachedResult
public boolean hasCachedResult()Has the calculation already been executed, with a cached result existing?- Returns:
- true iff a cached-result exists.
-
invalidate
public void invalidate()Description copied from interface:ResettableCalculation
Resets the cached-calculation, so the next call to doOperationWithParameters() is guaranteed to calculation the operation, and store the value in the cache.- Specified by:
invalidate
in interfaceResettableCalculation
-
execute
This performs the actual calculation when needed. It should only be called once, untilinvalidate()
is called.- Parameters:
input
- the input to the calculation.- Returns:
- the result of the calculation.
- Throws:
FeatureCalculationException
- if the calculation cannot be successfully completed.
-