Class Hunk

java.lang.Object
com.day.util.diff.Hunk

public class Hunk extends 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 final int
    type indicates a changed block
    static final int
    type indicates a deleted block
    static final int
    type indicates an inserted block
    final Range
    the range in the left document
    final Range
    the rnage in the right document
    final int
    the hunk type
    static final int
    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

    Modifier and Type
    Method
    Description
    Returns the next hunk of this chain
    Returns the previous hunk of this chain
    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 Details

    • UNMODIFIED

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

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

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

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

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

      public final int type
      the hunk type
  • Constructor Details

    • 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 Details

    • 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 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:
      IOException - if an I/O error occurs.