Class MyersDiff<T>

java.lang.Object
org.assertj.core.util.diff.myers.MyersDiff<T>
Type Parameters:
T - The type of the compared elements in the 'lines'.
All Implemented Interfaces:
DiffAlgorithm<T>

public class MyersDiff<T> extends Object implements DiffAlgorithm<T>
Copy from https://code.google.com/p/java-diff-utils/.

A clean-room implementation of Eugene Myers differencing algorithm.

See the paper at http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps

Author:
Juanco Anez
  • Constructor Details

    • MyersDiff

      public MyersDiff()
      Constructs an instance of the Myers differencing algorithm.
  • Method Details

    • diff

      public Patch<T> diff(List<T> original, List<T> revised)
      Computes the difference between the original sequence and the revised sequence and returns it as a Patch object. Return empty diff if get the error while procession the difference.
      Specified by:
      diff in interface DiffAlgorithm<T>
      Parameters:
      original - The original sequence. Must not be null.
      revised - The revised sequence. Must not be null.
      Returns:
      The patch representing the diff of the given sequences. Never null.
    • buildPath

      public PathNode buildPath(List<T> orig, List<T> rev)
      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 across the differences graph.
      Throws:
      IllegalStateException - if a diff path could not be found.
    • buildRevision

      public Patch<T> buildRevision(PathNode path, List<T> orig, List<T> rev)
      Constructs a Patch from a difference path.
      Parameters:
      path - The path.
      orig - The original sequence.
      rev - The revised sequence.
      Returns:
      A Patch script corresponding to the path.