nextDelta = deltas.get(deltaIndex);
@@ -270,7 +245,6 @@ public final class UnifiedDiffUtils {
curDelta = nextDelta;
deltaIndex++;
}
-
// Now output the post-Delta context code, clamping the end of the file
contextStart = curDelta.getSource().getPosition()
+ curDelta.getSource().getLines().size();
@@ -280,7 +254,6 @@ public final class UnifiedDiffUtils {
origTotal++;
revTotal++;
}
-
// Create and insert the block header, conforming to the Unified Diff
// standard
StringBuilder header = new StringBuilder();
@@ -294,10 +267,8 @@ public final class UnifiedDiffUtils {
header.append(revTotal);
header.append(" @@");
buffer.add(0, header.toString());
-
return buffer;
}
-
/**
* getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter. Author: Bill James (tankerbay@gmail.com).
*
@@ -314,13 +285,9 @@ public final class UnifiedDiffUtils {
}
return buffer;
}
-
- private UnifiedDiffUtils() {
- }
-
/**
* Compare the differences between two files and return to the original file and diff format
- *
+ *
* (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file.
* You can see all the differences and unmodified places from the original file.
* Also, this will be very easy and useful for making side-by-side comparison display applications,
@@ -329,16 +296,13 @@ public final class UnifiedDiffUtils {
*
* @param original Original file content
* @param revised revised file content
- *
*/
public static List generateOriginalAndDiff(List original, List revised) {
return generateOriginalAndDiff(original, revised, null, null);
}
-
-
/**
* Compare the differences between two files and return to the original file and diff format
- *
+ *
* (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file.
* You can see all the differences and unmodified places from the original file.
* Also, this will be very easy and useful for making side-by-side comparison display applications,
@@ -372,7 +336,6 @@ public final class UnifiedDiffUtils {
List originalWithPrefix = original.stream().map(v -> " " + v).collect(Collectors.toList());
return insertOrig(originalWithPrefix, unifiedDiff);
}
-
//Insert the diff format to the original file
private static List insertOrig(List original, List unifiedDiff) {
List result = new ArrayList<>();
@@ -401,7 +364,6 @@ public final class UnifiedDiffUtils {
insertOrig(diffList, result, original);
return result;
}
-
//Insert the diff format to the original file
private static void insertOrig(List> diffList, List result, List original) {
for (int i = 0; i < diffList.size(); i++) {
@@ -429,14 +391,12 @@ public final class UnifiedDiffUtils {
}
}
}
-
//Insert the unchanged content in the source file into result
private static void insert(List result, List noChangeContent) {
for (String ins : noChangeContent) {
result.add(ins);
}
}
-
//Parse the line containing @@ to get the modified line number to delete or add a few lines
private static Map getRowMap(String str) {
Map map = new HashMap<>();
@@ -452,7 +412,6 @@ public final class UnifiedDiffUtils {
}
return map;
}
-
//Get the specified part of the line from the original file
private static List getOrigList(List originalWithPrefix, int start, int end) {
List list = new ArrayList<>();
diff --git a/src/com/github/difflib/algorithm/Change.java b/src/com/github/difflib/algorithm/Change.java
index 9b6f1dfe..169e6076 100644
--- a/src/com/github/difflib/algorithm/Change.java
+++ b/src/com/github/difflib/algorithm/Change.java
@@ -14,21 +14,16 @@
* limitations under the License.
*/
package com.github.difflib.algorithm;
-
import com.github.difflib.patch.DeltaType;
-
/**
- *
* @author Tobias Warneke
*/
public class Change {
-
public final DeltaType deltaType;
public final int startOriginal;
public final int endOriginal;
public final int startRevised;
public final int endRevised;
-
public Change(DeltaType deltaType, int startOriginal, int endOriginal, int startRevised, int endRevised) {
this.deltaType = deltaType;
this.startOriginal = startOriginal;
@@ -36,11 +31,9 @@ public class Change {
this.startRevised = startRevised;
this.endRevised = endRevised;
}
-
public Change withEndOriginal(int endOriginal) {
return new Change(deltaType, startOriginal, endOriginal, startRevised, endRevised);
}
-
public Change withEndRevised(int endRevised) {
return new Change(deltaType, startOriginal, endOriginal, startRevised, endRevised);
}
diff --git a/src/com/github/difflib/algorithm/DiffAlgorithmFactory.java b/src/com/github/difflib/algorithm/DiffAlgorithmFactory.java
index 7e5205cd..8871a3f9 100644
--- a/src/com/github/difflib/algorithm/DiffAlgorithmFactory.java
+++ b/src/com/github/difflib/algorithm/DiffAlgorithmFactory.java
@@ -14,16 +14,14 @@
* limitations under the License.
*/
package com.github.difflib.algorithm;
-
import java.util.function.BiPredicate;
-
/**
- * Tool to create new instances of a diff algorithm. This one is only needed at the moment to
+ * Tool to create new instances of a diff algorithm. This one is only needed at the moment to
* set DiffUtils default diff algorithm.
+ *
* @author tw
*/
public interface DiffAlgorithmFactory {
DiffAlgorithmI create();
-
DiffAlgorithmI create(BiPredicate equalizer);
}
diff --git a/src/com/github/difflib/algorithm/DiffAlgorithmI.java b/src/com/github/difflib/algorithm/DiffAlgorithmI.java
index 117656e4..147a733f 100644
--- a/src/com/github/difflib/algorithm/DiffAlgorithmI.java
+++ b/src/com/github/difflib/algorithm/DiffAlgorithmI.java
@@ -14,28 +14,24 @@
* limitations under the License.
*/
package com.github.difflib.algorithm;
-
import java.util.Arrays;
import java.util.List;
-
/**
* Interface of a diff algorithm.
*
- * @author Tobias Warneke (t.warneke@gmx.net)
* @param type of data that is diffed.
+ * @author Tobias Warneke (t.warneke@gmx.net)
*/
public interface DiffAlgorithmI {
-
/**
* Computes the changeset to patch the source list to the target list.
*
- * @param source source data
- * @param target target data
+ * @param source source data
+ * @param target target data
* @param progress progress listener
* @return
*/
List computeDiff(List source, List target, DiffAlgorithmListener progress);
-
/**
* Simple extension to compute a changeset using arrays.
*
diff --git a/src/com/github/difflib/algorithm/DiffAlgorithmListener.java b/src/com/github/difflib/algorithm/DiffAlgorithmListener.java
index 37d51813..f09f428e 100644
--- a/src/com/github/difflib/algorithm/DiffAlgorithmListener.java
+++ b/src/com/github/difflib/algorithm/DiffAlgorithmListener.java
@@ -14,20 +14,18 @@
* limitations under the License.
*/
package com.github.difflib.algorithm;
-
/**
- *
* @author Tobias Warneke (t.warneke@gmx.net)
*/
public interface DiffAlgorithmListener {
void diffStart();
-
/**
* This is a step within the diff algorithm. Due to different implementations the value
* is not strict incrementing to the max and is not garantee to reach the max. It could
* stop before.
+ *
* @param value
- * @param max
+ * @param max
*/
void diffStep(int value, int max);
void diffEnd();
diff --git a/src/com/github/difflib/algorithm/myers/MyersDiff.java b/src/com/github/difflib/algorithm/myers/MyersDiff.java
index 2517de46..2101559d 100644
--- a/src/com/github/difflib/algorithm/myers/MyersDiff.java
+++ b/src/com/github/difflib/algorithm/myers/MyersDiff.java
@@ -14,44 +14,55 @@
* limitations under the License.
*/
package com.github.difflib.algorithm.myers;
-
import com.github.difflib.algorithm.Change;
import com.github.difflib.algorithm.DiffAlgorithmFactory;
import com.github.difflib.algorithm.DiffAlgorithmI;
import com.github.difflib.algorithm.DiffAlgorithmListener;
import com.github.difflib.patch.DeltaType;
import com.github.difflib.patch.Patch;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.BiPredicate;
-
/**
* A clean-room implementation of Eugene Myers greedy differencing algorithm.
*/
public final class MyersDiff implements DiffAlgorithmI {
-
private final BiPredicate equalizer;
-
public MyersDiff() {
equalizer = Object::equals;
}
-
public MyersDiff(final BiPredicate equalizer) {
Objects.requireNonNull(equalizer, "equalizer must not be null");
this.equalizer = equalizer;
}
-
+ /**
+ * Factory to create instances of this specific diff algorithm.
+ */
+ public static DiffAlgorithmFactory factory() {
+ return new DiffAlgorithmFactory() {
+ @Override
+ public DiffAlgorithmI
+ create() {
+ return new MyersDiff<>();
+ }
+ @Override
+ public DiffAlgorithmI
+ create(BiPredicate equalizer) {
+ return new MyersDiff<>(equalizer);
+ }
+ };
+ }
/**
* {@inheritDoc}
- *
+ *
* Return empty diff if get the error while procession the difference.
*/
@Override
public List computeDiff(final List source, final List target, DiffAlgorithmListener progress) {
Objects.requireNonNull(source, "source list must not be null");
Objects.requireNonNull(target, "target list must not be null");
-
if (progress != null) {
progress.diffStart();
}
@@ -62,30 +73,26 @@ public final class MyersDiff implements DiffAlgorithmI {
}
return result;
}
-
/**
* Computes the minimum diffpath that expresses de differences between the
* original and revised sequences, according to Gene Myers differencing
* algorithm.
*
* @param orig The original sequence.
- * @param rev The revised sequence.
+ * @param rev The revised sequence.
* @return A minimum {@link PathNode Path} accross the differences graph.
* @throws DifferentiationFailedException if a diff path could not be found.
*/
private PathNode buildPath(final List orig, final List rev, DiffAlgorithmListener progress) {
Objects.requireNonNull(orig, "original sequence is null");
Objects.requireNonNull(rev, "revised sequence is null");
-
// these are local constants
final int N = orig.size();
final int M = rev.size();
-
final int MAX = N + M + 1;
final int size = 1 + 2 * MAX;
final int middle = size / 2;
final PathNode diagonal[] = new PathNode[size];
-
diagonal[middle + 1] = new PathNode(0, -1, true, true, null);
for (int d = 0; d < MAX; d++) {
if (progress != null) {
@@ -97,7 +104,6 @@ public final class MyersDiff implements DiffAlgorithmI {
final int kminus = kmiddle - 1;
PathNode prev;
int i;
-
if ((k == -d) || (k != d && diagonal[kminus].i < diagonal[kplus].i)) {
i = diagonal[kplus].i;
prev = diagonal[kplus];
@@ -105,24 +111,17 @@ public final class MyersDiff implements DiffAlgorithmI {
i = diagonal[kminus].i + 1;
prev = diagonal[kminus];
}
-
diagonal[kminus] = null; // no longer used
-
int j = i - k;
-
PathNode node = new PathNode(i, j, false, false, prev);
-
while (i < N && j < M && equalizer.test(orig.get(i), rev.get(j))) {
i++;
j++;
}
-
if (i != node.i) {
node = new PathNode(i, j, true, false, node);
}
-
diagonal[kmiddle] = node;
-
if (i >= N && j >= M) {
return diagonal[kmiddle];
}
@@ -132,22 +131,20 @@ public final class MyersDiff implements DiffAlgorithmI {
// According to Myers, this cannot happen
throw new IllegalStateException("could not find a diff path");
}
-
/**
* Constructs a {@link Patch} from a difference path.
*
* @param actualPath The path.
- * @param orig The original sequence.
- * @param rev The revised sequence.
+ * @param orig The original sequence.
+ * @param rev The revised sequence.
* @return A {@link Patch} script corresponding to the path.
* @throws DifferentiationFailedException if a {@link Patch} could not be
- * built from the given path.
+ * built from the given path.
*/
private List buildRevision(PathNode actualPath, List orig, List rev) {
Objects.requireNonNull(actualPath, "path is null");
Objects.requireNonNull(orig, "original sequence is null");
Objects.requireNonNull(rev, "revised sequence is null");
-
PathNode path = actualPath;
List changes = new ArrayList<>();
if (path.isSnake()) {
@@ -159,11 +156,9 @@ public final class MyersDiff implements DiffAlgorithmI {
}
int i = path.i;
int j = path.j;
-
path = path.prev;
int ianchor = path.i;
int janchor = path.j;
-
if (ianchor == i && janchor != j) {
changes.add(new Change(DeltaType.INSERT, ianchor, i, janchor, j));
} else if (ianchor != i && janchor == j) {
@@ -171,30 +166,10 @@ public final class MyersDiff implements DiffAlgorithmI {
} else {
changes.add(new Change(DeltaType.CHANGE, ianchor, i, janchor, j));
}
-
if (path.isSnake()) {
path = path.prev;
}
}
return changes;
}
-
- /**
- * Factory to create instances of this specific diff algorithm.
- */
- public static DiffAlgorithmFactory factory() {
- return new DiffAlgorithmFactory() {
- @Override
- public DiffAlgorithmI
- create() {
- return new MyersDiff<>();
- }
-
- @Override
- public DiffAlgorithmI
- create(BiPredicate < T, T > equalizer) {
- return new MyersDiff<>(equalizer);
- }
- };
- }
}
diff --git a/src/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java b/src/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java
index ca4114c4..b1232412 100644
--- a/src/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java
+++ b/src/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java
@@ -14,60 +14,65 @@
* limitations under the License.
*/
package com.github.difflib.algorithm.myers;
-
import com.github.difflib.algorithm.Change;
import com.github.difflib.algorithm.DiffAlgorithmFactory;
import com.github.difflib.algorithm.DiffAlgorithmI;
import com.github.difflib.algorithm.DiffAlgorithmListener;
import com.github.difflib.patch.DeltaType;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
-
/**
- *
* @author tw
*/
public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
-
private final BiPredicate equalizer;
-
public MyersDiffWithLinearSpace() {
equalizer = Object::equals;
}
-
public MyersDiffWithLinearSpace(final BiPredicate equalizer) {
Objects.requireNonNull(equalizer, "equalizer must not be null");
this.equalizer = equalizer;
}
-
+ /**
+ * Factory to create instances of this specific diff algorithm.
+ */
+ public static DiffAlgorithmFactory factory() {
+ return new DiffAlgorithmFactory() {
+ @Override
+ public DiffAlgorithmI
+ create() {
+ return new MyersDiffWithLinearSpace<>();
+ }
+ @Override
+ public DiffAlgorithmI
+ create(BiPredicate equalizer) {
+ return new MyersDiffWithLinearSpace<>(equalizer);
+ }
+ };
+ }
@Override
public List computeDiff(List source, List target, DiffAlgorithmListener progress) {
Objects.requireNonNull(source, "source list must not be null");
Objects.requireNonNull(target, "target list must not be null");
-
if (progress != null) {
progress.diffStart();
}
-
DiffData data = new DiffData(source, target);
-
int maxIdx = source.size() + target.size();
-
buildScript(data, 0, source.size(), 0, target.size(), idx -> {
if (progress != null) {
progress.diffStep(idx, maxIdx);
}
});
-
if (progress != null) {
progress.diffEnd();
}
return data.script;
}
-
private void buildScript(DiffData data, int start1, int end1, int start2, int end2, Consumer progress) {
if (progress != null) {
progress.accept((end1 - start1) / 2 + (end2 - start2) / 2);
@@ -112,35 +117,29 @@ public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
buildScript(data, middle.end, end1, middle.end - middle.diag, end2, progress);
}
}
-
private Snake getMiddleSnake(DiffData data, int start1, int end1, int start2, int end2) {
final int m = end1 - start1;
final int n = end2 - start2;
if (m == 0 || n == 0) {
return null;
}
-
final int delta = m - n;
final int sum = n + m;
final int offset = (sum % 2 == 0 ? sum : sum + 1) / 2;
data.vDown[1 + offset] = start1;
data.vUp[1 + offset] = end1 + 1;
-
for (int d = 0; d <= offset; ++d) {
// Down
for (int k = -d; k <= d; k += 2) {
// First step
-
final int i = k + offset;
if (k == -d || k != d && data.vDown[i - 1] < data.vDown[i + 1]) {
data.vDown[i] = data.vDown[i + 1];
} else {
data.vDown[i] = data.vDown[i - 1] + 1;
}
-
int x = data.vDown[i];
int y = x - start1 + start2 - k;
-
while (x < end1 && y < end2 && equalizer.test(data.source.get(x), data.target.get(y))) {
data.vDown[i] = ++x;
++y;
@@ -152,7 +151,6 @@ public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
}
}
}
-
// Up
for (int k = delta - d; k <= delta + d; k += 2) {
// First step
@@ -163,7 +161,6 @@ public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
} else {
data.vUp[i] = data.vUp[i - 1];
}
-
int x = data.vUp[i] - 1;
int y = x - start1 + start2 - k;
while (x >= start1 && y >= start2 && equalizer.test(data.source.get(x), data.target.get(y))) {
@@ -178,11 +175,9 @@ public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
}
}
}
-
// According to Myers, this cannot happen
throw new IllegalStateException("could not find a diff path");
}
-
private Snake buildSnake(DiffData data, final int start, final int diag, final int end1, final int end2) {
int end = start;
while (end - diag < end2 && end < end1 && equalizer.test(data.source.get(end), data.target.get(end - diag))) {
@@ -190,16 +185,13 @@ public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
}
return new Snake(start, end, diag);
}
-
private class DiffData {
-
final int size;
final int[] vDown;
final int[] vUp;
final List script;
final List source;
final List target;
-
public DiffData(List source, List target) {
this.source = source;
this.target = target;
@@ -209,36 +201,14 @@ public class MyersDiffWithLinearSpace implements DiffAlgorithmI {
script = new ArrayList<>();
}
}
-
private class Snake {
-
final int start;
final int end;
final int diag;
-
public Snake(final int start, final int end, final int diag) {
this.start = start;
this.end = end;
this.diag = diag;
}
}
-
- /**
- * Factory to create instances of this specific diff algorithm.
- */
- public static DiffAlgorithmFactory factory() {
- return new DiffAlgorithmFactory() {
- @Override
- public DiffAlgorithmI
- create() {
- return new MyersDiffWithLinearSpace<>();
- }
-
- @Override
- public DiffAlgorithmI
- create(BiPredicate < T, T > equalizer) {
- return new MyersDiffWithLinearSpace<>(equalizer);
- }
- };
- }
}
diff --git a/src/com/github/difflib/algorithm/myers/PathNode.java b/src/com/github/difflib/algorithm/myers/PathNode.java
index fe8fd03a..eadc7b0c 100644
--- a/src/com/github/difflib/algorithm/myers/PathNode.java
+++ b/src/com/github/difflib/algorithm/myers/PathNode.java
@@ -14,14 +14,12 @@
* limitations under the License.
*/
package com.github.difflib.algorithm.myers;
-
/**
* A node in a diffpath.
*
* @author Juanco Anez
*/
public final class PathNode {
-
/**
* Position in the original sequence.
*/
@@ -34,16 +32,13 @@ public final class PathNode {
* The previous node in the path.
*/
public final PathNode prev;
-
public final boolean snake;
-
public final boolean bootstrap;
-
/**
* Concatenates a new path node with an existing diffpath.
*
- * @param i The position in the original sequence for the new node.
- * @param j The position in the revised sequence for the new node.
+ * @param i The position in the original sequence for the new node.
+ * @param j The position in the revised sequence for the new node.
* @param prev The previous node in the path.
*/
public PathNode(int i, int j, boolean snake, boolean bootstrap, PathNode prev) {
@@ -57,11 +52,9 @@ public final class PathNode {
}
this.snake = snake;
}
-
public boolean isSnake() {
return snake;
}
-
/**
* Is this a bootstrap node?
*
@@ -72,7 +65,6 @@ public final class PathNode {
public boolean isBootstrap() {
return bootstrap;
}
-
/**
* Skips sequences of {@link PathNode PathNodes} until a snake or bootstrap node is found, or the end of the
* path is reached.
@@ -88,7 +80,6 @@ public final class PathNode {
}
return this;
}
-
/**
* {@inheritDoc}
*/
diff --git a/src/com/github/difflib/patch/AbstractDelta.java b/src/com/github/difflib/patch/AbstractDelta.java
index f74f62ca..511560c4 100644
--- a/src/com/github/difflib/patch/AbstractDelta.java
+++ b/src/com/github/difflib/patch/AbstractDelta.java
@@ -14,20 +14,18 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
-
/**
- * Abstract delta between a source and a target.
+ * Abstract delta between a source and a target.
+ *
* @author Tobias Warneke (t.warneke@gmx.net)
*/
public abstract class AbstractDelta implements Serializable {
private final Chunk source;
private final Chunk target;
private final DeltaType type;
-
public AbstractDelta(DeltaType type, Chunk source, Chunk target) {
Objects.requireNonNull(source);
Objects.requireNonNull(target);
@@ -36,28 +34,24 @@ public abstract class AbstractDelta implements Serializable {
this.source = source;
this.target = target;
}
-
public Chunk getSource() {
return source;
}
-
public Chunk getTarget() {
return target;
}
-
public DeltaType getType() {
return type;
}
-
/**
* Verify the chunk of this delta, to fit the target.
+ *
* @param target
- * @throws PatchFailedException
+ * @throws PatchFailedException
*/
protected VerifyChunk verifyChunkToFitTarget(List target) throws PatchFailedException {
return getSource().verifyChunk(target);
}
-
protected VerifyChunk verifyAndApplyTo(List target) throws PatchFailedException {
final VerifyChunk verify = verifyChunkToFitTarget(target);
if (verify == VerifyChunk.OK) {
@@ -65,16 +59,13 @@ public abstract class AbstractDelta implements Serializable {
}
return verify;
}
-
protected abstract void applyTo(List target) throws PatchFailedException;
-
protected abstract void restore(List target);
-
/**
* Apply patch fuzzy.
*
- * @param target the list this patch will be applied to
- * @param fuzz the number of elements to ignore before/after the patched elements
+ * @param target the list this patch will be applied to
+ * @param fuzz the number of elements to ignore before/after the patched elements
* @param position the position this patch will be applied to. ignores {@code source.getPosition()}
* @see Description of Fuzzy Patch for more information.
*/
@@ -82,17 +73,14 @@ public abstract class AbstractDelta implements Serializable {
protected void applyFuzzyToAt(List target, int fuzz, int position) throws PatchFailedException {
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " does not supports applying patch fuzzy");
}
-
/**
* Create a new delta of the actual instance with customized chunk data.
*/
public abstract AbstractDelta withChunks(Chunk original, Chunk revised);
-
@Override
public int hashCode() {
return Objects.hash(this.source, this.target, this.type);
}
-
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/src/com/github/difflib/patch/ChangeDelta.java b/src/com/github/difflib/patch/ChangeDelta.java
index 376fd625..b266d408 100644
--- a/src/com/github/difflib/patch/ChangeDelta.java
+++ b/src/com/github/difflib/patch/ChangeDelta.java
@@ -14,18 +14,15 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
import java.util.List;
import java.util.Objects;
-
/**
* Describes the change-delta between original and revised texts.
*
- * @author Dmitry Naumenko
* @param The type of the compared elements in the data 'lines'.
+ * @author Dmitry Naumenko
*/
public final class ChangeDelta extends AbstractDelta {
-
/**
* Creates a change delta with the two given chunks.
*
@@ -37,7 +34,6 @@ public final class ChangeDelta extends AbstractDelta {
Objects.requireNonNull(source, "source must not be null");
Objects.requireNonNull(target, "target must not be null");
}
-
@Override
protected void applyTo(List target) throws PatchFailedException {
int position = getSource().getPosition();
@@ -51,7 +47,6 @@ public final class ChangeDelta extends AbstractDelta {
i++;
}
}
-
@Override
protected void restore(List target) {
int position = getTarget().getPosition();
@@ -65,26 +60,22 @@ public final class ChangeDelta extends AbstractDelta {
i++;
}
}
-
protected void applyFuzzyToAt(List target, int fuzz, int position) throws PatchFailedException {
int size = getSource().size();
for (int i = fuzz; i < size - fuzz; i++) {
target.remove(position + fuzz);
}
-
int i = fuzz;
for (T line : getTarget().getLines().subList(fuzz, getTarget().size() - fuzz)) {
target.add(position + i, line);
i++;
}
}
-
@Override
public String toString() {
return "[ChangeDelta, position: " + getSource().getPosition() + ", lines: "
+ getSource().getLines() + " to " + getTarget().getLines() + "]";
}
-
@Override
public AbstractDelta withChunks(Chunk original, Chunk revised) {
return new ChangeDelta(original, revised);
diff --git a/src/com/github/difflib/patch/Chunk.java b/src/com/github/difflib/patch/Chunk.java
index 072198a6..dfea5da0 100644
--- a/src/com/github/difflib/patch/Chunk.java
+++ b/src/com/github/difflib/patch/Chunk.java
@@ -14,13 +14,11 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
-
/**
* Holds the information about the part of text involved in the diff process
*
@@ -32,20 +30,18 @@ import java.util.Objects;
* differencing using this library.
*
*
- * @author Dmitry Naumenko
*/
public final class Chunk implements Serializable {
-
private final int position;
- private List lines;
private final List changePosition;
-
+ private List lines;
/**
* Creates a chunk and saves a copy of affected lines
*
- * @param position the start position
- * @param lines the affected lines
+ * @param position the start position
+ * @param lines the affected lines
* @param changePosition the positions of changed lines
*/
public Chunk(int position, List lines, List changePosition) {
@@ -53,22 +49,20 @@ public final class Chunk implements Serializable {
this.lines = new ArrayList<>(lines);
this.changePosition = changePosition != null ? new ArrayList<>(changePosition) : null;
}
-
/**
* Creates a chunk and saves a copy of affected lines
*
* @param position the start position
- * @param lines the affected lines
+ * @param lines the affected lines
*/
public Chunk(int position, List lines) {
this(position, lines, null);
}
-
/**
* Creates a chunk and saves a copy of affected lines
*
- * @param position the start position
- * @param lines the affected lines
+ * @param position the start position
+ * @param lines the affected lines
* @param changePosition the positions of changed lines
*/
public Chunk(int position, T[] lines, List changePosition) {
@@ -76,17 +70,15 @@ public final class Chunk implements Serializable {
this.lines = Arrays.asList(lines);
this.changePosition = changePosition != null ? new ArrayList<>(changePosition) : null;
}
-
/**
* Creates a chunk and saves a copy of affected lines
*
* @param position the start position
- * @param lines the affected lines
+ * @param lines the affected lines
*/
public Chunk(int position, T[] lines) {
this(position, lines, null);
}
-
/**
* Verifies that this chunk's saved text matches the corresponding text in
* the given sequence.
@@ -97,13 +89,12 @@ public final class Chunk implements Serializable {
public VerifyChunk verifyChunk(List target) throws PatchFailedException {
return verifyChunk(target, 0, getPosition());
}
-
/**
* Verifies that this chunk's saved text matches the corresponding text in
* the given sequence.
*
- * @param target the sequence to verify against.
- * @param fuzz the count of ignored prefix/suffix
+ * @param target the sequence to verify against.
+ * @param fuzz the count of ignored prefix/suffix
* @param position the position of target
* @throws PatchFailedException
*/
@@ -112,7 +103,6 @@ public final class Chunk implements Serializable {
int startIndex = fuzz;
int lastIndex = size() - fuzz;
int last = position + size() - 1;
-
if (position + fuzz > target.size() || last - fuzz > target.size()) {
return VerifyChunk.POSITION_OUT_OF_TARGET;
}
@@ -123,48 +113,40 @@ public final class Chunk implements Serializable {
}
return VerifyChunk.OK;
}
-
/**
* @return the start position of chunk in the text
*/
public int getPosition() {
return position;
}
-
- public void setLines(List lines) {
- this.lines = lines;
- }
-
/**
* @return the affected lines
*/
public List getLines() {
return lines;
}
-
+ public void setLines(List lines) {
+ this.lines = lines;
+ }
/**
* @return the positions of changed lines of chunk in the text
*/
public List getChangePosition() {
return changePosition;
}
-
public int size() {
return lines.size();
}
-
/**
* Returns the index of the last line of the chunk.
*/
public int last() {
return getPosition() + size() - 1;
}
-
@Override
public int hashCode() {
return Objects.hash(lines, position, size());
}
-
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -186,10 +168,8 @@ public final class Chunk implements Serializable {
}
return position == other.position;
}
-
@Override
public String toString() {
return "[position: " + position + ", size: " + size() + ", lines: " + lines + "]";
}
-
}
diff --git a/src/com/github/difflib/patch/ConflictOutput.java b/src/com/github/difflib/patch/ConflictOutput.java
index 2dfff6a5..74ee32f4 100644
--- a/src/com/github/difflib/patch/ConflictOutput.java
+++ b/src/com/github/difflib/patch/ConflictOutput.java
@@ -18,16 +18,12 @@ limitations under the License.
* #L%
*/
package com.github.difflib.patch;
-
import java.io.Serializable;
import java.util.List;
-
/**
- *
* @author tw
*/
@FunctionalInterface
public interface ConflictOutput extends Serializable {
-
public void processConflict(VerifyChunk verifyChunk, AbstractDelta delta, List result) throws PatchFailedException;
}
diff --git a/src/com/github/difflib/patch/DeleteDelta.java b/src/com/github/difflib/patch/DeleteDelta.java
index 890b8575..a420c754 100644
--- a/src/com/github/difflib/patch/DeleteDelta.java
+++ b/src/com/github/difflib/patch/DeleteDelta.java
@@ -14,27 +14,23 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
import java.util.List;
-
/**
* Describes the delete-delta between original and revised texts.
*
- * @author Dmitry Naumenko
* @param The type of the compared elements in the 'lines'.
+ * @author Dmitry Naumenko
*/
public final class DeleteDelta extends AbstractDelta {
-
/**
* Creates a change delta with the two given chunks.
*
* @param original The original chunk. Must not be {@code null}.
- * @param revised The original chunk. Must not be {@code null}.
+ * @param revised The original chunk. Must not be {@code null}.
*/
public DeleteDelta(Chunk original, Chunk revised) {
super(DeltaType.DELETE, original, revised);
}
-
@Override
protected void applyTo(List target) throws PatchFailedException {
int position = getSource().getPosition();
@@ -43,7 +39,6 @@ public final class DeleteDelta extends AbstractDelta {
target.remove(position);
}
}
-
@Override
protected void restore(List target) {
int position = this.getTarget().getPosition();
@@ -52,13 +47,11 @@ public final class DeleteDelta extends AbstractDelta {
target.add(position + i, lines.get(i));
}
}
-
@Override
public String toString() {
return "[DeleteDelta, position: " + getSource().getPosition() + ", lines: "
+ getSource().getLines() + "]";
}
-
@Override
public AbstractDelta withChunks(Chunk original, Chunk revised) {
return new DeleteDelta(original, revised);
diff --git a/src/com/github/difflib/patch/DeltaType.java b/src/com/github/difflib/patch/DeltaType.java
index 666e803a..6edeebe2 100644
--- a/src/com/github/difflib/patch/DeltaType.java
+++ b/src/com/github/difflib/patch/DeltaType.java
@@ -14,21 +14,19 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
/**
- * Specifies the type of the delta. There are three types of modifications from
- * the original to get the revised text.
- *
+ * Specifies the type of the delta. There are three types of modifications from
+ * the original to get the revised text.
+ *
* CHANGE: a block of data of the original is replaced by another block of data.
* DELETE: a block of data of the original is removed
* INSERT: at a position of the original a block of data is inserted
- *
- * to be complete there is also
- *
+ *
+ * to be complete there is also
+ *
* EQUAL: a block of data of original and the revised text is equal
- *
+ *
* which is no change at all.
- *
*/
public enum DeltaType {
/**
diff --git a/src/com/github/difflib/patch/DiffException.java b/src/com/github/difflib/patch/DiffException.java
index da01d621..2598456f 100644
--- a/src/com/github/difflib/patch/DiffException.java
+++ b/src/com/github/difflib/patch/DiffException.java
@@ -14,19 +14,15 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
/**
* Base class for all exceptions emanating from this package.
*
* @author Juanco Anez
*/
public class DiffException extends Exception {
-
private static final long serialVersionUID = 1L;
-
public DiffException() {
}
-
public DiffException(String msg) {
super(msg);
}
diff --git a/src/com/github/difflib/patch/EqualDelta.java b/src/com/github/difflib/patch/EqualDelta.java
index 17fdadc6..3d4ba3ce 100644
--- a/src/com/github/difflib/patch/EqualDelta.java
+++ b/src/com/github/difflib/patch/EqualDelta.java
@@ -14,27 +14,22 @@
* limitations under the License.
*/
package com.github.difflib.patch;
-
import java.util.List;
-
/**
* This delta contains equal lines of data. Therefore nothing is to do in applyTo and restore.
+ *
* @author tobens
*/
public class EqualDelta extends AbstractDelta {
-
public EqualDelta(Chunk source, Chunk target) {
super(DeltaType.EQUAL, source, target);
}
-
@Override
protected void applyTo(List target) throws PatchFailedException {
}
-
@Override
protected void restore(List target) {
}
-
/**
* {@inheritDoc}
*/
@@ -42,13 +37,11 @@ public class EqualDelta extends AbstractDelta {
protected void applyFuzzyToAt(List target, int fuzz, int delta) {
// equals so no operations
}
-
@Override
public String toString() {
return "[EqualDelta, position: " + getSource().getPosition() + ", lines: "
+ getSource().getLines() + "]";
}
-
@Override
public AbstractDelta withChunks(Chunk original, Chunk revised) {
return new EqualDelta