org.eclipse.ocl.examples.domain.library
Class AbstractIteration
java.lang.Object
org.eclipse.ocl.examples.domain.values.util.ValuesUtil
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, OnlyIteration, 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.
Nested Class Summary |
static class |
AbstractIteration.MutableObject
A MutableObject may be used as an iteration accumulatior containing a single changing value. |
Field Summary |
protected static java.lang.Object |
CARRY_ON
An out-of-band value that can be returned by updateAccumulator to signal
that the iteration should carry on rather than terminate using the returned value. |
Fields inherited from class org.eclipse.ocl.examples.domain.values.util.ValuesUtil |
EMPTY_BAG, EMPTY_SET, FALSE_VALUE, INTEGER_MAX_VALUE, INTEGER_MIN_VALUE, INVALID_VALUE, LONG_MAX_VALUE, LONG_MIN_VALUE, NULL_STRING, NULL_VALUE, ONE_VALUE, TRUE_VALUE, UNLIMITED_VALUE, ZERO_VALUE |
Method Summary |
java.lang.Object |
evaluateIteration(DomainIterationManager iterationManager)
The default iteration algorithm steps through the iteration domain by invoking
DomainIterationManager.hasCurrent() and DomainIterationManager.advanceIterators() . |
protected java.lang.Object |
resolveTerminalValue(DomainIterationManager iterationManager)
Return the final result at the end of an iteration over all the source elements. |
protected abstract java.lang.Object |
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.values.util.ValuesUtil |
asBagValue, asBoolean, asCollectionType, asCollectionValue, asInteger, asIntegerValue, asMetaclass, asNavigableObject, asObject, asOrderedCollectionValue, asOrderedSetValue, asRealValue, asSequenceValue, asSetValue, asString, asTupleValue, asType, asUniqueCollectionValue, asUnlimitedNaturalValue, asValue, bigDecimalValueOf, bigIntegerValueOf, characterValueOf, createBagAccumulatorValue, createBagOfEach, createBagRange, createBagValue, createCollectionAccumulatorValue, createInvalidValue, createObjectValue, createOrderedSetAccumulatorValue, createOrderedSetOfEach, createOrderedSetRange, createOrderedSetValue, createRange, createSequenceAccumulatorValue, createSequenceOfEach, createSequenceRange, createSequenceRange, createSequenceValue, createSetAccumulatorValue, createSetOfEach, createSetRange, createSetValue, createTupleOfEach, createTupleValue, createTupleValue, createTypeValue, getEcoreNumber, getTypeName, initAllStatics, integerValueOf, integerValueOf, integerValueOf, integerValueOf, integerValueOf, isBoxed, isCollectionValue, isIntegerNumber, isIntegerValue, isRealNumber, isUnboxed, isUnlimited, oclToString, realValueOf, realValueOf, realValueOf, realValueOf, realValueOf, stringValueOf, throwBooleanInvalidValueException, throwInvalidValueException, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CARRY_ON
@NonNull
protected static final java.lang.Object CARRY_ON
- An out-of-band value that can be returned by
updateAccumulator
to signal
that the iteration should carry on rather than terminate using the returned value.
AbstractIteration
public AbstractIteration()
evaluateIteration
@Nullable
public java.lang.Object evaluateIteration(@NonNull
DomainIterationManager iterationManager)
- 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:
java.lang.Exception
resolveTerminalValue
@Nullable
protected java.lang.Object resolveTerminalValue(@NonNull
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
@Nullable
protected abstract java.lang.Object updateAccumulator(@NonNull
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-CARRY_ON premature result of iteration, or CARRY_ON if complete
- Throws:
java.lang.Exception