Class MyersDiff<T>

java.lang.Object
com.github.difflib.algorithm.myers.MyersDiff<T>
All Implemented Interfaces:
DiffAlgorithmI<T>

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

    • equalizer

      private final BiPredicate<? super T, ? super T> equalizer
  • Constructor Details

    • MyersDiff

      public MyersDiff()
    • MyersDiff

      public MyersDiff(BiPredicate<? super T, ? super T> equalizer)
  • Method Details

    • computeDiff

      public List<Change> computeDiff(List<? extends T> source, List<? extends 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(List<? extends T> orig, List<? extends 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:
      IllegalStateException - if a diff path could not be found.
    • buildRevision

      private List<Change> buildRevision(PathNode actualPath, List<? extends T> orig, List<? extends 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:
      IllegalStateException - if a Patch could not be built from the given path.
    • factory

      public static DiffAlgorithmFactory factory()
      Factory to create instances of this specific diff algorithm.