Class Edit

java.lang.Object
org.eclipse.jgit.diff.Edit

public class Edit extends Object
A modified region detected between two versions of roughly the same content.

An edit covers the modified region only. It does not cover a common region.

Regions should be specified using 0 based notation, so add 1 to the start and end marks for line numbers in a file.

An edit where beginA == endA && beginB < endB is an insert edit, that is sequence B inserted the elements in region [beginB, endB) at beginA.

An edit where beginA < endA && beginB == endB is a delete edit, that is sequence B has removed the elements between [beginA, endA).

An edit where beginA < endA && beginB < endB is a replace edit, that is sequence B has replaced the range of elements between [beginA, endA) with those found in [beginB, endB).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Type of edit
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) int
     
    (package private) int
     
    (package private) int
     
    (package private) int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Edit(int as, int bs)
    Create a new empty edit.
    Edit(int as, int ae, int bs, int be)
    Create a new edit.
  • Method Summary

    Modifier and Type
    Method
    Description
    final Edit
    after(Edit cut)
    Construct a new edit representing the region after cut.
    final Edit
    before(Edit cut)
    Construct a new edit representing the region before cut.
    boolean
    void
    Increase getEndA() by 1.
    void
    Increase getEndB() by 1.
    final int
    Get start point in sequence A
    final int
    Get start point in sequence B
    final int
    Get end point in sequence A
    final int
    Get end point in sequence B
    final int
    Get length of the region in A
    final int
    Get length of the region in B
    final Edit.Type
    Get type
    int
    final boolean
    Whether edit is empty
    final void
    shift(int amount)
    Move the edit region by the specified amount.
    void
    Swap A and B, so the edit goes the other direction.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • beginA

      int beginA
    • endA

      int endA
    • beginB

      int beginB
    • endB

      int endB
  • Constructor Details

    • Edit

      public Edit(int as, int bs)
      Create a new empty edit.
      Parameters:
      as - beginA: start and end of region in sequence A; 0 based.
      bs - beginB: start and end of region in sequence B; 0 based.
    • Edit

      public Edit(int as, int ae, int bs, int be)
      Create a new edit.
      Parameters:
      as - beginA: start of region in sequence A; 0 based.
      ae - endA: end of region in sequence A; must be >= as.
      bs - beginB: start of region in sequence B; 0 based.
      be - endB: end of region in sequence B; must be > = bs.
  • Method Details

    • getType

      public final Edit.Type getType()
      Get type
      Returns:
      the type of this region
    • isEmpty

      public final boolean isEmpty()
      Whether edit is empty
      Returns:
      true if the edit is empty (lengths of both a and b is zero)
    • getBeginA

      public final int getBeginA()
      Get start point in sequence A
      Returns:
      start point in sequence A
    • getEndA

      public final int getEndA()
      Get end point in sequence A
      Returns:
      end point in sequence A
    • getBeginB

      public final int getBeginB()
      Get start point in sequence B
      Returns:
      start point in sequence B
    • getEndB

      public final int getEndB()
      Get end point in sequence B
      Returns:
      end point in sequence B
    • getLengthA

      public final int getLengthA()
      Get length of the region in A
      Returns:
      length of the region in A
    • getLengthB

      public final int getLengthB()
      Get length of the region in B
      Returns:
      return length of the region in B
    • shift

      public final void shift(int amount)
      Move the edit region by the specified amount.
      Parameters:
      amount - the region is shifted by this amount, and can be positive or negative.
      Since:
      4.8
    • before

      public final Edit before(Edit cut)
      Construct a new edit representing the region before cut.
      Parameters:
      cut - the cut point. The beginning A and B points are used as the end points of the returned edit.
      Returns:
      an edit representing the slice of this edit that occurs before cut starts.
    • after

      public final Edit after(Edit cut)
      Construct a new edit representing the region after cut.
      Parameters:
      cut - the cut point. The ending A and B points are used as the starting points of the returned edit.
      Returns:
      an edit representing the slice of this edit that occurs after cut ends.
    • extendA

      public void extendA()
      Increase getEndA() by 1.
    • extendB

      public void extendB()
      Increase getEndB() by 1.
    • swap

      public void swap()
      Swap A and B, so the edit goes the other direction.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object