Class DiffUtils

java.lang.Object
com.github.difflib.DiffUtils

public final class DiffUtils extends Object
Implements the difference and patching engine
  • Field Details

    • DEFAULT_DIFF

      static DiffAlgorithmFactory DEFAULT_DIFF
      This factory generates the DEFAULT_DIFF algorithm for all these routines.
  • Constructor Details

    • DiffUtils

      private DiffUtils()
  • Method Details

    • withDefaultDiffAlgorithmFactory

      public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory)
    • diff

      public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmListener progress)
      Computes the difference between the original and revised list of elements with default diff algorithm
      Type Parameters:
      T - types to be diffed
      Parameters:
      original - The original text. Must not be null.
      revised - The revised text. Must not be null.
      progress - progress listener
      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)
    • diff

      public static <T> Patch<T> diff(List<T> original, List<T> revised, boolean includeEqualParts)
    • diff

      public static Patch<String> diff(String sourceText, String targetText, DiffAlgorithmListener progress)
      Computes the difference between the original and revised text.
    • diff

      public static <T> Patch<T> diff(List<T> source, List<T> target, BiPredicate<T,T> equalizer)
      Computes the difference between the original and revised list of elements with default diff algorithm
      Parameters:
      source - The original text. Must not be null.
      target - The revised text. Must not be null.
      equalizer - the equalizer object to replace the default compare algorithm (Object.equals). If null the default equalizer of the default algorithm is used..
      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, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress)
    • diff

      public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress, boolean includeEqualParts)
      Computes the difference between the original and revised list of elements with default diff algorithm
      Parameters:
      original - The original text. Must not be null.
      revised - The revised text. Must not be null.
      algorithm - The diff algorithm. Must not be null.
      progress - The diff algorithm listener.
      includeEqualParts - Include equal data parts into the patch.
      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, DiffAlgorithmI<T> algorithm)
      Computes the difference between the original and revised list of elements with default diff algorithm
      Parameters:
      original - The original text. Must not be null.
      revised - The revised text. Must not be null.
      algorithm - The diff algorithm. Must not be null.
      Returns:
      The patch describing the difference between the original and revised sequences. Never null.
    • diffInline

      public static Patch<String> diffInline(String original, String revised)
      Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of characters, like DiffRowGenerator does and merges those changes at the end together again.
      Parameters:
      original -
      revised -
      Returns:
    • compressLines

      private static List<String> compressLines(List<String> lines, String delimiter)
    • patch

      public static <T> List<T> patch(List<T> original, Patch<T> 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 <T> List<T> unpatch(List<T> revised, Patch<T> patch)
      Unpatch the revised text for a given patch
      Parameters:
      revised - the revised text
      patch - the given patch
      Returns:
      the original text