Class MeyersDiff<T>

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

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

  • Constructor Details

    • MeyersDiff

      public MeyersDiff()
    • MeyersDiff

      public MeyersDiff(BiPredicate<T,T> equalizer)
  • Method Details

    • computeDiff

      public List<Change> computeDiff(List<T> source, 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(List<T> orig, 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 List<Change> buildRevision(PathNode actualPath, List<T> orig, 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.
    • factory

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