org.eclipse.ocl.examples.domain.library
Class AbstractIteration

java.lang.Object
  extended by org.eclipse.ocl.examples.domain.library.AbstractFeature
      extended by org.eclipse.ocl.examples.domain.library.AbstractIteration
All Implemented Interfaces:
LibraryFeature, LibraryIteration
Direct Known Subclasses:
AnyIteration, ClosureIteration, CollectIteration, CollectNestedIteration, ExistsIteration, ForAllIteration, IsUniqueIteration, IterateIteration, OneIteration, RejectIteration, SelectIteration, SortedByIteration

public abstract class AbstractIteration
extends AbstractFeature
implements LibraryIteration

AbstractIteration realizes shared characteristics of library iterations by providing a default iteration algorithm with a call-back at each iteration step.


Constructor Summary
AbstractIteration()
           
 
Method Summary
 Value evaluateIteration(DomainIterationManager iterationManager)
          The default iteration algorithm steps through the iteration domain by invoking DomainIterationManager.hasCurrent() and DomainIterationManager.advanceIterators().
protected  Value resolveTerminalValue(DomainIterationManager iterationManager)
          Return the final result at the end of an iteration over all the source elements.
protected abstract  Value updateAccumulator(DomainIterationManager iterationManager)
          Update the accumulatorValue with the bodyValue resulting from the current iteration for which the iterators define the context in the environment.
 
Methods inherited from class org.eclipse.ocl.examples.domain.library.AbstractFeature
getLibraryValidator, getValidator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.ocl.examples.domain.library.LibraryIteration
createAccumulatorValue
 
Methods inherited from interface org.eclipse.ocl.examples.domain.library.LibraryFeature
getValidator
 

Constructor Detail

AbstractIteration

public AbstractIteration()
Method Detail

evaluateIteration

public Value evaluateIteration(DomainIterationManager iterationManager)
                        throws InvalidValueException
The default iteration algorithm steps through the iteration domain by invoking DomainIterationManager.hasCurrent() and DomainIterationManager.advanceIterators(). At each step updateAccumulator(DomainIterationManager) is invoked to update the accumulator for that step. A non-null return causes a premature exit and forms the return from the overall evaluation. If all steps complete resolveTerminalValue(DomainIterationManager) is invoked to provide the return value.

Derived classes may override this method to change the iteration algorithm or override the call-backs to customize the default iteration.

Specified by:
evaluateIteration in interface LibraryIteration
Parameters:
iterationManager - the iteration space
Returns:
the result
Throws:
InvalidValueException - if a body evaluates to invalid

resolveTerminalValue

protected Value resolveTerminalValue(DomainIterationManager iterationManager)
Return the final result at the end of an iteration over all the source elements. The default implementation just returns the accumulator. Derived iterations should override.
This method is bypassed if the iteration ends prematurely.

Parameters:
iterationManager - the iteration context
Returns:
the result

updateAccumulator

protected abstract Value updateAccumulator(DomainIterationManager iterationManager)
Update the accumulatorValue with the bodyValue resulting from the current iteration for which the iterators define the context in the environment.

Parameters:
iterationManager - the iteration context
Returns:
non-null premature result of iteration, or null if complete
Throws:
InvalidEvaluationException