JLibDiff
Class diff

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

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

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(), Serialized Form

Field Summary
(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(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.
 
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.
 void diffString(java.lang.String s1, java.lang.String s2)
          Compares two strings and updates the vector of Hunks.
 java.util.Vector getHunk()
          Returns a vector containing Hunks.
private static java.util.Vector getHunk(edit start, char[] A, char[] B, java.lang.String sEOL)
           
private static java.util.Vector getHunk(edit start, java.lang.String[] A, java.lang.String[] B, java.lang.String sEOL)
           
 Hunk hunkAt(int i)
          Return the hunk at the specified index.
 int numberOfHunk()
          Returns the number of hunks in the vector.
 void print()
          Print Hunks with normal format.
 
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
Constructor Detail

diff

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


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.
Method Detail

getHunk

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


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

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

diffString

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

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

getHunk

private static java.util.Vector getHunk(edit start,
                                        java.lang.String[] A,
                                        java.lang.String[] B,
                                        java.lang.String sEOL)
                                 throws java.io.IOException
java.io.IOException

getHunk

private static java.util.Vector getHunk(edit start,
                                        char[] A,
                                        char[] B,
                                        java.lang.String sEOL)
                                 throws java.io.IOException
java.io.IOException

print

public void print()
Print Hunks with normal format.



Copyright 2003 Soucejammer project.