Class DefaultConflictDetector

  • All Implemented Interfaces:
    IConflictDetector

    public class DefaultConflictDetector
    extends Object
    implements IConflictDetector
    The conflict detector is in charge of refining the Comparison model with all detected Conflict between its differences.

    This default implementation of IConflictDetector should detect most generic cases, but is not aimed at detecting conflicts at "business" level. For example, adding two enum literals of the same value but distinct IDs might be seen as a conflict... but that is not the "generic" case.

    • Constructor Detail

      • DefaultConflictDetector

        public DefaultConflictDetector()
    • Method Detail

      • checkConflict

        protected void checkConflict​(Comparison comparison,
                                     Diff diff,
                                     Iterable<Diff> candidates)
        This will be called once for each difference in the comparison model.
        Parameters:
        comparison - The originating comparison of those diffs.
        diff - Diff for which we are to try and determine conflicts.
        candidates - An iterable over the Diffs that possible candidates for conflicts.
      • checkContainmentConflict

        protected void checkContainmentConflict​(Comparison comparison,
                                                ReferenceChange diff,
                                                Iterable<ReferenceChange> candidates)
        This will be called once for each ReferenceChange on containment references in the comparison model.
        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The reference change for which we are to try and determine conflicts.
        candidates - An iterable over the ReferenceChanges that are possible candidates for conflicts.
      • checkContainmentConflict

        protected void checkContainmentConflict​(Comparison comparison,
                                                ReferenceChange diff,
                                                ReferenceChange candidate)
        For each couple of diffs on the same value in which one is a containment reference change, we will call this in order to check for possible conflicts.

        Once here, we know that diff is a containment reference change, and we known that diff and candidate are both pointing to the same value. candidate can be a containment reference change, but that is not a given.

        Parameters:
        comparison - The originating comparison of those diffs.
        diff - Containment reference changes for which we need to check possible conflicts.
        candidate - A reference change that point to the same value as diff.
      • checkContainmentFeatureMapConflict

        protected void checkContainmentFeatureMapConflict​(Comparison comparison,
                                                          FeatureMapChange diff,
                                                          Iterable<FeatureMapChange> candidates)
        This will be called once for each FeatureMapChange on containment values in the comparison model.
        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The feature map change for which we are to try and determine conflicts.
        candidates - An iterable over the FeatureMapChanges that are possible candidates for conflicts.
        Since:
        3.2
      • checkContainmentFeatureMapConflict

        protected void checkContainmentFeatureMapConflict​(Comparison comparison,
                                                          FeatureMapChange diff,
                                                          FeatureMapChange candidate)
        For each couple of diffs on the same value in which one is a containment feature map change, we will call this in order to check for possible conflicts.

        Once here, we know that diff is a containment feature map change, and we known that diff and candidate are both pointing to the same value. candidate can be a containment feature map change, but that is not a given.

        Parameters:
        comparison - The originating comparison of those diffs.
        diff - Containment feature map changes for which we need to check possible conflicts.
        candidate - A feature map change that point to the same value as diff.
        Since:
        3.2
      • checkFeatureChangeConflict

        protected void checkFeatureChangeConflict​(Comparison comparison,
                                                  Diff diff,
                                                  Iterable<Diff> candidates)
        This will be called from checkConflict(Comparison, Diff, Iterable) in order to detect conflicts on a Diff that is of type "CHANGE".

        Those can only conflict with other CHANGE Diffs on the same reference.

        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The diff which we are to check for conflicts.
        candidates - The list of candidates for a conflict. This list only contains Diff from the side opposite to diff.
      • isMergeableText

        protected boolean isMergeableText​(String left,
                                          String right,
                                          String origin)
        Specifies whether the given three versions of a text left, right, and origin are mergeable with a line-based three-way merge.
        Parameters:
        left - The left version.
        right - The right version.
        origin - The original version.
        Returns:
        true if they are mergeable, false otherwise.
        Since:
        3.2
      • checkFeatureMoveConflict

        protected void checkFeatureMoveConflict​(Comparison comparison,
                                                Diff diff,
                                                Iterable<Diff> candidates)
        This will be called from checkConflict(Comparison, Diff, Iterable) in order to detect conflicts on a Diff that is of type "CHANGE" or "MOVE".

        Those can only conflict with other Diffs of the same type on the same reference.

        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The diff which we are to check for conflicts.
        candidates - The list of candidates for a conflict. This list only contains Diff from the side opposite to diff.
      • checkFeatureDeleteConflict

        protected void checkFeatureDeleteConflict​(Comparison comparison,
                                                  Diff diff,
                                                  Iterable<Diff> candidates)
        This will be called from checkConflict(Comparison, Diff, Iterable) in order to detect conflicts on a Diff that is of type "DELETE" and which is not a containment reference change.

        The only potential conflict for such a diff is a "MOVE" of that same value on the opposite side.

        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The diff which we are to check for conflicts.
        candidates - The list of candidates for a conflict. This list only contains Diff from the side opposite to diff.
      • checkFeatureAddConflict

        protected void checkFeatureAddConflict​(Comparison comparison,
                                               Diff diff,
                                               Iterable<Diff> candidates)
        This will be called from checkConflict(Comparison, Diff, Iterable) in order to detect conflicts on a Diff that is of type "ADD" and which is not a containment reference change.

        These will conflict with Diffs on the other side on the same reference in the same container, of type ADD an on the same value.

        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The diff which we are to check for conflicts.
        candidates - The list of candidates for a conflict. This list only contains Diff from the side opposite to diff.
      • checkResourceAttachmentConflict

        protected void checkResourceAttachmentConflict​(Comparison comparison,
                                                       ResourceAttachmentChange diff,
                                                       Iterable<Diff> candidates)
        This will be called once for each ResourceAttachmentChange in the comparison model.
        Parameters:
        comparison - The originating comparison of those diffs.
        diff - The "root" difference for which we are to try and determine conflicts.
        candidates - An iterable over the Diffs that are possible candidates for conflicts.
      • getMatchResource

        protected MatchResource getMatchResource​(Comparison comparison,
                                                 Resource resource)
        Returns the MatchResource corresponding to the given resource.
        Parameters:
        comparison - the comparison to search for a MatchResource.
        resource - Resource for which we need a MatchResource.
        Returns:
        The MatchResource corresponding to the given resource.
      • conflictOn

        protected void conflictOn​(Comparison comparison,
                                  Diff diff1,
                                  Diff diff2,
                                  ConflictKind kind)
        This will be called whenever we detect a new conflict in order to create (or update) the actual association.
        Parameters:
        comparison - The originating comparison of those diffs.
        diff1 - First of the two differences for which we detected a conflict.
        diff2 - Second of the two differences for which we detected a conflict.
        kind - Kind of this conflict.