|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--JLibDiff.diff
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
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 |
java.util.Vector v
java.lang.String msEOL
private java.lang.String msEndOfLine
private java.lang.String diffAlgorithmClass
Constructor Detail |
public diff()
diff
containing no Hunks.
public diff(diff d)
public diff(java.util.Vector v)
public diff(java.lang.String s1, java.lang.String s2) throws java.io.IOException
diff
which contains Hunks corresponding
to the difference between the two files passed in arguments.
s1
- first file to compare.s2
- second file to compare.public diff(java.lang.String s1, java.lang.String s2, java.lang.String algorithmClass) throws java.io.IOException
diff
which contains Hunks corresponding
to the difference between the two files passed in arguments.
s1
- first file to compare.s2
- second file to compare.Method Detail |
public void supressEndOfLine()
public java.util.Vector getHunk()
public java.util.Vector getUnderlyingVector()
public int numberOfHunk()
public Hunk hunkAt(int i)
i
- index of the hunk that will be returned.public void accept(HunkVisitor visitor)
accept
in interface HunkVisitable
visitor
- the HunkVisitor.public void diffFile(java.lang.String s1, java.lang.String s2) throws java.io.IOException
s1
- first file to compare.s2
- second file to compare.
java.io.IOException
private java.lang.Object[] getLines(int firstLine, int numLines, java.lang.Object[] parent)
public void diffBuffer(java.io.BufferedReader in, java.io.BufferedReader inn) throws java.io.IOException
in
- first BufferedReader to compare.inn
- second BufferedReader to compare.
java.io.IOException
protected DiffAlgorithm getDiffAlgorithmClass() throws java.lang.IllegalAccessException, java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.InstantiationException
protected void makeDiff(java.lang.String[] A, java.lang.String[] B)
public void print()
public void setDiffAlgorithmClass(java.lang.String diffAlgorithmClass)
diffAlgorithmClass
- The diffAlgorithmClass to set
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |