org.eclipse.emf.compare.conflict

## Class DefaultConflictDetector

- java.lang.Object
- - org.eclipse.emf.compare.conflict.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 Summary

Constructors
Constructor and Description
`DefaultConflictDetector()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `checkConflict(Comparison comparison, Diff diff, Iterable<Diff> candidates)` This will be called once for each difference in the comparison model.
`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.
`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.
`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.
`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.
`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.
`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".
`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.
`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".
`protected void` `checkResourceAttachmentConflict(Comparison comparison, ResourceAttachmentChange diff, Iterable<Diff> candidates)` This will be called once for each ResourceAttachmentChange in the comparison model.
`protected void` `checkResourceAttachmentConflict(Comparison comparison, ResourceAttachmentChange diff, ReferenceChange candidate)` This will be called from `checkResourceAttachmentConflict(Comparison, ResourceAttachmentChange, Iterable)` for each ReferenceChange in the comparison model that is on the other side and that impacts the changed root.
`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.
`void` `detect(Comparison comparison, Monitor monitor)` This is the entry point of the conflict detection process.
`protected MatchResource` `getMatchResource(Comparison comparison, Resource resource)` Returns the MatchResource corresponding to the given `resource`.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DefaultConflictDetector

    public DefaultConflictDetector()

### Method Detail

#### detect

    public void detect(Comparison comparison,
                       Monitor monitor)

This is the entry point of the conflict detection process.

It is expected to complete the input `comparison` by iterating over the `differences` it contain, filling in all conflicts it can detect between those Diffs.

Specified by:
  `detect` in interface `IConflictDetector`
Parameters:
  `comparison` - The comparison this engine is expected to complete.
  `monitor` - The monitor to report progress or to check for cancellation
See Also:
  `IConflictDetector.detect(org.eclipse.emf.compare.Comparison, org.eclipse.emf.common.util.Monitor)`

#### 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`.

#### checkResourceAttachmentConflict

    protected void checkResourceAttachmentConflict(Comparison comparison,
                                                   ResourceAttachmentChange diff,
                                                   ReferenceChange candidate)

This will be called from `checkResourceAttachmentConflict(Comparison, ResourceAttachmentChange, Iterable)` for each ReferenceChange in the comparison model that is on the other side and that impacts the changed root.

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

#### 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.