Class DocumentDiff
- java.lang.Object
-
- org.apache.jackrabbit.vault.util.diff.DocumentDiff
-
public class DocumentDiff extends 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(Writer out, int numContextLines)
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.void
write(DiffWriter out, int numContextLines)
Writes the differences to the given writer in a unified diff format.
-
-
-
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(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(StringBuffer buf, 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(Writer out, int numContextLines) throws 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:
IOException
- if an I/O error occurs
-
write
public void write(DiffWriter out, int numContextLines) throws 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:
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.
-
-