Class Hunk


  • public class Hunk
    extends java.lang.Object
    A hunk records a block of diff between the left and the right document. it represents either a insertion, deletion, change or identity. several hunks are chained in a linked list.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CHANGED
      type indicates a changed block
      static int DELETED
      type indicates a deleted block
      static int INSERTED
      type indicates an inserted block
      Range left
      the range in the left document
      Range right
      the rnage in the right document
      int type
      the hunk type
      static int UNMODIFIED
      type indicates an unmodified block
    • Constructor Summary

      Constructors 
      Constructor Description
      Hunk​(Range left, Range right, int type, Hunk prev)
      Creates a new hunk and adds it to the previous hunk
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Hunk next()
      Returns the next hunk of this chain
      Hunk prev()
      Returns the previous hunk of this chain
      Hunk write​(DiffWriter out, int numContextLines)
      Writes a unified diff to the given writer and returns the next hunk to continue the output.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UNMODIFIED

        public static final int UNMODIFIED
        type indicates an unmodified block
        See Also:
        Constant Field Values
      • INSERTED

        public static final int INSERTED
        type indicates an inserted block
        See Also:
        Constant Field Values
      • DELETED

        public static final int DELETED
        type indicates a deleted block
        See Also:
        Constant Field Values
      • CHANGED

        public static final int CHANGED
        type indicates a changed block
        See Also:
        Constant Field Values
      • left

        public final Range left
        the range in the left document
      • right

        public final Range right
        the rnage in the right document
      • type

        public final int type
        the hunk type
    • Constructor Detail

      • Hunk

        public Hunk​(Range left,
                    Range right,
                    int type,
                    Hunk prev)
        Creates a new hunk and adds it to the previous hunk
        Parameters:
        left - the left range
        right - the right range
        type - the hunk type
        prev - the previous hunk
    • Method Detail

      • prev

        public Hunk prev()
        Returns the previous hunk of this chain
        Returns:
        the previous hunk.
      • next

        public Hunk next()
        Returns the next hunk of this chain
        Returns:
        the next hunk.
      • write

        public Hunk write​(DiffWriter out,
                          int numContextLines)
                   throws java.io.IOException
        Writes a unified diff to the given writer and returns the next hunk to continue the output.
        Parameters:
        out - the writer
        numContextLines - the number of context lines to include in the diff blocks. do not change during iteration!
        Returns:
        the next hunk or null.
        Throws:
        java.io.IOException - if an I/O error occurs.