Class ThreeWayTextDiff

java.lang.Object
org.eclipse.emf.compare.internal.ThreeWayTextDiff

public class ThreeWayTextDiff extends Object
Three-way differencing utility for plain text.

Taking three versions of a plain text as input (the origin, left, and right version), a three-way diff provides the information on whether the left and right version underwent conflicting changes and, if not, enables to compute a new merged version of the text so that all changes of the left and right version are combined.

The differencing, conflict detection, and merging is line-based; that is, a conflict-free merge can only be performed if each single line is changed only on one side (left or right), each changed line on one side has not been deleted on the other side, and a total order of lines can be found (e.g., no additions of new lines at the same line). Otherwise, the modifications of the left version and the right version are in conflict.

  • Constructor Details

    • ThreeWayTextDiff

      public ThreeWayTextDiff(String origin, String left, String right)
      Constructs a ThreeWayTextDiff for the given origin version of a plain text and the two potentially modified versions of it, left and right.
      Parameters:
      origin - The common ancestor version of the plain text.
      left - The potentially modified left-hand side version of the common ancestor.
      right - The potentially modified right-hand side version of the common ancestor.
  • Method Details

    • isConflicting

      public boolean isConflicting()
      Specifies whether the modification on the left-hand side and the modifications on the right-hand side are conflicting.

      A conflict occurs if a line is changed on both sides (left and right), a line is changed on one side and is deleted on the other side, or no total order of lines can be found (e.g., two additions of new lines at the same original line).

      Returns:
      true if left and right is in conflict; false otherwise.
    • getMerged

      public String getMerged()
      Returns the merge result of the modifications applied at the left-hand side and the right-hand side.

      If the left-hand side modifications and the right-hand side modifications are not conflicting, the merge operation is symmetric; that is, the merge result will always yield the same result, also when switching the left-hand side and the right-hand side. If the left-hand and right-hand side modifications are conflicting, this method will still return a merged version. However, in this case, the merge operation might be not be symmetric; that is, switching left and right might yield different merge results.

      Returns:
      The result of merging the left-hand side and right-hand side differences.