Class CalculationPart<S,T extends FeatureInput>

Object
CalculationPart<S,T>
Type Parameters:
S - result-type of the calculation
T - 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 CalculationParts 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    equals(Object other)
     
    protected abstract S
    execute(T input)
    This performs the actual calculation when needed.
    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
     
    void
    Resets the cached-calculation, so the next call to doOperationWithParameters() is guaranteed to calculation the operation, and store the value in the cache.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CalculationPart

      public CalculationPart()
  • Method Details

    • getOrCalculate

      public S getOrCalculate(T input) throws FeatureCalculationException
      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

      public abstract boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • 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 interface ResettableCalculation
    • execute

      protected abstract S execute(T input) throws FeatureCalculationException
      This performs the actual calculation when needed. It should only be called once, until invalidate() is called.
      Parameters:
      input - the input to the calculation.
      Returns:
      the result of the calculation.
      Throws:
      FeatureCalculationException - if the calculation cannot be successfully completed.