129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.internal.text.revisions.Hunk;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import dwtx.core.runtime.Assert;
|
|
18
|
|
19 /**
|
|
20 * A hunk describes a contiguous range of changed, added or deleted lines. <code>Hunk</code>s are separated by
|
|
21 * one or more unchanged lines.
|
|
22 *
|
|
23 * @since 3.3
|
|
24 */
|
|
25 public final class Hunk {
|
|
26 /**
|
|
27 * The line at which the hunk starts in the current document. Must be in
|
|
28 * <code>[0, numberOfLines]</code> – note the inclusive end; there may be a hunk with
|
|
29 * <code>line is numberOfLines</code> to describe deleted lines at then end of the document.
|
|
30 */
|
|
31 public final int line;
|
|
32 /**
|
|
33 * The difference in lines compared to the corresponding line range in the original. Positive
|
|
34 * for added lines, negative for deleted lines.
|
|
35 */
|
|
36 public final int delta;
|
|
37 /** The number of changed lines in this hunk, must be >= 0. */
|
|
38 public final int changed;
|
|
39
|
|
40 /**
|
|
41 * Creates a new hunk.
|
|
42 *
|
|
43 * @param line the line at which the hunk starts, must be >= 0
|
|
44 * @param delta the difference in lines compared to the original
|
|
45 * @param changed the number of changed lines in this hunk, must be >= 0
|
|
46 */
|
|
47 public Hunk(int line, int delta, int changed) {
|
|
48 Assert.isLegal(line >= 0);
|
|
49 Assert.isLegal(changed >= 0);
|
|
50 this.line= line;
|
|
51 this.delta= delta;
|
|
52 this.changed= changed;
|
|
53 }
|
|
54
|
|
55 /*
|
|
56 * @see java.lang.Object#toString()
|
|
57 */
|
|
58 public String toString() {
|
|
59 return "Hunk [" + line + ">" + changed + (delta < 0 ? "-" : "+") + Math.abs(delta) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
|
60 }
|
|
61
|
|
62 /*
|
|
63 * @see java.lang.Object#hashCode()
|
|
64 */
|
|
65 public int hashCode() {
|
|
66 final int prime= 31;
|
|
67 int result= 1;
|
|
68 result= prime * result + changed;
|
|
69 result= prime * result + delta;
|
|
70 result= prime * result + line;
|
|
71 return result;
|
|
72 }
|
|
73
|
|
74 /*
|
|
75 * @see java.lang.Object#equals(java.lang.Object)
|
|
76 */
|
|
77 public bool equals(Object obj) {
|
|
78 if (obj is this)
|
|
79 return true;
|
|
80 if (obj instanceof Hunk) {
|
|
81 Hunk other= (Hunk) obj;
|
|
82 return other.line is this.line && other.delta is this.delta && other.changed is this.changed;
|
|
83 }
|
|
84 return false;
|
|
85 }
|
|
86 }
|