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 of a plain text and the two
potentially modified versions of it, left and right . |
Modifier and Type | Method and Description |
---|---|
String |
getLeft()
Returns the potentially modified left-hand side version of the origin.
|
String |
getMerged()
Performs and returns a merge of the modifications of the left-hand side and the right-hand side.
|
String |
getOrigin()
Returns the original version.
|
String |
getRight()
Returns the potentially modified right-hand side version of the origin.
|
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
of a plain text and the two
potentially modified versions of it, left
and right
.origin
- The original version of the plain text.left
- The potentially modified left version of the origin.right
- The potentially modified right version of the origin.public String getOrigin()
public String getLeft()
public String getRight()
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).
When considering each change as a deletion and addition of a line, the conflict detection boils down to finding additions on both sides that are inserted before or after the same line.
true
if left and right is in conflict; false
otherwise.public String getMerged()
If the left-hand side diff and the right-hand side diff is 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 diffs are conflicting, this method will still return a merged version, taking the left-hand side and applying the patches of the right-hand side. 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.