本文整理汇总了Java中com.sksamuel.diffpatch.DiffMatchPatch.Diff方法的典型用法代码示例。如果您正苦于以下问题:Java DiffMatchPatch.Diff方法的具体用法?Java DiffMatchPatch.Diff怎么用?Java DiffMatchPatch.Diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sksamuel.diffpatch.DiffMatchPatch
的用法示例。
在下文中一共展示了DiffMatchPatch.Diff方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDifferencesHtml
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
protected String getDifferencesHtml(String first, String second, Formatter whitespaceFormatter) {
if (first == null) {
if (second == null) {
return null;
} else {
first = "";
}
} else if (second == null) {
second = "";
}
LinkedList<DiffMatchPatch.Diff> diffs = getDiffs(first, second);
String rootTag = first.startsWith("<pre>") && first.endsWith("</pre>")
? "pre"
: "div";
String diffPrettyHtml = diffToHtml(rootTag, diffs, whitespaceFormatter);
if (first.startsWith("<pre>") && first.endsWith("</pre>")) {
diffPrettyHtml = diffPrettyHtml.replaceFirst("^<div>", "<pre>").replaceFirst("</div>$", "</pre>");
}
return diffPrettyHtml;
}
示例2: countDifferencesBetweenAnd
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
/**
* Determines number of differences (substrings that are not equal) between two strings.
* @param first first string to compare.
* @param second second string to compare.
* @return number of different substrings.
*/
public int countDifferencesBetweenAnd(String first, String second) {
if (first == null) {
if (second == null) {
return 0;
} else {
first = "";
}
} else if (second == null) {
second = "";
}
LinkedList<DiffMatchPatch.Diff> diffs = getDiffs(first, second);
int diffCount = 0;
for (DiffMatchPatch.Diff diff : diffs) {
if (diff.operation != DiffMatchPatch.Operation.EQUAL) {
diffCount++;
}
}
return diffCount;
}
示例3: assertThatAllDiffsAreEqual
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
public boolean assertThatAllDiffsAreEqual(LinkedList<DiffMatchPatch.Diff> diffs){
for(DiffMatchPatch.Diff diff : diffs){
if(diff.operation == DiffMatchPatch.Operation.DELETE || diff.operation == DiffMatchPatch.Operation.INSERT){
return false;
}
}
return true;
}
示例4: isEqualTo
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
/**
* Verifies that the content of the actual File is equal to the given one.
*
* @param expected the given value to compare the actual value to.
* @param reportPath the path to the report which should be generated if the files differ.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}..
*/
public DiffAssert isEqualTo(Path expected, Path reportPath) {
LinkedList<DiffMatchPatch.Diff> diffs = diff(actual, expected);
boolean allDiffsAreEqual = assertThatAllDiffsAreEqual(diffs);
if(!allDiffsAreEqual){
writeHtmlReport(reportPath, diffs);
}
assertThat(allDiffsAreEqual).as("The content of the following files differ. Actual: %s, Expected %s. Check the HTML report for more details: %s", actual.toAbsolutePath(), expected.toAbsolutePath(), reportPath.toAbsolutePath()).isTrue();
return myself;
}
示例5: diff
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
private static LinkedList<DiffMatchPatch.Diff> diff(Path actual, Path expected){
DiffMatchPatch differ = new DiffMatchPatch();
try {
return differ.diff_main(IOUtils.toString(expected.toUri()), IOUtils.toString(actual.toUri()), false);
} catch (IOException e) {
throw new RuntimeException("Failed to diff files.", e);
}
}
示例6: writeHtmlReport
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
private static void writeHtmlReport(Path reportPath, LinkedList<DiffMatchPatch.Diff> diffs){
DiffMatchPatch differ = new DiffMatchPatch();
try {
Files.createDirectories(reportPath.getParent());
try (BufferedWriter writer = Files.newBufferedWriter(reportPath, Charset.forName("UTF-8"))) {
writer.write(differ.diff_prettyHtml(diffs));
}
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to write report %s", reportPath.toAbsolutePath()), e);
}
}
示例7: call
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
@Override
public ZeroOrOne<NodeInfo> call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String text1 = ((StringValue) arguments[0].head()).getStringValue();
String text2 = ((StringValue) arguments[1].head()).getStringValue();
DiffMatchPatch dmp = new DiffMatchPatch();
LinkedList<DiffMatchPatch.Diff> diffs = dmp.diff_main(text1, text2);
LinkedTreeBuilder builder = (LinkedTreeBuilder) TreeModel.LINKED_TREE.makeBuilder(context.getController().makePipelineConfiguration());
builder.setLineNumbering(false);
builder.open();
builder.startDocument(0);
builder.startElement(new NoNamespaceName("diff"), AnyType.getInstance(), ExplicitLocation.UNKNOWN_LOCATION, 0);
builder.startContent();
for (Diff diff : diffs) {
String tagName = null;
switch (diff.operation) {
case INSERT:
tagName = "ins";
break;
case DELETE:
tagName = "del";
break;
case EQUAL:
tagName = "eq";
break;
}
builder.startElement(new NoNamespaceName(tagName), AnyType.getInstance(), ExplicitLocation.UNKNOWN_LOCATION, 0);
builder.startContent();
builder.characters(diff.text, ExplicitLocation.UNKNOWN_LOCATION, 0);
builder.endElement();
}
builder.endElement();
builder.endDocument();
builder.close();
NodeInfo nodeInfo = builder.getCurrentRoot();
return new ZeroOrOne<NodeInfo>(nodeInfo);
} catch (Exception e) {
throw new XPathException("Error differencing nodes", e);
}
}
示例8: getDiffs
import com.sksamuel.diffpatch.DiffMatchPatch; //导入方法依赖的package包/类
protected LinkedList<DiffMatchPatch.Diff> getDiffs(String first, String second) {
LinkedList<DiffMatchPatch.Diff> diffs = diffMatchPatch.diff_main(cleanupValue(first), cleanupValue(second));
diffMatchPatch.diff_cleanupSemantic(diffs);
return diffs;
}