Package org.assertj.core.util.diff
Class DiffUtils
- java.lang.Object
-
- org.assertj.core.util.diff.DiffUtils
-
public class DiffUtils extends Object
Copy from https://code.google.com/p/java-diff-utils/.Implements the difference and patching engine
- Author:
- Dmitry Naumenko, Bill James ([email protected])
-
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
unifiedDiffChunkRe
-
Constructor Summary
Constructors Constructor Description DiffUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Patch<T>
diff(List<T> original, List<T> revised)
Computes the difference between the original and revised list of elements with default diff algorithmstatic <T> Patch<T>
diff(List<T> original, List<T> revised, DiffAlgorithm<T> algorithm)
Computes the difference between the original and revised list of elements with default diff algorithmstatic List<String>
generateUnifiedDiff(String original, String revised, List<String> originalLines, Patch<String> patch, int contextSize)
generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing the Patch.private static List<String>
getDeltaText(Delta<String> delta)
getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameterstatic Patch<String>
parseUnifiedDiff(List<String> diff)
Parse the given text in unified format and creates the list of deltas for it.static <T> List<T>
patch(List<T> original, Patch<T> patch)
Patch the original text with given patchprivate static List<String>
processDeltas(List<String> origLines, List<Delta<String>> deltas, int contextSize)
processDeltas takes a list of Deltas and outputs them together in a single block of Unified-Diff-format text.
-
-
-
Field Detail
-
unifiedDiffChunkRe
private static Pattern unifiedDiffChunkRe
-
-
Method Detail
-
diff
public static <T> Patch<T> diff(List<T> original, List<T> revised)
Computes the difference between the original and revised list of elements with default diff algorithm- Type Parameters:
T
- the type of elements.- Parameters:
original
- The original text. Must not benull
.revised
- The revised text. Must not benull
.- Returns:
- The patch describing the difference between the original and
revised sequences. Never
null
.
-
diff
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithm<T> algorithm)
Computes the difference between the original and revised list of elements with default diff algorithm- Type Parameters:
T
- the type of elements.- Parameters:
original
- The original text. Must not benull
.revised
- The revised text. Must not benull
.algorithm
- The diff algorithm. Must not benull
.- Returns:
- The patch describing the difference between the original and
revised sequences. Never
null
.
-
patch
public static <T> List<T> patch(List<T> original, Patch<T> patch) throws IllegalStateException
Patch the original text with given patch- Type Parameters:
T
- the type of elements.- Parameters:
original
- the original textpatch
- the given patch- Returns:
- the revised text
- Throws:
IllegalStateException
- if can't apply patch
-
parseUnifiedDiff
public static Patch<String> parseUnifiedDiff(List<String> diff)
Parse the given text in unified format and creates the list of deltas for it.- Parameters:
diff
- the text in unified format- Returns:
- the patch with deltas.
-
generateUnifiedDiff
public static List<String> generateUnifiedDiff(String original, String revised, List<String> originalLines, Patch<String> patch, int contextSize)
generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing the Patch.- Parameters:
original
- Filename of the original (unrevised file)revised
- Filename of the revised fileoriginalLines
- Lines of the original filepatch
- Patch created by the diff() functioncontextSize
- number of lines of context output around each difference in the file.- Returns:
- List of strings representing the Unified Diff representation of the Patch argument.
-
processDeltas
private static List<String> processDeltas(List<String> origLines, List<Delta<String>> deltas, int contextSize)
processDeltas takes a list of Deltas and outputs them together in a single block of Unified-Diff-format text.- Parameters:
origLines
- the lines of the original filedeltas
- the Deltas to be output as a single blockcontextSize
- the number of lines of context to place around block- Returns:
- the Unified-Diff-format text
-
-