Package com.day.util.diff
Class DocumentDiff
java.lang.Object
com.day.util.diff.DocumentDiff
The document diff is used to create a diff between 2 documents.
It provides 2 possibilites to use the differences: either using the
ChangeListener
which is called for each line of the document, or
using the Hunk
s that form the differences of this diff.-
Constructor Summary
ConstructorsConstructorDescriptionDocumentDiff
(Document left, Document right) Create a new diff from the given 2 documents -
Method Summary
Modifier and TypeMethodDescriptiongetHunks()
Returns the linked list of hunksReturns an element factory that provides the elements of the merged result of this diff where the left document is dominant.Returns an element factory that provides the elements of the merged result of this diff where the right document is dominant.int
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
Same aswrite(DiffWriter, int)
but wraps the given writer with a default diff writer.void
write
(StringBuffer buf, int numContextLines) Same aswrite(Writer, int)
but to a string buffer.void
write
(StringBuffer buf, String lineSeparator, int numContextLines) Same aswrite(DiffWriter, int)
but to a string buffer.
-
Constructor Details
-
DocumentDiff
Create a new diff from the given 2 documents- Parameters:
left
- the left documentright
- the right document
-
-
Method Details
-
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
Returns the linked list of hunks- Returns:
- the hunks.
-
write
Same aswrite(Writer, int)
but to a string buffer.- Parameters:
buf
- the buffernumContextLines
- the number of context lines.
-
write
Same aswrite(DiffWriter, int)
but to a string buffer.- Parameters:
buf
- the bufferlineSeparator
- the line separator to usenumContextLines
- the number of context lines.
-
write
Same aswrite(DiffWriter, int)
but wraps the given writer with a default diff writer.- Parameters:
out
- the writernumContextLines
- the number of context lines.- Throws:
IOException
- if an I/O error occurs
-
write
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:
IOException
- if an I/O error occurs
-
showChanges
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
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
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.
-