Class ComparisonUtil
- java.lang.Object
-
- org.eclipse.emf.compare.internal.utils.ComparisonUtil
-
public final class ComparisonUtil extends Object
This utility class provides common methods for navigation over and querying of the Comparison model.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanbothArePlatformResourcesAndOnlyOneExists(Resource leftResource, Resource rightResource)Checks if both resources are platform resources and only one exists.static booleanbothResourceHaveResourceSet(Resource leftResource, Resource rightResource)Checks if both resources have resource set.static voiddelete(Diff diff)Deletesthe givendiff.static ComparisongetComparison(Diff diff)Returns the comparison associated with the given diff.static ComparisongetComparison(EObject object)Returns the comparison associated with the given object.static com.google.common.base.Function<Diff,Iterable<Diff>>getDirectSubDiffs(boolean leftToRight)When merging aDiff, returns the first level of sub diffs of this given diff, and all associated diffs (seeDiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.static EObjectgetExpectedSide(Match match, DifferenceSource source, boolean mergeRightToLeft)Determines the side of the givenMatchwhich represents the model state the other side will be changed to.static com.google.common.base.Function<Diff,Iterable<Diff>>getSubDiffs(boolean leftToRight)When merging aDiff, returns the sub diffs of this given diff, and all associated diffs (seeDiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.static booleanisAddOrSetDiff(Diff difference)Checks if the given difference is either an addition or a "set" from the default value to a new reference.static booleanisContainedInFeatureMap(EObject object)Determines if the givenEObjectis contained directly within a FeatureMap by checking theEAnnotations.static booleanisDeleteOrUnsetDiff(Diff difference)Checks if the given difference is either a deletion or a "unset" to the default value.static booleanisFeatureMapContainment(Diff diff)Checks whether the given diff corresponds to a feature map containment change.static EObjectmoveElementGetExpectedContainer(Comparison comparison, FeatureMapChange diff, boolean rightToLeft)Get the expected target container in case of a move.
-
-
-
Method Detail
-
getSubDiffs
public static com.google.common.base.Function<Diff,Iterable<Diff>> getSubDiffs(boolean leftToRight)
When merging aDiff, returns the sub diffs of this given diff, and all associated diffs (seeDiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.If the diff is an
AttributeChange, aFeatureMapChangeor aResourceAttachmentChange, this method will return an empty iterable.If the diff is a
ReferenceChangethis method will return all differences contained in the match that contains the value of the reference change, and all associated diffs of these differences.- Parameters:
leftToRight- the direction of merge.- Returns:
- an iterable containing the sub diffs of this given diff, and all associated diffs of these sub diffs.
- Since:
- 3.0
-
getDirectSubDiffs
public static com.google.common.base.Function<Diff,Iterable<Diff>> getDirectSubDiffs(boolean leftToRight)
When merging aDiff, returns the first level of sub diffs of this given diff, and all associated diffs (seeDiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.If the diff is an
AttributeChange, aFeatureMapChangeor aResourceAttachmentChange, this method will return an empty iterable.If the diff is a
ReferenceChangethis method will return the first level differences contained in the match that contains the value of the reference change, and all associated diffs of these differences.- Parameters:
leftToRight- the direction of merge.- Returns:
- an iterable containing the first level of sub diffs of this given diff, and all associated diffs of these sub diffs.
- Since:
- 3.3
-
isAddOrSetDiff
public static boolean isAddOrSetDiff(Diff difference)
Checks if the given difference is either an addition or a "set" from the default value to a new reference.- Parameters:
difference- The given difference.- Returns:
trueif this is an addition or "set" diff.
-
isDeleteOrUnsetDiff
public static boolean isDeleteOrUnsetDiff(Diff difference)
Checks if the given difference is either a deletion or a "unset" to the default value.- Parameters:
difference- The given difference.- Returns:
trueif this is a deletion or "unset" diff.
-
isFeatureMapContainment
public static boolean isFeatureMapContainment(Diff diff)
Checks whether the given diff corresponds to a feature map containment change. This holds true for differences on feature map containment references' values.- Parameters:
diff- The diff to consider.- Returns:
trueif the givendiffis to be considered a containment change,falseotherwise.
-
moveElementGetExpectedContainer
public static EObject moveElementGetExpectedContainer(Comparison comparison, FeatureMapChange diff, boolean rightToLeft)
Get the expected target container in case of a move.- Parameters:
comparison- The comparison object.diff- The diff we are currently merging.rightToLeft- Whether we should move the value in the left or right side.- Returns:
- The expected target container if found,
nullotherwise.
-
getComparison
public static Comparison getComparison(EObject object)
Returns the comparison associated with the given object. The given object is expected to be an instance of one of the Class from the ComparePackage model.- Parameters:
object- the object from which the comparison should be retrieved.- Returns:
- the comparison.
-
getComparison
public static Comparison getComparison(Diff diff)
Returns the comparison associated with the given diff.- Parameters:
diff- The diff, which must either have a match or a MatchResource container, otherwise a NPE will be thrown.- Returns:
- The comparison that contains the given diff, or
nullif there's none.
-
getExpectedSide
public static EObject getExpectedSide(Match match, DifferenceSource source, boolean mergeRightToLeft)
Determines the side of the givenMatchwhich represents the model state the other side will be changed to.- Parameters:
match- The match whose side is returned.source- The source from which side the differences are determined.mergeRightToLeft- The direction of the merge.- Returns:
- The side of the given
matchwhich represents the desired model state in regards to the givenDifferenceSourceandMergeDirection.
-
isContainedInFeatureMap
public static boolean isContainedInFeatureMap(EObject object)
Determines if the givenEObjectis contained directly within a FeatureMap by checking theEAnnotations.- Parameters:
object- The object to check.- Returns:
- if the
objectis directly contained within a FeatureMap.
-
bothArePlatformResourcesAndOnlyOneExists
public static boolean bothArePlatformResourcesAndOnlyOneExists(Resource leftResource, Resource rightResource)
Checks if both resources are platform resources and only one exists.- Parameters:
leftResource- the first resource to check.rightResource- the second resource to check.- Returns:
- true if both resources are platform resources and only one exists, false otherwise.
-
bothResourceHaveResourceSet
public static boolean bothResourceHaveResourceSet(Resource leftResource, Resource rightResource)
Checks if both resources have resource set.- Parameters:
leftResource- the first resource to check.rightResource- the second resource to check.- Returns:
- true if both resources have resource set, false otherwise.
-
delete
public static void delete(Diff diff)
Deletesthe givendiff.Conflicts and equivalences of the
diffwill also be removed if they get meaningless after thediffhas been deleted. A conflict is meaningless, if it has diffs only on one side after the deletion. An equivalence is meaningless, if it has only one diff left.- Parameters:
diff- The diff to delete.
-
-