java-diff-utils

简介: java-diff-utils

谁终将声震人间,必长久深自缄默;谁终将点燃闪电,必长久如云漂泊。——尼采

https://github.com/java-diff-utils/java-diff-utils

Diff Utils库是一个开源库,用于在文本或某种数据之间执行比较/差异操作:计算差异,应用补丁,生成统一差异或解析它们,生成差异输出以便将来显示(如并排视图)等。

例如:

//create a configured DiffRowGenerator
DiffRowGenerator generator = 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.

还可以使用并排视图:

DiffRowGenerator generator = 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."));
System.out.println("|original|new|");
System.out.println("|--------|---|");
for (DiffRow row : rows) {
    System.out.println("|" + row.getOldLine() + "|" + row.getNewLine() + "|");
}
original new
This is a test senctence. This is a test for diffutils.
This is the second line. This is the second line.
~And here is the finish.~

引入:

相关文章
|
7月前
|
Java
【java】修复:java: Error during the transformation of 'com.aicloud.data.util.ExcelUtils'; post-co...
【java】修复:java: Error during the transformation of 'com.aicloud.data.util.ExcelUtils'; post-co...
297 0
|
7月前
|
Java
java base64转doc文件
以下是使用Java进行Base64转换的例子: 1. 使用Java Base64工具类进行转换 ```java // 导入相关包 import java.util.Base64; import java.io.FileOutputStream; import java.io.IOException; // 将Base64字符串转换为字节数组 byte[] decodedBytes = Base64.getDecoder().decode(base64String); // 将字节数组写入到文件中 try (FileOutputStream fos = new FileOutputStrea
192 0
|
Java
什么是package-info.java
什么是package-info.java
424 0
com.google.common.base.Preconditions.checkNotNull(Preconditions.java:877)
com.google.common.base.Preconditions.checkNotNull(Preconditions.java:877)
93 0
Test.java 文件代码
Test.java 文件代码
110 0
|
IDE Java Maven
package-info.java
package-info.java 文件估计大家见过但是自己却很少去创建和使用它、因为对于一般应用来说可能真的太少见了。
408 0
|
算法 Java 调度
Java Runtime Data Area | Java Debug 笔记
Java Runtime Data Area | Java Debug 笔记
|
XML 安全 Java
使用Kotlin 1.1.5 的REPL 来简单分析一下Java 9 中的$ jmod list java.base.jmod
$ jmod list java.base.jmod 命令行列出了 模块 java.base.jmod 中所有文件(.class文件, .dat, .jar, .
1284 0