Class MyersDiff<T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Equalizer<T> equalizer
      The equalizer.
    • Constructor Summary

      Constructors 
      Constructor Description
      MyersDiff()
      Constructs an instance of the Myers differencing algorithm.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      PathNode buildPath​(java.util.List<T> orig, java.util.List<T> rev)
      Computes the minimum diffpath that expresses de differences between the original and revised sequences, according to Gene Myers differencing algorithm.
      Patch<T> buildRevision​(PathNode path, java.util.List<T> orig, java.util.List<T> rev)
      Constructs a Patch from a difference path.
      private java.util.List<T> copyOfRange​(java.util.List<T> original, int fromIndex, int to)
      Creates a new list containing the elements returned by List.subList(int, int).
      Patch<T> diff​(java.util.List<T> original, java.util.List<T> revised)
      Computes the difference between the original sequence and the revised sequence and returns it as a Patch object.
      private boolean equals​(T orig, T rev)  
      • Methods inherited from class java.lang.Object

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

      • equalizer

        private final Equalizer<T> equalizer
        The equalizer.
    • Constructor Detail

      • MyersDiff

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

      • diff

        public Patch<T> diff​(java.util.List<T> original,
                             java.util.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​(java.util.List<T> orig,
                                  java.util.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:
        java.lang.IllegalStateException - if a diff path could not be found.
      • equals

        private boolean equals​(T orig,
                               T rev)
      • buildRevision

        public Patch<T> buildRevision​(PathNode path,
                                      java.util.List<T> orig,
                                      java.util.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.
      • copyOfRange

        private java.util.List<T> copyOfRange​(java.util.List<T> original,
                                              int fromIndex,
                                              int to)
        Creates a new list containing the elements returned by List.subList(int, int).
        Parameters:
        original - The original sequence. Must not be null.
        fromIndex - low endpoint (inclusive) of the subList.
        to - high endpoint (exclusive) of the subList.
        Returns:
        A new list of the specified range within the original list.