Package com.day.util.diff
Class DocumentDiff
- java.lang.Object
-
- com.day.util.diff.DocumentDiff
-
public class DocumentDiff extends java.lang.Object
The document diff is used to create a diff between 2 documents. It provides 2 possibilites to use the differences: either using theChangeListener
which is called for each line of the document, or using theHunk
s that form the differences of this diff.
-
-
Constructor Summary
Constructors Constructor Description DocumentDiff(Document left, Document right)
Create a new diff from the given 2 documents
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Hunk
getHunks()
Returns the linked list of hunksElementsFactory
getMergedLeft()
Returns an element factory that provides the elements of the merged result of this diff where the left document is dominant.ElementsFactory
getMergedRight()
Returns an element factory that provides the elements of the merged result of this diff where the right document is dominant.int
getNumDeltaElements()
Returns the number of changed elements.void
showChanges(ChangeListener listener, int numContextLines)
Iterate over all changes and invoke the respective methods in the given listener.void
write(DiffWriter out, int numContextLines)
Writes the differences to the given writer in a unified diff format.void
write(java.io.Writer out, int numContextLines)
Same aswrite(DiffWriter, int)
but wraps the given writer with a default diff writer.void
write(java.lang.StringBuffer buf, int numContextLines)
Same aswrite(Writer, int)
but to a string buffer.void
write(java.lang.StringBuffer buf, java.lang.String lineSeparator, int numContextLines)
Same aswrite(DiffWriter, int)
but to a string buffer.
-
-
-
Method Detail
-
getNumDeltaElements
public int getNumDeltaElements()
Returns the number of changed elements. each insertion and each deletion counts as 1 change. if elements were modified the greate change is counted. eg: if you change 'foo' to 'bar' this is actually 1 deletion and 1 insertion but counts as 1 change. if you change 'foo\nbar\n' to 'hello' this counts as 2 changes since this includes 2 deletions.- Returns:
- the number of changed elements.
-
getHunks
public Hunk getHunks()
Returns the linked list of hunks- Returns:
- the hunks.
-
write
public void write(java.lang.StringBuffer buf, int numContextLines)
Same aswrite(Writer, int)
but to a string buffer.- Parameters:
buf
- the buffernumContextLines
- the number of context lines.
-
write
public void write(java.lang.StringBuffer buf, java.lang.String lineSeparator, int numContextLines)
Same aswrite(DiffWriter, int)
but to a string buffer.- Parameters:
buf
- the bufferlineSeparator
- the line separator to usenumContextLines
- the number of context lines.
-
write
public void write(java.io.Writer out, int numContextLines) throws java.io.IOException
Same aswrite(DiffWriter, int)
but wraps the given writer with a default diff writer.- Parameters:
out
- the writernumContextLines
- the number of context lines.- Throws:
java.io.IOException
- if an I/O error occurs
-
write
public void write(DiffWriter out, int numContextLines) throws java.io.IOException
Writes the differences to the given writer in a unified diff format. the context lines specify how many unmodified lines should sourround the actual difference.- Parameters:
out
- the writernumContextLines
- the number of context lines.- Throws:
java.io.IOException
- if an I/O error occurs
-
showChanges
public void showChanges(ChangeListener listener, int numContextLines)
Iterate over all changes and invoke the respective methods in the given listener. the context lines specify how many unmodified lines should sourround the respective change.- Parameters:
listener
- the change listenernumContextLines
- the number of context lines
-
getMergedLeft
public ElementsFactory getMergedLeft()
Returns an element factory that provides the elements of the merged result of this diff where the left document is dominant.- Returns:
- the merged elements.
-
getMergedRight
public ElementsFactory getMergedRight()
Returns an element factory that provides the elements of the merged result of this diff where the right document is dominant.- Returns:
- the merged elements.
-
-