public class ThreeWayTextDiff extends Object
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 and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
String |
getMerged()
Returns the merge result of the modifications applied at the left-hand side and the right-hand side.
|
boolean |
isConflicting()
Specifies whether the modification on the left-hand side and the modifications on the right-hand side
are conflicting.
|
public ThreeWayTextDiff(String origin, String left, String right)
ThreeWayTextDiff
for the given origin
version of a plain text and the two
potentially modified versions of it, left
and right
.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.public boolean isConflicting()
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).
true
if left and right is in conflict; false
otherwise.public String getMerged()
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.
Copyright (c) 2006, 2014 Obeo and others. All rights reserved.