DiffUtils#diff(List<String>,List<String) output does not provide too much information
saiema opened this issue · comments
Following the provided example, I would expect an output where at least three changes were detected. The obtained output is:
[ChangeDelta, position: 0, lines: [This is the first line, This would be the second line, And this is the third line] to [This would be the first line, This would be second line, And tis is the last line of the text, Another one bytes the dust]]
Is this the expected output? I was expecting something more akin to the output of the diff
command or the one obtained when using git diff
. Is there a way to get a more usable output?
Provided example:
import com.github.difflib.DiffUtils;
import com.github.difflib.patch.AbstractDelta;
import com.github.difflib.patch.Patch;
import java.util.Arrays;
import java.util.List;
public class Test {
public static void main(String[] args) {
String[] stringA = new String[] {"This is the first line", "This would be the second line","And this is the third line"};
String[] stringB = new String[] {"This would be the first line", "This would be second line", "And tis is the last line of the text", "Another one bytes the dust"};
List<String> original = Arrays.asList(stringA);
List<String> revised = Arrays.asList(stringB);
// Compute diff. Get the Patch object. Patch is the container for computed deltas.
Patch<String> patch = DiffUtils.diff(original, revised);
for (AbstractDelta<String> delta : patch.getDeltas()) {
System.out.println(delta);
}
}
}
Maybe you need to use DiffUtils.diffInline
or go to the more sophisticated DiffRowGenerator
.