public class DiffUtils
extends java.lang.Object
Implements the difference and patching engine
| Modifier and Type | Field and Description |
|---|---|
private static java.util.regex.Pattern |
unifiedDiffChunkRe |
| Constructor and Description |
|---|
DiffUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Patch<T> |
diff(java.util.List<T> original,
java.util.List<T> revised)
Computes the difference between the original and revised list of elements
with default diff algorithm
|
static <T> Patch<T> |
diff(java.util.List<T> original,
java.util.List<T> revised,
DiffAlgorithm<T> algorithm)
Computes the difference between the original and revised list of elements
with default diff algorithm
|
static java.util.List<java.lang.String> |
generateUnifiedDiff(java.lang.String original,
java.lang.String revised,
java.util.List<java.lang.String> originalLines,
Patch<java.lang.String> patch,
int contextSize)
generateUnifiedDiff takes a Patch and some other arguments, returning the
Unified Diff format text representing the Patch.
|
private static java.util.List<java.lang.String> |
getDeltaText(Delta<java.lang.String> delta)
getDeltaText returns the lines to be added to the Unified Diff text from
the Delta parameter
|
static Patch<java.lang.String> |
parseUnifiedDiff(java.util.List<java.lang.String> diff)
Parse the given text in unified format and creates the list of deltas for
it.
|
static <T> java.util.List<T> |
patch(java.util.List<T> original,
Patch<T> patch)
Patch the original text with given patch
|
private static java.util.List<java.lang.String> |
processDeltas(java.util.List<java.lang.String> origLines,
java.util.List<Delta<java.lang.String>> deltas,
int contextSize)
processDeltas takes a list of Deltas and outputs them together in a
single block of Unified-Diff-format text.
|
public static <T> Patch<T> diff(java.util.List<T> original, java.util.List<T> revised)
original - The original text. Must not be null.revised - The revised text. Must not be null.null.public static <T> Patch<T> diff(java.util.List<T> original, java.util.List<T> revised, DiffAlgorithm<T> algorithm)
original - The original text. Must not be null.revised - The revised text. Must not be null.algorithm - The diff algorithm. Must not be null.null.public static <T> java.util.List<T> patch(java.util.List<T> original,
Patch<T> patch)
throws java.lang.IllegalStateException
original - the original textpatch - the given patchjava.lang.IllegalStateException - if can't apply patchpublic static Patch<java.lang.String> parseUnifiedDiff(java.util.List<java.lang.String> diff)
diff - the text in unified formatpublic static java.util.List<java.lang.String> generateUnifiedDiff(java.lang.String original,
java.lang.String revised,
java.util.List<java.lang.String> originalLines,
Patch<java.lang.String> patch,
int contextSize)
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.private static java.util.List<java.lang.String> processDeltas(java.util.List<java.lang.String> origLines,
java.util.List<Delta<java.lang.String>> deltas,
int contextSize)
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 blockprivate static java.util.List<java.lang.String> getDeltaText(Delta<java.lang.String> delta)
delta - the Delta to output