diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-09-01 23:09:48 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-09-03 23:55:46 -0700 |
commit | fe8fe13349bb46ae690cfea6d3e57bfdac2301e4 (patch) | |
tree | 8c4740ab796a0ce909d5cfbbb3cf46329cf39bd6 /org.eclipse.jgit | |
parent | 596c3f668b184e41b147aab6260c23189e521c09 (diff) | |
download | jgit-fe8fe13349bb46ae690cfea6d3e57bfdac2301e4.tar.gz jgit-fe8fe13349bb46ae690cfea6d3e57bfdac2301e4.zip |
Add helper methods to Edit
Exposing isEmpty, getLengthA, getLengthB make it easier to examine
the state of an edit and work with it from higher level code.
The before and after cut routines make it easy to split an edit
that contains another edit, such as to decompose a REPLACE that
contains a common sequence within it.
Change-Id: Id63d6476a7a6b23acb7ab237d414a0a1a7200290
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java index 109c049ccd..4a5de57b07 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java @@ -130,6 +130,11 @@ public class Edit { return Type.REPLACE; } + /** @return true if the edit is empty (lengths of both a and b is zero). */ + public final boolean isEmpty() { + return beginA == endA && beginB == endB; + } + /** @return start point in sequence A. */ public final int getBeginA() { return beginA; @@ -150,6 +155,42 @@ public class Edit { return endB; } + /** @return length of the region in A. */ + public final int getLengthA() { + return endA - beginA; + } + + /** @return length of the region in B. */ + public final int getLengthB() { + return endB - beginB; + } + + /** + * Construct a new edit representing the region before cut. + * + * @param cut + * the cut point. The beginning A and B points are used as the + * end points of the returned edit. + * @return an edit representing the slice of {@code this} edit that occurs + * before {@code cut} starts. + */ + public final Edit before(Edit cut) { + return new Edit(beginA, cut.beginA, beginB, cut.beginB); + } + + /** + * Construct a new edit representing the region after cut. + * + * @param cut + * the cut point. The ending A and B points are used as the + * starting points of the returned edit. + * @return an edit representing the slice of {@code this} edit that occurs + * after {@code cut} ends. + */ + public final Edit after(Edit cut) { + return new Edit(cut.endA, endA, cut.endB, endB); + } + /** Increase {@link #getEndA()} by 1. */ public void extendA() { endA++; |