Class DefaultDiffEngine
- All Implemented Interfaces:
IDiffEngine
Match object.
This default implementation aims at being generic enough to be used for any model, whatever the metamodel. However, specific differences, refinements of differences or even higher level differences might be necessary.
TODO document available extension possibilities.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ObjectWe'll use this "placeholder" to differentiate the unmatched elements from the "null" values that attributes can legitimately use. -
Constructor Summary
ConstructorsConstructorDescriptionCreate the diff engine.DefaultDiffEngine(IDiffProcessor processor) Create the diff engine. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckForDifferences(Match match, Monitor monitor) Checks the givenMatch's sides for potential differences.protected voidcheckResourceAttachment(Match match, Monitor monitor) Checks whether the givenMatch's sides have changed resources.protected voidcomputeContainmentDifferences(Match match, EReference reference, boolean checkOrdering) Delegates the computation of Differences for a given containment reference according to the type of comparison (two- or three-way), and whether we need to take ordering changes into account.protected voidcomputeContainmentDifferencesThreeWay(Match match, EReference reference, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given containmentreference.protected voidcomputeContainmentDifferencesTwoWay(Match match, EReference reference, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given containmentreference.protected voidcomputeDifferences(Match match, EAttribute attribute, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the givenattribute.protected voidcomputeDifferences(Match match, EReference reference, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the givenreference.protected voidcomputeMultiValuedFeatureDifferences(Match match, EStructuralFeature feature, boolean checkOrdering) Delegates the computation of Differences for a given muti-valued feature according to the type of comparison (two- or three-way), and whether we need to take ordering changes into account.protected voidcomputeMultiValuedFeatureDifferencesThreeWay(Match match, EStructuralFeature feature, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given multi-valuedfeature.protected voidcomputeMultiValuedFeatureDifferencesTwoWay(Match match, EStructuralFeature feature, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given multi-valuedfeature.protected voidcomputeSingleValuedAttributeDifferences(Match match, EAttribute attribute) Computes the difference between the sides of the givenmatchfor the given single-valuedattribute.protected voidcomputeSingleValuedReferenceDifferencesThreeWay(Match match, EReference reference) Computes the difference between the sides of the givenmatchfor the given single-valuedreference.protected voidcomputeSingleValuedReferenceDifferencesTwoWay(Match match, EReference reference) Computes the difference between the sides of the givenmatchfor the given single-valuedreference.protected voidcreateContainmentDifferences(Match match, EReference reference, boolean checkOrdering, List<Object> values, List<Object> lcsWithOrigin, DifferenceSource side) Called fromcomputeContainmentDifferencesThreeWay(Match, EReference, boolean)once our LCS have been computed and we know what really changed.protected voidcreateContainmentDifferencesNoOrdering(Match match, EReference reference, List<Object> sideValues, DifferenceSource side) This will iterate over the given list of values from a containment reference and create the differences that can be detected from it.protected FeatureFilterThis will be used in order to create theFeatureFilterthat should be used by this engine to determine the structural features on which it is to try and detect differences.protected voidcreateMultiValuedFeatureDifferencesNoOrdering(Match match, EStructuralFeature feature, List<Object> sideValues, List<Object> originValues, DifferenceSource side) This will iterate over the given list of values from a multi-valued feature and create the differences that can be detected from it.voiddiff(Comparison comparison, Monitor monitor) This is the entry point of the differencing process.protected voidfeatureChange(Match match, EStructuralFeature feature, Object value, DifferenceKind kind, DifferenceSource source) Delegates to the diff processor to create the specified feature change.protected final IDiffProcessorThis will return the diff processor that has been created through#createDiffProcessor()for this differencing process.protected static com.google.common.base.Optional<Object>getIfPresent(List<Object> list, int index) This will be used in order to read the LCS synchronously with the iteration on its target lists' values.protected static com.google.common.base.Optional<Match>getMatchIfPresent(Comparison comparison, List<Object> list, int index) This will be used in order to read the LCS synchronously with the iteration on its target lists' values.protected <E> intindexOf(Comparison comparison, List<E> list, E element) Checks whether the givenlistcontains the givenelementaccording to the semantics ofIEqualityHelper#matchingValues(Comparison, Object, Object)and returns the index at which it is positioned if applicable.protected static booleanChecks whether the given EObject is a root of its resource or not.protected booleanmatchingContainment(IEqualityHelper equalityHelper, EObject o1, EObject o2) Checks whether the two given EObjects are contained within the same object, under the same reference.
-
Field Details
-
UNMATCHED_VALUE
We'll use this "placeholder" to differentiate the unmatched elements from the "null" values that attributes can legitimately use.
-
-
Constructor Details
-
DefaultDiffEngine
public DefaultDiffEngine()Create the diff engine. -
DefaultDiffEngine
Create the diff engine.- Parameters:
processor- this instance will be called for each detected difference.
-
-
Method Details
-
indexOf
Checks whether the givenlistcontains the givenelementaccording to the semantics ofIEqualityHelper#matchingValues(Comparison, Object, Object)and returns the index at which it is positioned if applicable.- Type Parameters:
E- Type of the input iterable's content.- Parameters:
comparison- This will be used in order to retrieve the Match for EObjects when comparing them.list- List which content we are to check.element- The element we expect to be contained inlist.- Returns:
- The index at which the given
listcontainselement,-1otherwise.
-
diff
This is the entry point of the differencing process.It will complete the input
comparisonby iterating over thematchesit contain, filling in the differences it can detect for each distinct Match.- Specified by:
diffin interfaceIDiffEngine- Parameters:
comparison- The comparison this engine is expected to complete.monitor- The monitor to report progress or to check for cancellation.- See Also:
-
checkForDifferences
Checks the givenMatch's sides for potential differences. Will recursively check for differences on submatches.- Parameters:
match- The match that is to be checked.monitor- The monitor to report progress or to check for cancellation.
-
checkResourceAttachment
Checks whether the givenMatch's sides have changed resources. This will only be called forMatchelements referencing the root(s) of an EMF Resource.- Parameters:
match- The match that is to be checked.monitor- The monitor to report progress or to check for cancellation.
-
isRoot
Checks whether the given EObject is a root of its resource or not.- Parameters:
eObj- The EObject to check.- Returns:
trueif this object is a root of its containing resource,falseotherwise.
-
computeContainmentDifferences
protected void computeContainmentDifferences(Match match, EReference reference, boolean checkOrdering) Delegates the computation of Differences for a given containment reference according to the type of comparison (two- or three-way), and whether we need to take ordering changes into account.- Parameters:
match- The match which sides we need to check for potential differences.reference- The reference whose values are currently being checked for differences.checkOrdering- Whether we need to detect ordering changes or ignore them.
-
computeMultiValuedFeatureDifferences
protected void computeMultiValuedFeatureDifferences(Match match, EStructuralFeature feature, boolean checkOrdering) Delegates the computation of Differences for a given muti-valued feature according to the type of comparison (two- or three-way), and whether we need to take ordering changes into account.- Parameters:
match- The match which sides we need to check for potential differences.feature- The feature whose values are currently being checked for differences.checkOrdering- Whether we need to detect ordering changes or ignore them.
-
computeContainmentDifferencesThreeWay
protected void computeContainmentDifferencesThreeWay(Match match, EReference reference, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given containmentreference.This is only meant for three-way comparisons.
Note that this is no longer used for references which ordering is not considered, so
checkOrderingwill always betrue.- Parameters:
match- The match which sides we need to check for potential differences.reference- The containment reference which values are to be checked.checkOrdering-trueif we should consider ordering changes on this reference,falseotherwise.
-
createContainmentDifferencesNoOrdering
protected void createContainmentDifferencesNoOrdering(Match match, EReference reference, List<Object> sideValues, DifferenceSource side) This will iterate over the given list of values from a containment reference and create the differences that can be detected from it.Ordering changes will not be considered at all from this method. Values that exist in both the given list of elements and the origin (either ancestor or right side for two-way comparisons), will only have a Diff if their container or containing reference has changed. If they are still in the same container and reference, then even if they are not in the same position, we will not try and detect an ordering change.
- Parameters:
match- The match which sides we need to check for potential differences.reference- The containment reference which values are to be checked.sideValues- Value of thatreferenceon the givenside.side- The side currently being compared.
-
createContainmentDifferences
protected void createContainmentDifferences(Match match, EReference reference, boolean checkOrdering, List<Object> values, List<Object> lcsWithOrigin, DifferenceSource side) Called fromcomputeContainmentDifferencesThreeWay(Match, EReference, boolean)once our LCS have been computed and we know what really changed. It will be used for both the left and right side.- Parameters:
match- The match which sides we need to check for potential differences.reference- The containment reference which values are to be checked.checkOrdering-trueif we should consider ordering changes on this reference,falseotherwise.values- Value of thatreferenceon the givenside.lcsWithOrigin- LCS between the reference values on the givensideand the values in origin.side- The side currently being compared.
-
matchingContainment
Checks whether the two given EObjects are contained within the same object, under the same reference.- Parameters:
equalityHelper- Our current equality helper.o1- First of the two EObjects to compare.o2- Second of the two EObjects to compare.- Returns:
trueif these two objects are contained within the same container, false otherwise.
-
getMatchIfPresent
protected static com.google.common.base.Optional<Match> getMatchIfPresent(Comparison comparison, List<Object> list, int index) This will be used in order to read the LCS synchronously with the iteration on its target lists' values. This should be used cautiously since it will work on empty lists, null values and out-of-scope objects.- Parameters:
comparison- The current comparison.list- A list of EObjects. May be empty or contain out-of-scope values.index- Index of the object we seek within this list.- Returns:
- An optional containing the match of the object at the given index... or
Optional.absent().
-
getIfPresent
This will be used in order to read the LCS synchronously with the iteration on its target lists' values. This should be used cautiously since it will work on empty lists, and null values contained in the list are treated the same as an empty list and considered to be Optional.absent().- Parameters:
list- A list of EObjects. May be empty or contain null or out-of-scope values.index- Index of the object we seek within this list.- Returns:
- An optional containing the object at the given index... or
Optional.absent().
-
computeContainmentDifferencesTwoWay
protected void computeContainmentDifferencesTwoWay(Match match, EReference reference, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given containmentreference.This is only meant for two-way comparisons.
Note that this is no longer used for references which ordering is not considered, so
checkOrderingwill always betrue.- Parameters:
match- The match which sides we need to check for potential differences.reference- The containment reference which values are to be checked.checkOrdering-trueif we should consider ordering changes on this reference,falseotherwise.
-
computeDifferences
Computes the difference between the sides of the givenmatchfor the givenattribute.- Parameters:
match- The match which sides we need to check for potential differences.attribute- The attribute which values are to be checked.checkOrdering-trueif we should consider ordering changes on this attribute,falseotherwise.
-
computeDifferences
Computes the difference between the sides of the givenmatchfor the givenreference.- Parameters:
match- The match which sides we need to check for potential differences.reference- The reference which values are to be checked.checkOrdering-trueif we should consider ordering changes on this reference,falseotherwise.
-
computeMultiValuedFeatureDifferencesThreeWay
protected void computeMultiValuedFeatureDifferencesThreeWay(Match match, EStructuralFeature feature, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given multi-valuedfeature.The given
featurecannot be a containment reference.This is only meant for three-way comparisons.
Note that this is no longer used for features which ordering is not considered, so
checkOrderingwill always betrue.- Parameters:
match- The match which sides we need to check for potential differences.feature- The feature which values are to be checked.checkOrdering-trueif we should consider ordering changes on this feature,falseotherwise.
-
createMultiValuedFeatureDifferencesNoOrdering
protected void createMultiValuedFeatureDifferencesNoOrdering(Match match, EStructuralFeature feature, List<Object> sideValues, List<Object> originValues, DifferenceSource side) This will iterate over the given list of values from a multi-valued feature and create the differences that can be detected from it.Ordering changes will not be considered at all from this method. Values that exist in both the given list of elements and the origin (either ancestor or right side for two-way comparisons), will never have a Diff even if they are not at the same index in the list of their respective side.
- Parameters:
match- The match which sides we need to check for potential differences.feature- The feature which values are to be checked. Cannot be a containment reference.sideValues- Value of thatreferenceon the givenside.originValues- Value of thatreferenceon the origin side. Could be the common ancestor or the right side in case of two-way comparisons.side- The side currently being compared.
-
computeMultiValuedFeatureDifferencesTwoWay
protected void computeMultiValuedFeatureDifferencesTwoWay(Match match, EStructuralFeature feature, boolean checkOrdering) Computes the difference between the sides of the givenmatchfor the given multi-valuedfeature.The given
featurecannot be a containment reference.This is only meant for two-way comparisons.
Note that this is no longer used for features which ordering is not considered, so
checkOrderingwill always betrue.- Parameters:
match- The match which sides we need to check for potential differences.feature- The feature which values are to be checked.checkOrdering-trueif we should consider ordering changes on this feature,falseotherwise.
-
computeSingleValuedAttributeDifferences
Computes the difference between the sides of the givenmatchfor the given single-valuedattribute.- Parameters:
match- The match which sides we need to check for potential differences.attribute- The attribute which values are to be checked.
-
computeSingleValuedReferenceDifferencesThreeWay
Computes the difference between the sides of the givenmatchfor the given single-valuedreference.The given
referencecannot be a containment reference.This is only meant for three-way comparisons.
- Parameters:
match- The match which sides we need to check for potential differences.reference- The reference which values are to be checked.
-
computeSingleValuedReferenceDifferencesTwoWay
Computes the difference between the sides of the givenmatchfor the given single-valuedreference.The given
referencecannot be a containment reference.This is only meant for two-way comparisons.
- Parameters:
match- The match which sides we need to check for potential differences.reference- The reference which values are to be checked.
-
createFeatureFilter
This will be used in order to create theFeatureFilterthat should be used by this engine to determine the structural features on which it is to try and detect differences.- Returns:
- The newly created feature filter.
-
featureChange
protected void featureChange(Match match, EStructuralFeature feature, Object value, DifferenceKind kind, DifferenceSource source) Delegates to the diff processor to create the specified feature change.- Parameters:
match- The match on which values we detected a diff.feature- The exact feature on which a diff was detected.value- The value for which we detected a changed.kind- The kind of difference to create.source- The source from which originates that diff.
-
getDiffProcessor
This will return the diff processor that has been created through#createDiffProcessor()for this differencing process.- Returns:
- The diff processor to notify of difference detections.
-