Class AbstractArrayProcessorWithContextSwitching
- All Implemented Interfaces:
Cloneable
,ArrayProcessor
,ArrayProcessorWithContextSwitching
- Direct Known Subclasses:
AbstractConvolution
,AbstractDerivator
,AbstractMorphology
,GeneralizedBitProcessing
,StreamingApertureProcessor
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 Summary
ModifierConstructorDescriptionprotected
Creates an instance of this class with the given context. -
Method Summary
Modifier and TypeMethodDescriptionfinal ArrayContext
context()
This implementation of the method just returns a reference to newContext argument, passed to the constructor.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.final ArrayContext
contextPart
(double fromPart, double toPart) final MemoryModel
Returns the memory model used by this instance for all operations.
-
Constructor Details
-
AbstractArrayProcessorWithContextSwitching
Creates an instance of this class with the given context. The reference to the passed argument will be returned bycontext()
method.- Parameters:
context
- the context used by this instance for all operations (may be null).
-
-
Method Details
-
context
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 interfaceArrayProcessorWithContextSwitching
- Parameters:
newContext
- another context, used by the returned instance; may be null.- Returns:
- new instance with another context.
-
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 interfaceArrayProcessor
- Returns:
- the current context used by this instance; may be null.
-
memoryModel
Returns the memory model used by this instance for all operations. Equal tocontext()
.getMemoryModel()
ifcontext()
!=null, in other case equal toSimpleMemoryModel.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
This method returns
. This operation is needful very often while implementing most array processors.context()
== null ? null :context()
.part
(fromPart, toPart))- Parameters:
fromPart
- the estimated ready part, from 0.0 to 1.0, of the total algorithm at the start of the subtask: seeArrayContext.updateProgress(net.algart.arrays.ArrayContext.Event)
methodtoPart
- the estimated ready part, from 0.0 to 1.0, of the total algorithm at the finish of the subtask: seeArrayContext.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.
-