JLibDiff
Class diff3

java.lang.Object
  |
  +--JLibDiff.diff3
All Implemented Interfaces:
Hunk3Visitable

public class diff3
extends java.lang.Object
implements Hunk3Visitable

The diff3 class compares three files or three BufferedReaders. after comparison, the vector will represente a list of Hunk3 corresponding with blocks of difference.

to generate Hunk3, one can instanciate as follows the class diff3:

     diff3 d = new diff3(file1,file2,file3);
 

which is equivalent to:

     diff3 d = new diff3();
     d.diffFile(file1,file2,file3);
 

To compaire three BufferedReader we have to instanciate as follows:

     diff3 d = new diff3();
     d.diffBuffer(BufferedReader1,BufferedReader2,BufferedReader3);
 

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

	diff3 d = new diff3(file1,file2,file3);
	d.print();
     d.save("diff.txt");
 

Example using BufferedReader and ED_format:

 
	BufferedReader in0=new BufferedReader(new FileReader(file1));
	BufferedReader in1=new BufferedReader(new FileReader(file2));
     BufferedReader in2=new BufferedReader(new FileReader(file3)); 
	diff3 d = new diff3();
	d.diffBuffer(in0,in1,in2);
	d.print_ED();
	d.save_ED("diff.txt");
 

See Also:
diff.diff3#getHunk3(), diff.diff3#hunk3At(), diff.diff3#numberOfHunk3(), diff.diff3#print(), diff.diff3#save()

Nested Class Summary
private  class diff3.OverLapBuildResult
           
private  class diff3.OverlapIndexes
           
private  class diff3.OverlapTestResult
           
private  class diff3.Range
           
 
Field Summary
private  TextLineReader2 reader0
           
private  TextLineReader2 reader1
           
(package private)  java.util.Vector v
           
 
Constructor Summary
diff3()
          Allocates a new diff3 containing no Hunks.
diff3(java.lang.String s0, java.lang.String s1, java.lang.String s2)
          Allocates a new diff3 which contains Hunk3 corresponding to the differences between the three files passed in arguments.
 
Method Summary
 void accept(Hunk3Visitor visitor)
           
private  int addSingleFileChangeHunks(java.util.Vector buildDiff3, java.util.Vector singleFile, java.util.Vector v12, int startIndex, int endIndex, int diff12Index, DiffType type)
           
private  boolean areHunksEquivelent(Hunk h1, Hunk h2)
           
private  boolean areHunksEquivelent(Hunk h1, Hunk h2, int fileNum)
           
private  boolean areRangesEqual(TextLineReader2 reader1, int startLine1, int endLine1, TextLineReader2 reader2, int startLine2, int endLine2)
           
private  boolean areRangesSame(int start0, int end0, int start1, int end1)
           
private  java.util.Vector buildDiff3(java.util.Vector v01, java.util.Vector v02, java.util.Vector v12)
           
private  diff3.OverLapBuildResult buildOverLapHunk(java.util.Vector v01, java.util.Vector v02, java.util.Vector v12, int index01, int index02, int diff12Index)
           
 void diffFile(java.lang.String s0, java.lang.String s1, java.lang.String s2)
          Compaires three files and updates the vector of Hunk3.
private  boolean doHunkRangesMatch(Hunk h1, Hunk h2)
          Returns true if both hunks point to the exact same regions file 0.
private  boolean doHunksMatch(Hunk h1, Hunk h2)
          Returns true if both hunks reflect the exact same change to both files.
private  boolean doHunksOverlap(Hunk h1, Hunk h2)
           
private  diff3.OverlapTestResult findOverlapIndex(Hunk hunk, java.util.Vector diffVector, int startIndex)
           
private  diff3.OverlapIndexes getEndOfOverlap(java.util.Vector v01, java.util.Vector v02, int index01, int index02)
           
 TextLineReader2 getFile0Lines()
           
 java.util.Vector getHunk3()
          Returns a vector containing Hunk3.
private  java.util.Vector getHunk3(java.util.Vector v0, java.util.Vector v1)
           
private  boolean hunk1HasHighest0(Hunk h1, Hunk h2)
           
private  boolean hunk1HasLowest0(Hunk h1, Hunk h2)
           
 Hunk3 hunk3At(int i)
          Return the hunk3 at the specified index.
private  boolean isHunkOneBeforeHunkTwo(Hunk h1, Hunk h2)
          Returns true if Hunk 1 refers to a region of file 0 entirely before the region reference by hunk 2.
private  boolean isNumWithinRange(int num, int startRange, int endRange)
           
 int numberOfHunk3()
          Returns the number of hunk3 in the vector.
 void print()
          Print Hunk3 with normal format.
private  void processHunks(java.util.Vector vec, java.lang.String file0, java.lang.String file1, java.lang.String file2)
           
private  java.util.ArrayList rangeToArrayList(TextLineReader2 reader, int startLine, int endLine)
           
 void save(java.lang.String file)
          Save Hunk3 with normal format at the specified file.
private  Hunk3 using_to_diff3_block(Hunk[] using, Hunk[] last_using, int low_thread, int high_thread, Hunk3 last_diff3)
           
 
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

reader0

private TextLineReader2 reader0

reader1

private TextLineReader2 reader1
Constructor Detail

diff3

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


diff3

public diff3(java.lang.String s0,
             java.lang.String s1,
             java.lang.String s2)
      throws java.io.IOException
Allocates a new diff3 which contains Hunk3 corresponding to the differences between the three files passed in arguments.

Parameters:
s0 - first file.
s1 - second file.
s2 - therd file.
Method Detail

getFile0Lines

public TextLineReader2 getFile0Lines()

diffFile

public void diffFile(java.lang.String s0,
                     java.lang.String s1,
                     java.lang.String s2)
              throws java.io.IOException
Compaires three files and updates the vector of Hunk3.

Parameters:
s0 - first file.
s1 - second file.
s2 - therd file.
java.io.IOException

processHunks

private void processHunks(java.util.Vector vec,
                          java.lang.String file0,
                          java.lang.String file1,
                          java.lang.String file2)
                   throws java.io.IOException
java.io.IOException

areRangesEqual

private boolean areRangesEqual(TextLineReader2 reader1,
                               int startLine1,
                               int endLine1,
                               TextLineReader2 reader2,
                               int startLine2,
                               int endLine2)

rangeToArrayList

private java.util.ArrayList rangeToArrayList(TextLineReader2 reader,
                                             int startLine,
                                             int endLine)

addSingleFileChangeHunks

private int addSingleFileChangeHunks(java.util.Vector buildDiff3,
                                     java.util.Vector singleFile,
                                     java.util.Vector v12,
                                     int startIndex,
                                     int endIndex,
                                     int diff12Index,
                                     DiffType type)

buildDiff3

private java.util.Vector buildDiff3(java.util.Vector v01,
                                    java.util.Vector v02,
                                    java.util.Vector v12)

buildOverLapHunk

private diff3.OverLapBuildResult buildOverLapHunk(java.util.Vector v01,
                                                  java.util.Vector v02,
                                                  java.util.Vector v12,
                                                  int index01,
                                                  int index02,
                                                  int diff12Index)

hunk1HasLowest0

private boolean hunk1HasLowest0(Hunk h1,
                                Hunk h2)

hunk1HasHighest0

private boolean hunk1HasHighest0(Hunk h1,
                                 Hunk h2)

getEndOfOverlap

private diff3.OverlapIndexes getEndOfOverlap(java.util.Vector v01,
                                             java.util.Vector v02,
                                             int index01,
                                             int index02)

findOverlapIndex

private diff3.OverlapTestResult findOverlapIndex(Hunk hunk,
                                                 java.util.Vector diffVector,
                                                 int startIndex)

isHunkOneBeforeHunkTwo

private boolean isHunkOneBeforeHunkTwo(Hunk h1,
                                       Hunk h2)
Returns true if Hunk 1 refers to a region of file 0 entirely before the region reference by hunk 2.


doHunksMatch

private boolean doHunksMatch(Hunk h1,
                             Hunk h2)
Returns true if both hunks reflect the exact same change to both files.


doHunkRangesMatch

private boolean doHunkRangesMatch(Hunk h1,
                                  Hunk h2)
Returns true if both hunks point to the exact same regions file 0.


doHunksOverlap

private boolean doHunksOverlap(Hunk h1,
                               Hunk h2)

isNumWithinRange

private boolean isNumWithinRange(int num,
                                 int startRange,
                                 int endRange)

getHunk3

private java.util.Vector getHunk3(java.util.Vector v0,
                                  java.util.Vector v1)

using_to_diff3_block

private Hunk3 using_to_diff3_block(Hunk[] using,
                                   Hunk[] last_using,
                                   int low_thread,
                                   int high_thread,
                                   Hunk3 last_diff3)

areRangesSame

private boolean areRangesSame(int start0,
                              int end0,
                              int start1,
                              int end1)

areHunksEquivelent

private boolean areHunksEquivelent(Hunk h1,
                                   Hunk h2)

areHunksEquivelent

private boolean areHunksEquivelent(Hunk h1,
                                   Hunk h2,
                                   int fileNum)

getHunk3

public java.util.Vector getHunk3()
Returns a vector containing Hunk3.


hunk3At

public Hunk3 hunk3At(int i)
Return the hunk3 at the specified index.

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

numberOfHunk3

public int numberOfHunk3()
Returns the number of hunk3 in the vector.


print

public void print()
Print Hunk3 with normal format.


save

public void save(java.lang.String file)
          throws java.io.IOException
Save Hunk3 with normal format at the specified file.

Parameters:
file - file in which Hunks will be saved.
java.io.IOException

accept

public void accept(Hunk3Visitor visitor)
Specified by:
accept in interface Hunk3Visitable


Copyright © 2003 Soucejammer project.