difflib
Class DiffUtils

java.lang.Object
  extended by difflib.DiffUtils

public class DiffUtils
extends java.lang.Object

Implements the difference and patching engine

Version:
0.4.1
Author:
Dmitry Naumenko

Constructor Summary
DiffUtils()
           
 
Method Summary
static Patch diff(java.util.List<?> original, java.util.List<?> revised)
          Compute the difference between the original and revised texts with default diff algorithm
static Patch diff(java.util.List<?> original, java.util.List<?> revised, DiffAlgorithm algorithm)
          Compute the difference between the original and revised texts with given 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 patch, int contextSize)
          generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing the Patch.
static Patch parseUnifiedDiff(java.util.List<java.lang.String> diff)
          Parse the given text in unified format and creates the list of deltas for it.
static java.util.List<?> patch(java.util.List<?> original, Patch patch)
          Patch the original text with given patch
static java.util.List<?> unpatch(java.util.List<?> revised, Patch patch)
          Unpatch the revised text for a given patch
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiffUtils

public DiffUtils()
Method Detail

diff

public static Patch diff(java.util.List<?> original,
                         java.util.List<?> revised)
Compute the difference between the original and revised texts with default diff algorithm

Parameters:
original - the original text
revised - the revised text
Returns:
the patch describing the difference between the original and revised texts

diff

public static Patch diff(java.util.List<?> original,
                         java.util.List<?> revised,
                         DiffAlgorithm algorithm)
Compute the difference between the original and revised texts with given diff algorithm

Parameters:
original - the original text
revised - the revised text
algorithm - the given algorithm
Returns:
the patch describing the difference between the original and revised texts

patch

public static java.util.List<?> patch(java.util.List<?> original,
                                      Patch patch)
                               throws PatchFailedException
Patch the original text with given patch

Parameters:
original - the original text
patch - the given patch
Returns:
the revised text
Throws:
PatchFailedException - if can't apply patch

unpatch

public static java.util.List<?> unpatch(java.util.List<?> revised,
                                        Patch patch)
Unpatch the revised text for a given patch

Parameters:
revised - the revised text
patch - the given patch
Returns:
the original text

parseUnifiedDiff

public static Patch parseUnifiedDiff(java.util.List<java.lang.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 java.util.List<java.lang.String> generateUnifiedDiff(java.lang.String original,
                                                                   java.lang.String revised,
                                                                   java.util.List<java.lang.String> originalLines,
                                                                   Patch 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 file
originalLines - - Lines of the original file
patch - - Patch created by the diff() function
contextSize - - 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.