//create a configured DiffRowGenerator DiffRowGeneratorgenerator= DiffRowGenerator.create() .showInlineDiffs(true) .mergeOriginalRevised(true) .inlineDiffByWord(true) .oldTag(f -> "~") //introduce markdown style for strikethrough .newTag(f -> "**") //introduce markdown style for bold .build();
//compute the differences for two test texts. List<DiffRow> rows = generator.generateDiffRows( Arrays.asList("This is a test senctence."), Arrays.asList("This is a test for diffutils."));
System.out.println(rows.get(0).getOldLine());
会得到:This is a test senctencefor diffutils.
还可以使用并排视图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
DiffRowGeneratorgenerator= DiffRowGenerator.create() .showInlineDiffs(true) .inlineDiffByWord(true) .oldTag(f -> "~") .newTag(f -> "**") .build(); List<DiffRow> rows = generator.generateDiffRows( Arrays.asList("This is a test senctence.", "This is the second line.", "And here is the finish."), Arrays.asList("This is a test for diffutils.", "This is the second line."));