本文整理汇总了Java中com.sksamuel.diffpatch.DiffMatchPatch类的典型用法代码示例。如果您正苦于以下问题:Java DiffMatchPatch类的具体用法?Java DiffMatchPatch怎么用?Java DiffMatchPatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiffMatchPatch类属于com.sksamuel.diffpatch包,在下文中一共展示了DiffMatchPatch类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseMsfManifest
import com.sksamuel.diffpatch.DiffMatchPatch; //导入依赖的package包/类
private static void parseMsfManifest(String manifestUrl) throws IOException, JSONException {
JSONObject manifest, files;
manifest = new JSONObject(new String(RemoteReader.fetch(manifestUrl)));
files = manifest.getJSONObject("files");
mMsfInfo.url = manifest.getString("url");
mMsfInfo.patches = new HashMap<String, LinkedList<DiffMatchPatch.Patch>>();
Iterator it = files.keys();
DiffMatchPatch dmp = new DiffMatchPatch();
while(it.hasNext()) {
String key = (String) it.next();
mMsfInfo.patches.put(key, (LinkedList<DiffMatchPatch.Patch>) dmp.patch_fromText(files.getString(key)));
}
}
开发者ID:Android-leak,项目名称:csploit,代码行数:18,代码来源:UpdateService.java
示例2: 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;
}
开发者ID:fhoeben,项目名称:hsac-fitnesse-fixtures,代码行数:21,代码来源:CompareFixture.java
示例3: 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;
}
开发者ID:fhoeben,项目名称:hsac-fitnesse-fixtures,代码行数:26,代码来源:CompareFixture.java
示例4: handle
import com.sksamuel.diffpatch.DiffMatchPatch; //导入依赖的package包/类
@Override
public List<ProcessTask> handle(EntityManager manager) {
if (!manager.getTransaction().isActive()) {
manager.getTransaction().begin();
}
Patch patch = (Patch) manager.find(Patch.class, id);
if (FileExtensions.isPatchable(patch.getFile().getRelativePath())) {
DiffMatchPatch dmp = new DiffMatchPatch();
String result = patch.getDiff();
String original = patch.getFile().getContent();
patch.setDiff(dmp.patch_toText(dmp.patch_make(original, result)));
}
manager.getTransaction().commit();
return new ArrayList<>();
}
开发者ID:Idrinths-Stellaris-Mods,项目名称:Mod-Tools,代码行数:16,代码来源:GenerateFilePatch.java
示例5: 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;
}
开发者ID:RobWin,项目名称:assertj-diff,代码行数:18,代码来源:DiffAssert.java
示例6: 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;
}
开发者ID:RobWin,项目名称:assertj-diff,代码行数:9,代码来源:DiffAssert.java
示例7: 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);
}
}
开发者ID:RobWin,项目名称:assertj-diff,代码行数:9,代码来源:DiffAssert.java
示例8: 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);
}
}
开发者ID:RobWin,项目名称:assertj-diff,代码行数:12,代码来源:DiffAssert.java
示例9: compareFuzzy
import com.sksamuel.diffpatch.DiffMatchPatch; //导入依赖的package包/类
public static int compareFuzzy(String one, String another) {
DiffMatchPatch matcher = new DiffMatchPatch();
LinkedList<Diff> diffs = matcher.diff_main(one, another);
return matcher.diff_levenshtein(diffs);
}
开发者ID:BlackCraze,项目名称:GameResourceBot,代码行数:6,代码来源:Resource.java
示例10: 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);
}
}
开发者ID:Armatiek,项目名称:xslweb,代码行数:44,代码来源:DiffText.java
示例11: 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;
}
开发者ID:fhoeben,项目名称:hsac-fitnesse-fixtures,代码行数:6,代码来源:CompareFixture.java
注:本文中的com.sksamuel.diffpatch.DiffMatchPatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论