ie.tomallen.utils
Class Diff

java.lang.Object
  |
  +--ie.tomallen.utils.Diff

public class Diff
extends java.lang.Object

Diff replicates the GNU diff command. Takes in two arrays of strings and output the to s string the same of output from the diff command without using files.

Version:
0.1
Author:
Tom Allen (based on code by Stuart D. Gathman)

Nested Class Summary
static class Diff.change
          The result of comparison is an "edit script": a chain of change objects.
 
Field Summary
 boolean heuristic
          When set to true, the comparison uses a heuristic to speed it up.
protected  ie.tomallen.utils.Diff.UnaryPredicate ignore
          Set to ignore certain kinds of lines when printing an edit script.
 boolean no_discards
          When set to true, the algorithm returns a guarranteed minimal set of changes.
 
Constructor Summary
Diff(java.lang.Object[] a, java.lang.Object[] b)
          Diff, the object constructor.
Diff(java.lang.String strA, java.lang.String strB)
          Diff, String constructor.
 
Method Summary
 Diff.change diff_2()
          Report the differences of two files.
 java.lang.String print_script(Diff.change script)
          print_script, Implementation Divide SCRIPT into pieces by calling HUNKFUN and print each piece with PRINTFUN.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

heuristic

public boolean heuristic
When set to true, the comparison uses a heuristic to speed it up. With this heuristic, for files with a constant small density of changes, the algorithm is linear in the file size.


no_discards

public boolean no_discards
When set to true, the algorithm returns a guarranteed minimal set of changes. This makes things slower, sometimes much slower.


ignore

protected ie.tomallen.utils.Diff.UnaryPredicate ignore
Set to ignore certain kinds of lines when printing an edit script. For example, ignoring blank lines or comments.

Constructor Detail

Diff

public Diff(java.lang.Object[] a,
            java.lang.Object[] b)
Diff, the object constructor. Prepare to find differences between two arrays. Each element of the arrays is translated to an "equivalence number" based on the result of equals. The original Object arrays are no longer needed for computing the differences. They will be needed again later to print the results of the comparison as an edit script, if desired.

Parameters:
a - Array of object to be compared against b
b - Array of object to be compared against a

Diff

public Diff(java.lang.String strA,
            java.lang.String strB)
Diff, String constructor. Prepare to find differences between two String. Each line of the string is translated to an "equivalence number" based on the result of equals. The original Object arrays are no longer needed for computing the differences. They will be needed again later to print the results of the comparison as an edit script, if desired.

Parameters:
strA - String to be compared against b
strB - String to be compared against a
Method Detail

diff_2

public Diff.change diff_2()
Report the differences of two files. DEPTH is the current directory depth.

Returns:
change comment

print_script

public java.lang.String print_script(Diff.change script)
print_script, Implementation Divide SCRIPT into pieces by calling HUNKFUN and print each piece with PRINTFUN. Both functions take one arg, an edit script. PRINTFUN takes a subscript which belongs together (with a null link at the end) and prints it.

Parameters:
script - Diff.change
Returns:
String the output of the diff