JLibDiff
Class diff

java.lang.Object
  |
  +--JLibDiff.diff
All Implemented Interfaces:
define, HunkVisitable

public class diff
extends java.lang.Object
implements define, HunkVisitable

The diff class compares two files. it compares also two BufferedReaders or two strings. after the comparison the vector will represents a list of hunk corresponding with blocks of difference.

to generate a file of difference, one can instanciate as follows the class diff:

     diff d = new diff(file1,file2);
 

which is equivalent to:

     diff d = new diff();
     d.diffFile(file1,file2);
 

To compare two BufferedReaders or two String we have to instanciate as follows:

     diff d = new diff();
     d.diffBuffer(BufferedReader1,BufferedReader2);
 

or:

     diff d = new diff();
     d.diffString(String1,String2);
 

The class diff includes methods for examining, printing or saveing blocks of difference: (Hunks). Here are some more examples of how diff can be used:

	diff d=new diff(args[0],args[1]);
	d.print();
     d.save("diff.txt");
 

Example using BufferedReader and ED_format:

	BufferedReader in=new BufferedReader(new FileReader(args[0]));
	BufferedReader inn=new BufferedReader(new FileReader(args[1]));
	diff d = new diff();
	d.diffBuffer(in,inn);
	d.print_ED();
	d.save_ED("diff.txt");
 

To go throw the list of Hunks we can choose between an Enumeration or a loop by spesifyng index in the vector to get at each time the corresponding Hunk.

     Vector v=d.getHunk();
     for(Enumeration e=v.element();e.hasMoreElements(); )
       {
         System.out.print(((Hunk)e.nextElement()).convert());
       }
 

or:

     diff d = new diff(file1,file2);
     for(int i=0; i

See Also:
diff.diff#getHunk(), diff.diff#hunkAt(), diff.diff#numberOfHunk(), diff.diff#print(), diff.diff#print_ED(), diff.diff#print_RCS(), diff.diff#save(), diff.diff#save_ED(), diff.diff#save_RCS()

Field Summary
private  java.lang.String diffAlgorithmClass
           
private  java.lang.String msEndOfLine
           
(package private)  java.lang.String msEOL
           
(package private)  java.util.Vector v
           
 
Fields inherited from interface JLibDiff.define
DELETE, INSERT, MAXLINES, ORIGIN
 
Constructor Summary
diff()
          Allocates a new diff containing no Hunks.
diff(diff d)
           
diff(java.lang.String s1, java.lang.String s2)
          Allocates a new diff which contains Hunks corresponding to the difference between the two files passed in arguments.
diff(java.lang.String s1, java.lang.String s2, java.lang.String algorithmClass)
          Allocates a new diff which contains Hunks corresponding to the difference between the two files passed in arguments.
diff(java.util.Vector v)
           
 
Method Summary
 void accept(HunkVisitor visitor)
          Accept a visitor in order to visit the collection of hunks.
 void diffBuffer(java.io.BufferedReader in, java.io.BufferedReader inn)
          Compares two BufferedReaders and updates the vector of Hunks.
 void diffFile(java.lang.String s1, java.lang.String s2)
          Compares two files and updates the vector of Hunks.
protected  DiffAlgorithm getDiffAlgorithmClass()
           
 java.util.Vector getHunk()
          Returns a vector containing Hunks.
private  java.lang.Object[] getLines(int firstLine, int numLines, java.lang.Object[] parent)
           
 java.util.Vector getUnderlyingVector()
           
 Hunk hunkAt(int i)
          Return the hunk at the specified index.
protected  void makeDiff(java.lang.String[] A, java.lang.String[] B)
           
 int numberOfHunk()
          Returns the number of hunks in the vector.
 void print()
          Print Hunks with normal format.
 void setDiffAlgorithmClass(java.lang.String diffAlgorithmClass)
          Sets the diffAlgorithmClass.
 void supressEndOfLine()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

v

java.util.Vector v

msEOL

java.lang.String msEOL

msEndOfLine

private java.lang.String msEndOfLine

diffAlgorithmClass

private java.lang.String diffAlgorithmClass
Constructor Detail

diff

public diff()
Allocates a new diff containing no Hunks.


diff

public diff(diff d)

diff

public diff(java.util.Vector v)

diff

public diff(java.lang.String s1,
            java.lang.String s2)
     throws java.io.IOException
Allocates a new diff which contains Hunks corresponding to the difference between the two files passed in arguments.

Parameters:
s1 - first file to compare.
s2 - second file to compare.

diff

public diff(java.lang.String s1,
            java.lang.String s2,
            java.lang.String algorithmClass)
     throws java.io.IOException
Allocates a new diff which contains Hunks corresponding to the difference between the two files passed in arguments.

Parameters:
s1 - first file to compare.
s2 - second file to compare.
Method Detail

supressEndOfLine

public void supressEndOfLine()

getHunk

public java.util.Vector getHunk()
Returns a vector containing Hunks.


getUnderlyingVector

public java.util.Vector getUnderlyingVector()

numberOfHunk

public int numberOfHunk()
Returns the number of hunks in the vector.


hunkAt

public Hunk hunkAt(int i)
Return the hunk at the specified index.

Parameters:
i - index of the hunk that will be returned.

accept

public void accept(HunkVisitor visitor)
Accept a visitor in order to visit the collection of hunks.

Specified by:
accept in interface HunkVisitable
Parameters:
visitor - the HunkVisitor.

diffFile

public void diffFile(java.lang.String s1,
                     java.lang.String s2)
              throws java.io.IOException
Compares two files and updates the vector of Hunks.

Parameters:
s1 - first file to compare.
s2 - second file to compare.
java.io.IOException

getLines

private java.lang.Object[] getLines(int firstLine,
                                    int numLines,
                                    java.lang.Object[] parent)

diffBuffer

public void diffBuffer(java.io.BufferedReader in,
                       java.io.BufferedReader inn)
                throws java.io.IOException
Compares two BufferedReaders and updates the vector of Hunks.

Parameters:
in - first BufferedReader to compare.
inn - second BufferedReader to compare.
java.io.IOException

getDiffAlgorithmClass

protected DiffAlgorithm getDiffAlgorithmClass()
                                       throws java.lang.IllegalAccessException,
                                              java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.InstantiationException

makeDiff

protected void makeDiff(java.lang.String[] A,
                        java.lang.String[] B)

print

public void print()
Print Hunks with normal format.


setDiffAlgorithmClass

public void setDiffAlgorithmClass(java.lang.String diffAlgorithmClass)
Sets the diffAlgorithmClass.

Parameters:
diffAlgorithmClass - The diffAlgorithmClass to set


Copyright 2003 Soucejammer project.