difflib.myers
Class MyersDiff<T>

java.lang.Object
  extended by difflib.myers.MyersDiff<T>
All Implemented Interfaces:
DiffAlgorithm<T>

public class MyersDiff<T>
extends Object
implements DiffAlgorithm<T>

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 Summary
MyersDiff()
          Constructs an instance of the Myers differencing algorithm.
MyersDiff(Equalizer<T> equalizer)
          Constructs an instance of the Myers differencing algorithm.
 
Method Summary
 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.
 Patch<T> buildRevision(PathNode path, List<T> orig, List<T> rev)
          Constructs a Patch from a difference path.
static
<T> T[]
copyOfRange2(T[] original, int from, int to)
          Copied here from JDK 1.6
static
<T,U> T[]
copyOfRange2(U[] original, int from, int to, Class<? extends T[]> newType)
          Copied here from JDK 1.6
 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.
 Patch<T> diff(T[] original, T[] revised)
          Computes the difference between the original sequence and the revised sequence and returns it as a Patch object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyersDiff

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


MyersDiff

public MyersDiff(Equalizer<T> equalizer)
Constructs an instance of the Myers differencing algorithm.

Parameters:
equalizer - Must not be null.
Method Detail

diff

public Patch<T> diff(T[] original,
                     T[] revised)
Computes the difference between the original sequence and the revised sequence and returns it as a Patch object.

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:
Returns an empty diff if get the error while procession the difference.

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)
                   throws DifferentiationFailedException
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

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.
Throws:
DifferentiationFailedException - if a Patch could not be built from the given path.

copyOfRange2

public static <T> T[] copyOfRange2(T[] original,
                                   int from,
                                   int to)
Copied here from JDK 1.6


copyOfRange2

public static <T,U> T[] copyOfRange2(U[] original,
                                     int from,
                                     int to,
                                     Class<? extends T[]> newType)
Copied here from JDK 1.6



Copyright © 2009-2013. All Rights Reserved.