Class AbstractArrayProcessorWithContextSwitching

java.lang.Object
net.algart.arrays.AbstractArrayProcessorWithContextSwitching
All Implemented Interfaces:
Cloneable, ArrayProcessor, ArrayProcessorWithContextSwitching
Direct Known Subclasses:
AbstractConvolution, AbstractDerivator, AbstractMorphology, GeneralizedBitProcessing, StreamingApertureProcessor

public abstract class AbstractArrayProcessorWithContextSwitching extends Object implements ArrayProcessorWithContextSwitching, Cloneable

A skeletal implementation of the ArrayProcessorWithContextSwitching interface. Usually, you need to extend this class to implement that interface.

This class stores the context, passed to the constructor and returned by context() method, in an internal field. The context(ArrayContext newContext) method, switching the context, creates new instance of this class by standard clone() method of this object and then changes the internal field (containing a reference to the current context) to the newContext value. Please override context(ArrayContext newContext) or the standard clone() method if this algorithm is not suitable.

Author:
Daniel Alievsky
  • Constructor Details

    • AbstractArrayProcessorWithContextSwitching

      protected AbstractArrayProcessorWithContextSwitching(ArrayContext context)
      Creates an instance of this class with the given context. The reference to the passed argument will be returned by context() method.
      Parameters:
      context - the context used by this instance for all operations (may be null).
  • Method Details

    • context

      public ArrayProcessorWithContextSwitching context(ArrayContext newContext)

      This method is implemented here via cloning this object (by standard clone() call) and replacing the value of the field, where a reference to the current context is stored, with newContext value. This technique is suitable for most implementation. However, if you need, you can override this method; maybe, it is enough to override clone() instead.

      Specified by:
      context in interface ArrayProcessorWithContextSwitching
      Parameters:
      newContext - another context, used by the returned instance; may be null.
      Returns:
      new instance with another context.
    • context

      public final ArrayContext context()
      This implementation of the method just returns a reference to newContext argument, passed to the constructor.

      This method works very quickly (it just returns a value of some private field).

      Specified by:
      context in interface ArrayProcessor
      Returns:
      the current context used by this instance; may be null.
    • memoryModel

      public final MemoryModel memoryModel()
      Returns the memory model used by this instance for all operations. Equal to context().getMemoryModel() if context()!=null, in other case equal to SimpleMemoryModel.getInstance().

      This method works very quickly (it just returns a value of some private field).

      Returns:
      the memory model used by this instance for all operations; cannot be null.
    • contextPart

      public final ArrayContext contextPart(double fromPart, double toPart)

      This method returns context() == null ? null : context().part(fromPart, toPart)). This operation is needful very often while implementing most array processors.

      Parameters:
      fromPart - the estimated ready part, from 0.0 to 1.0, of the total algorithm at the start of the subtask: see ArrayContext.updateProgress(net.algart.arrays.ArrayContext.Event) method
      toPart - the estimated ready part, from 0.0 to 1.0, of the total algorithm at the finish of the subtask: see ArrayContext.updateProgress(net.algart.arrays.ArrayContext.Event) method; must be not less than fromPart range.
      Returns:
      new context, describing the execution of the subtask of the current task.
      Throws:
      IllegalArgumentException - if fromPart or toPart is not in 0.0..1.0 range or if fromPart>toPart.