Package org.assertj.core.util.diff.myers
Class MyersDiff<T>
- java.lang.Object
-
- org.assertj.core.util.diff.myers.MyersDiff<T>
-
- Type Parameters:
T- The type of the compared elements in the 'lines'.
- All Implemented Interfaces:
DiffAlgorithm<T>
public class MyersDiff<T> extends Object implements DiffAlgorithm<T>
Copy from https://code.google.com/p/java-diff-utils/.A clean-room implementation of Eugene Myers differencing algorithm.
See the paper at http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps
- Author:
- Juanco Anez
-
-
Constructor Summary
Constructors Constructor Description MyersDiff()Constructs an instance of the Myers differencing algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PathNodebuildPath(List<T> orig, List<T> rev)Computes the minimum diffpath that expresses de differences between the original and revised sequences, according to Gene Myers differencing algorithm.Patch<T>buildRevision(PathNode path, List<T> orig, List<T> rev)Constructs aPatchfrom a difference path.private List<T>copyOfRange(List<T> original, int fromIndex, int to)Creates a new list containing the elements returned byList.subList(int, int).Patch<T>diff(List<T> original, List<T> revised)Computes the difference between the original sequence and the revised sequence and returns it as aPatchobject.private booleanequals(T orig, T rev)
-
-
-
Method Detail
-
diff
public Patch<T> diff(List<T> original, List<T> revised)
Computes the difference between the original sequence and the revised sequence and returns it as aPatchobject. Return empty diff if get the error while procession the difference.- Specified by:
diffin interfaceDiffAlgorithm<T>- Parameters:
original- The original sequence. Must not benull.revised- The revised sequence. Must not benull.- Returns:
- The patch representing the diff of the given sequences. Never
null.
-
buildPath
public PathNode buildPath(List<T> orig, List<T> rev)
Computes the minimum diffpath that expresses de differences between the original and revised sequences, according to Gene Myers differencing algorithm.- Parameters:
orig- The original sequence.rev- The revised sequence.- Returns:
- A minimum
Pathacross the differences graph. - Throws:
IllegalStateException- if a diff path could not be found.
-
buildRevision
public Patch<T> buildRevision(PathNode path, List<T> orig, List<T> rev)
Constructs aPatchfrom a difference path.- Parameters:
path- The path.orig- The original sequence.rev- The revised sequence.- Returns:
- A
Patchscript corresponding to the path.
-
copyOfRange
private List<T> copyOfRange(List<T> original, int fromIndex, int to)
Creates a new list containing the elements returned byList.subList(int, int).- Parameters:
original- The original sequence. Must not benull.fromIndex- low endpoint (inclusive) of the subList.to- high endpoint (exclusive) of the subList.- Returns:
- A new list of the specified range within the original list.
-
-