org.eclipse.ocl.examples.domain.library
Class AbstractIteration
java.lang.Object
org.eclipse.ocl.examples.domain.library.AbstractFeature
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.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AbstractIteration
public AbstractIteration()
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