2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
/// <summary>A modified region detected between two versions of roughly the same content.
52
/// A modified region detected between two versions of roughly the same content.
54
/// An edit covers the modified region only. It does not cover a common region.
56
/// Regions should be specified using 0 based notation, so add 1 to the start and
57
/// end marks for line numbers in a file.
59
/// An edit where <code>beginA == endA && beginB < endB</code> is an insert edit,
60
/// that is sequence B inserted the elements in region
61
/// <code>[beginB, endB)</code> at <code>beginA</code>.
63
/// An edit where <code>beginA < endA && beginB == endB</code> is a delete edit,
64
/// that is sequence B has removed the elements between
65
/// <code>[beginA, endA)</code>.
67
/// An edit where <code>beginA < endA && beginB < endB</code> is a replace edit,
68
/// that is sequence B has replaced the range of elements between
69
/// <code>[beginA, endA)</code> with those found in <code>[beginB, endB)</code>.
73
/// <summary>Type of edit</summary>
90
/// <summary>Create a new empty edit.</summary>
91
/// <remarks>Create a new empty edit.</remarks>
92
/// <param name="as">beginA: start and end of region in sequence A; 0 based.</param>
93
/// <param name="bs">beginB: start and end of region in sequence B; 0 based.</param>
94
public Edit(int @as, int bs) : this(@as, @as, bs, bs)
98
/// <summary>Create a new edit.</summary>
99
/// <remarks>Create a new edit.</remarks>
100
/// <param name="as">beginA: start of region in sequence A; 0 based.</param>
101
/// <param name="ae">endA: end of region in sequence A; must be >= as.</param>
102
/// <param name="bs">beginB: start of region in sequence B; 0 based.</param>
103
/// <param name="be">endB: end of region in sequence B; must be >= bs.</param>
104
public Edit(int @as, int ae, int bs, int be)
112
/// <returns>the type of this region</returns>
113
public Edit.Type GetType()
119
return Edit.Type.REPLACE;
123
return Edit.Type.DELETE;
130
return Edit.Type.INSERT;
134
return Edit.Type.EMPTY;
139
/// <returns>true if the edit is empty (lengths of both a and b is zero).</returns>
140
public bool IsEmpty()
142
return beginA == endA && beginB == endB;
145
/// <returns>start point in sequence A.</returns>
146
public int GetBeginA()
151
/// <returns>end point in sequence A.</returns>
157
/// <returns>start point in sequence B.</returns>
158
public int GetBeginB()
163
/// <returns>end point in sequence B.</returns>
169
/// <returns>length of the region in A.</returns>
170
public int GetLengthA()
172
return endA - beginA;
175
/// <returns>length of the region in B.</returns>
176
public int GetLengthB()
178
return endB - beginB;
181
/// <summary>Construct a new edit representing the region before cut.</summary>
182
/// <remarks>Construct a new edit representing the region before cut.</remarks>
183
/// <param name="cut">
184
/// the cut point. The beginning A and B points are used as the
185
/// end points of the returned edit.
188
/// an edit representing the slice of
189
/// <code>this</code>
195
public NGit.Diff.Edit Before(NGit.Diff.Edit cut)
197
return new NGit.Diff.Edit(beginA, cut.beginA, beginB, cut.beginB);
200
/// <summary>Construct a new edit representing the region after cut.</summary>
201
/// <remarks>Construct a new edit representing the region after cut.</remarks>
202
/// <param name="cut">
203
/// the cut point. The ending A and B points are used as the
204
/// starting points of the returned edit.
207
/// an edit representing the slice of
208
/// <code>this</code>
214
public NGit.Diff.Edit After(NGit.Diff.Edit cut)
216
return new NGit.Diff.Edit(cut.endA, endA, cut.endB, endB);
221
/// <see cref="GetEndA()">GetEndA()</see>
224
public virtual void ExtendA()
231
/// <see cref="GetEndB()">GetEndB()</see>
234
public virtual void ExtendB()
239
/// <summary>Swap A and B, so the edit goes the other direction.</summary>
240
/// <remarks>Swap A and B, so the edit goes the other direction.</remarks>
241
public virtual void Swap()
251
public override int GetHashCode()
253
return beginA ^ endA;
256
public override bool Equals(object o)
258
if (o is NGit.Diff.Edit)
260
NGit.Diff.Edit e = (NGit.Diff.Edit)o;
261
return this.beginA == e.beginA && this.endA == e.endA && this.beginB == e.beginB
262
&& this.endB == e.endB;
267
public override string ToString()
269
Edit.Type t = GetType();
270
return t + "(" + beginA + "-" + endA + "," + beginB + "-" + endB + ")";