difflib.myers
Class MyersDiff

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

public class MyersDiff
extends Object
implements DiffAlgorithm

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.
 
Method Summary
static PathNode buildPath(Object[] orig, Object[] rev)
          Computes the minimum diffpath that expresses de differences between the original and revised sequences, according to Gene Myers differencing algorithm.
static Patch buildRevision(PathNode path, Object[] orig, Object[] rev)
          Constructs a Patch from a difference path.
static
<T> T[]
copyOfRange(T[] original, int from, int to)
          Copied here from JDK 1.6
static
<T,U> T[]
copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)
          Copied here from JDK 1.6
 Patch diff(List<?> original, List<?> revised)
          Computes the difference between the original sequence and the revised sequence and returns it as a Patch object.
 Patch diff(Object[] orig, Object[] rev)
          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.

Method Detail

diff

public Patch diff(List<?> original,
                  List<?> 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
Parameters:
original - the original text
revised - the revised text
Returns:
the patch

diff

public Patch diff(Object[] orig,
                  Object[] rev)
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
Parameters:
orig - the original text
rev - the revised text
Returns:
the patch

buildPath

public static PathNode buildPath(Object[] orig,
                                 Object[] 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 static Patch buildRevision(PathNode path,
                                  Object[] orig,
                                  Object[] 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.

copyOfRange

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


copyOfRange

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



Copyright © 2009-2011. All Rights Reserved.