mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
This commit is contained in:
@@ -33,15 +33,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A clean-room implementation of <a href="http://www.cs.arizona.edu/people/gene/">
|
||||
* Eugene Myers</a> differencing algorithm.
|
||||
*
|
||||
* <p>
|
||||
* See the paper at <a href="http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps">
|
||||
* http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps</a></p>
|
||||
*
|
||||
* @author <a href="mailto:juanco@suigeneris.org">Juanco Anez</a>
|
||||
* @param T The type of the compared elements in the 'lines'.
|
||||
* A clean-room implementation of Eugene Myers greedy differencing algorithm.
|
||||
*/
|
||||
public final class MyersDiff<T> implements DiffAlgorithm<T> {
|
||||
|
||||
@@ -116,8 +108,8 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
|
||||
final int kplus = kmiddle + 1;
|
||||
final int kminus = kmiddle - 1;
|
||||
PathNode prev = null;
|
||||
|
||||
int i;
|
||||
|
||||
if ((k == -d) || (k != d && diagonal[kminus].i < diagonal[kplus].i)) {
|
||||
i = diagonal[kplus].i;
|
||||
prev = diagonal[kplus];
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
||||
<!--
|
||||
#%L
|
||||
java-diff-utils
|
||||
%%
|
||||
Copyright (C) 2009 - 2017 java-diff-utils
|
||||
%%
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
#L%
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta name="generator" content=
|
||||
"HTML Tidy for Cygwin (vers 1st February 2003), see www.w3.org">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
The {@link difflib.myers diff.myers} package
|
||||
implements <a href=
|
||||
"http://www.cs.arizona.edu/people/gene/">Gene Myers</a>'
|
||||
differencing algorithm.
|
||||
</p>
|
||||
<p>
|
||||
Myer's algorithm produces optimum results (minimum diffs), but
|
||||
consumes considerably more memory than SimpleDiff, so its not
|
||||
suitable for very large files.
|
||||
</p>
|
||||
@author <a href="mailto:juanco@suigeneris.org">Juanco Anez</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -172,6 +172,10 @@ public class DiffRowGenerator {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static final Equalizer<String> IGNORE_WHITESPACE_EQUALIZER = (original, revised)
|
||||
-> original.trim().replaceAll("\\s+", " ").equals(revised.trim().replaceAll("\\s+", " "));
|
||||
public static final Equalizer<String> DEFAULT_EQUALIZER = Object::equals;
|
||||
|
||||
private DiffRowGenerator(Builder builder) {
|
||||
showInlineDiffs = builder.showInlineDiffs;
|
||||
ignoreWhiteSpaces = builder.ignoreWhiteSpaces;
|
||||
@@ -180,16 +184,7 @@ public class DiffRowGenerator {
|
||||
columnWidth = builder.columnWidth;
|
||||
mergeOriginalRevised = builder.mergeOriginalRevised;
|
||||
inlineDiffByWord = builder.inlineDiffByWord;
|
||||
equalizer = new Equalizer<String>() {
|
||||
@Override
|
||||
public boolean equals(String original, String revised) {
|
||||
if (ignoreWhiteSpaces) {
|
||||
return original.trim().replaceAll("\\s+", " ").equals(revised.trim().replaceAll("\\s+", " "));
|
||||
} else {
|
||||
return original.equals(revised);
|
||||
}
|
||||
}
|
||||
};
|
||||
equalizer = ignoreWhiteSpaces?IGNORE_WHITESPACE_EQUALIZER:DEFAULT_EQUALIZER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user