Class DiffUtils


  • public final class DiffUtils
    extends java.lang.Object
    Implements the difference and patching engine
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DiffUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.List<java.lang.String> compressLines​(java.util.List<java.lang.String> lines, java.lang.String delimiter)  
      static Patch<java.lang.String> diff​(java.lang.String sourceText, java.lang.String targetText, DiffAlgorithmListener progress)
      Computes the difference between the original and revised text.
      static <T> Patch<T> diff​(java.util.List<T> original, java.util.List<T> revised)  
      static <T> Patch<T> diff​(java.util.List<T> original, java.util.List<T> revised, boolean includeEqualParts)  
      static <T> Patch<T> diff​(java.util.List<T> original, java.util.List<T> revised, DiffAlgorithmI<T> algorithm)
      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, DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress)  
      static <T> Patch<T> diff​(java.util.List<T> original, java.util.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
      static <T> Patch<T> diff​(java.util.List<T> original, java.util.List<T> revised, DiffAlgorithmListener progress)
      Computes the difference between the original and revised list of elements with default diff algorithm
      static <T> Patch<T> diff​(java.util.List<T> source, java.util.List<T> target, java.util.function.BiPredicate<T,​T> equalizer)
      Computes the difference between the original and revised list of elements with default diff algorithm
      static Patch<java.lang.String> diffInline​(java.lang.String original, java.lang.String revised)
      Computes the difference between the given texts inline.
      static <T> java.util.List<T> patch​(java.util.List<T> original, Patch<T> patch)
      Patch the original text with given patch
      static <T> java.util.List<T> unpatch​(java.util.List<T> revised, Patch<T> 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

        private DiffUtils()
    • Method Detail

      • diff

        public static <T> Patch<T> diff​(java.util.List<T> original,
                                        java.util.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​(java.util.List<T> original,
                                        java.util.List<T> revised)
      • diff

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

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

        public static <T> Patch<T> diff​(java.util.List<T> source,
                                        java.util.List<T> target,
                                        java.util.function.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​(java.util.List<T> original,
                                        java.util.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​(java.util.List<T> original,
                                        java.util.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<java.lang.String> diffInline​(java.lang.String original,
                                                         java.lang.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 java.util.List<java.lang.String> compressLines​(java.util.List<java.lang.String> lines,
                                                                      java.lang.String delimiter)
      • patch

        public static <T> java.util.List<T> patch​(java.util.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> java.util.List<T> unpatch​(java.util.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