|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.borland.primetime.util.Diff
The Diff class is capable of diffing two text files and producing an array of DiffEntries which represent the differences between the two files. The differences can also be expressed as an edit script with add and delete instructions similar to the "--rcs" output of the Unix diff.exe The diff algorithm is based on: An O(NP) Sequence Comparison Algorithm Sun Wu, Udi Manber, Gene Myers, Webb Miller August 1989 To use this file, first instantiate a new Diff object. A Diff object is able to do diff's between BufferedReaders Files, and String arrays, and the result of the last diff is cached in an array of DiffEntry objects. To get the result of a diff, get an iterator that can give the DiffEntry objects one by one, or call toEditScript to get an edit script. As a convenience, this class can turn an edit script into a cached array of DiffEntry objects, as long as the edit script is in the format that diff.exe uses for the --rcs output.
Inner Class Summary | |
class |
Diff.DiffEntry
A DiffEntry is used to describe a region of lines that are changed from an ORIGINAL file to a NEW file. |
Field Summary | |
protected Diff.DiffEntry[] |
delta
|
protected int |
numEntries
|
Constructor Summary | |
Diff()
The default constructor just sets up an empty object. |
Method Summary | |
void |
addAddition(int startLine,
java.lang.String[] lines)
Manually add to the cached array of DiffEntry objects. |
void |
addChange(int startLine,
java.lang.String[] lines)
Manually add to the cached array of DiffEntry objects A change means 'lines will substitute an equal number of existing lines starting at startLine. |
void |
addDeletion(int startLine,
int count)
Manually add to the cached array of DiffEntry objects. |
boolean |
diff(java.io.BufferedReader reader1,
java.io.BufferedReader reader2)
Make a diff between the two buffered inputs and cache the resulting array of DiffEntry objects. |
boolean |
diff(java.io.File file1,
java.io.File file2)
Make a diff between two files and cache the resulting array of DiffEntry objects. |
boolean |
diff(java.lang.String[] lines1,
java.lang.String[] lines2)
Make a diff between two arrays of strings and cache the resulting array of DiffEntry objects. |
boolean |
editScriptToDiff(java.util.Iterator diffFile)
Given a difference between 2 files, expressed as an edit script produced by diff.exe with the --rcs option, fill this Diff object with DifEntries that are equivalent to the edit script. |
java.util.Iterator |
iterator()
Return a new iterator that iterates through the diffEntries in a FIFO order. |
void |
reset()
Empty the current cache of DiffEntry objects, which will make the object ready for a fresh diff. |
java.util.Iterator |
reverseIterator()
Return a new iterator that iterates through the diffEntries in a FILO order. |
int |
size()
Gets the number of valid DiffEntry objects currently cached in our object. |
java.lang.String[] |
toEditScript()
Produce an "diff.exe --rcs" compatible edit script from the last diff executed. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Diff.DiffEntry[] delta
protected int numEntries
Constructor Detail |
public Diff()
Method Detail |
public int size()
public void reset()
public boolean diff(java.io.BufferedReader reader1, java.io.BufferedReader reader2)
reader1
- the first readerreader2
- the second readerpublic boolean diff(java.lang.String[] lines1, java.lang.String[] lines2)
lines1
- the first array of stringslines2
- the second array of stringspublic boolean diff(java.io.File file1, java.io.File file2)
file1
- the first filefile2
- the second filepublic void addAddition(int startLine, java.lang.String[] lines)
startLine
- The line after which we add lineslines
- The lines we will addpublic void addDeletion(int startLine, int count)
startLine
- the first line to be deletedcount
- the number of lines to deletepublic void addChange(int startLine, java.lang.String[] lines)
startLine
- the first line to be changed.lines
- the new linespublic boolean editScriptToDiff(java.util.Iterator diffFile)
diffFile
- The difference between 2 files expressed as an
iterator over an arrayList of Strings.public java.lang.String[] toEditScript()
public java.util.Iterator iterator()
public java.util.Iterator reverseIterator()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |