Class MyersDiff<T>

  • All Implemented Interfaces:
    DiffAlgorithmI<T>

    public final class MyersDiff<T>
    extends java.lang.Object
    implements DiffAlgorithmI<T>
    A clean-room implementation of Eugene Myers greedy differencing algorithm.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.BiPredicate<T,​T> DEFAULT_EQUALIZER  
      private java.util.function.BiPredicate<T,​T> equalizer  
    • Constructor Summary

      Constructors 
      Constructor Description
      MyersDiff()  
      MyersDiff​(java.util.function.BiPredicate<T,​T> equalizer)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private PathNode buildPath​(java.util.List<T> orig, java.util.List<T> rev, DiffAlgorithmListener progress)
      Computes the minimum diffpath that expresses de differences between the original and revised sequences, according to Gene Myers differencing algorithm.
      private java.util.List<Change> buildRevision​(PathNode actualPath, java.util.List<T> orig, java.util.List<T> rev)
      Constructs a Patch from a difference path.
      java.util.List<Change> computeDiff​(java.util.List<T> source, java.util.List<T> target, DiffAlgorithmListener progress)
      Computes the changeset to patch the source list to the target list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_EQUALIZER

        private final java.util.function.BiPredicate<T,​T> DEFAULT_EQUALIZER
      • equalizer

        private final java.util.function.BiPredicate<T,​T> equalizer
    • Constructor Detail

      • MyersDiff

        public MyersDiff()
      • MyersDiff

        public MyersDiff​(java.util.function.BiPredicate<T,​T> equalizer)
    • Method Detail

      • computeDiff

        public java.util.List<Change> computeDiff​(java.util.List<T> source,
                                                  java.util.List<T> target,
                                                  DiffAlgorithmListener progress)
        Computes the changeset to patch the source list to the target list. Return empty diff if get the error while procession the difference.
        Specified by:
        computeDiff in interface DiffAlgorithmI<T>
        Parameters:
        source - source data
        target - target data
        progress - progress listener
        Returns:
      • buildPath

        private PathNode buildPath​(java.util.List<T> orig,
                                   java.util.List<T> rev,
                                   DiffAlgorithmListener progress)
        Computes the minimum diffpath that expresses de differences between the original and revised sequences, according to Gene Myers differencing algorithm.
        Parameters:
        orig - The original sequence.
        rev - The revised sequence.
        Returns:
        A minimum Path accross the differences graph.
        Throws:
        DifferentiationFailedException - if a diff path could not be found.
      • buildRevision

        private java.util.List<Change> buildRevision​(PathNode actualPath,
                                                     java.util.List<T> orig,
                                                     java.util.List<T> rev)
        Constructs a Patch from a difference path.
        Parameters:
        actualPath - The path.
        orig - The original sequence.
        rev - The revised sequence.
        Returns:
        A Patch script corresponding to the path.
        Throws:
        DifferentiationFailedException - if a Patch could not be built from the given path.