Class DocumentDiff

java.lang.Object
com.day.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 the ChangeListener which is called for each line of the document, or using the Hunks that form the differences of this diff.
  • Constructor Details

    • DocumentDiff

      public DocumentDiff(Document left, Document right)
      Create a new diff from the given 2 documents
      Parameters:
      left - the left document
      right - 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

      public Hunk getHunks()
      Returns the linked list of hunks
      Returns:
      the hunks.
    • write

      public void write(StringBuffer buf, int numContextLines)
      Same as write(Writer, int) but to a string buffer.
      Parameters:
      buf - the buffer
      numContextLines - the number of context lines.
    • write

      public void write(StringBuffer buf, String lineSeparator, int numContextLines)
      Same as write(DiffWriter, int) but to a string buffer.
      Parameters:
      buf - the buffer
      lineSeparator - the line separator to use
      numContextLines - the number of context lines.
    • write

      public void write(Writer out, int numContextLines) throws IOException
      Same as write(DiffWriter, int) but wraps the given writer with a default diff writer.
      Parameters:
      out - the writer
      numContextLines - 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 writer
      numContextLines - 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 listener
      numContextLines - 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.