Class ComparisonUtil

java.lang.Object
org.eclipse.emf.compare.internal.utils.ComparisonUtil

public final class ComparisonUtil
extends java.lang.Object
This utility class provides common methods for navigation over and querying of the Comparison model.
  • Method Summary

    Modifier and Type Method Description
    static boolean bothArePlatformResourcesAndOnlyOneExists​(Resource leftResource, Resource rightResource)
    Checks if both resources are platform resources and only one exists.
    static boolean bothResourceHaveResourceSet​(Resource leftResource, Resource rightResource)
    Checks if both resources have resource set.
    static void delete​(Diff diff)
    Deletes the given diff.
    static Comparison getComparison​(Diff diff)
    Returns the comparison associated with the given diff.
    static Comparison getComparison​(EObject object)
    Returns the comparison associated with the given object.
    static com.google.common.base.Function<Diff,​java.lang.Iterable<Diff>> getDirectSubDiffs​(boolean leftToRight)
    When merging a Diff, returns the first level of sub diffs of this given diff, and all associated diffs (see DiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.
    static EObject getExpectedSide​(Match match, DifferenceSource source, boolean mergeRightToLeft)
    Determines the side of the given Match which represents the model state the other side will be changed to.
    static com.google.common.base.Function<Diff,​java.lang.Iterable<Diff>> getSubDiffs​(boolean leftToRight)
    When merging a Diff, returns the sub diffs of this given diff, and all associated diffs (see DiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.
    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.
    static boolean isContainedInFeatureMap​(EObject object)
    Determines if the given EObject is contained directly within a FeatureMap by checking the EAnnotations.
    static boolean isDeleteOrUnsetDiff​(Diff difference)
    Checks if the given difference is either a deletion or a "unset" to the default value.
    static boolean isFeatureMapContainment​(Diff diff)
    Checks whether the given diff corresponds to a feature map containment change.
    static EObject moveElementGetExpectedContainer​(Comparison comparison, FeatureMapChange diff, boolean rightToLeft)
    Get the expected target container in case of a move.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getSubDiffs

      public static com.google.common.base.Function<Diff,​java.lang.Iterable<Diff>> getSubDiffs​(boolean leftToRight)
      When merging a Diff, returns the sub diffs of this given diff, and all associated diffs (see DiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.

      If the diff is an AttributeChange, a FeatureMapChange or a ResourceAttachmentChange , this method will return an empty iterable.

      If the diff is a ReferenceChange this 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,​java.lang.Iterable<Diff>> getDirectSubDiffs​(boolean leftToRight)
      When merging a Diff, returns the first level of sub diffs of this given diff, and all associated diffs (see DiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)) of these sub diffs.

      If the diff is an AttributeChange, a FeatureMapChange or a ResourceAttachmentChange , this method will return an empty iterable.

      If the diff is a ReferenceChange this 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:
      true if 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:
      true if 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:
      true if the given diff is to be considered a containment change, false otherwise.
    • 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, null otherwise.
    • 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 null if there's none.
    • getExpectedSide

      public static EObject getExpectedSide​(Match match, DifferenceSource source, boolean mergeRightToLeft)
      Determines the side of the given Match which 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 match which represents the desired model state in regards to the given DifferenceSource and MergeDirection.
    • isContainedInFeatureMap

      public static boolean isContainedInFeatureMap​(EObject object)
      Determines if the given EObject is contained directly within a FeatureMap by checking the EAnnotations.
      Parameters:
      object - The object to check.
      Returns:
      if the object is 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)
      Deletes the given diff.

      Conflicts and equivalences of the diff will also be removed if they get meaningless after the diff has 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.