KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > text > revisions > Hunk


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  *******************************************************************************/

11 package org.eclipse.jface.internal.text.revisions;
12
13 import org.eclipse.core.runtime.Assert;
14
15 /**
16  * A hunk describes a contiguous range of changed, added or deleted lines. <code>Hunk</code>s are separated by
17  * one or more unchanged lines.
18  *
19  * @since 3.3
20  */

21 public final class Hunk {
22     /**
23      * The line at which the hunk starts in the current document. Must be in
24      * <code>[0, numberOfLines]</code> &ndash; note the inclusive end; there may be a hunk with
25      * <code>line == numberOfLines</code> to describe deleted lines at then end of the document.
26      */

27     public final int line;
28     /**
29      * The difference in lines compared to the corresponding line range in the original. Positive
30      * for added lines, negative for deleted lines.
31      */

32     public final int delta;
33     /** The number of changed lines in this hunk, must be &gt;= 0. */
34     public final int changed;
35
36     /**
37      * Creates a new hunk.
38      *
39      * @param line the line at which the hunk starts, must be &gt;= 0
40      * @param delta the difference in lines compared to the original
41      * @param changed the number of changed lines in this hunk, must be &gt;= 0
42      */

43     public Hunk(int line, int delta, int changed) {
44         Assert.isLegal(line >= 0);
45         Assert.isLegal(changed >= 0);
46         this.line= line;
47         this.delta= delta;
48         this.changed= changed;
49     }
50
51     /*
52      * @see java.lang.Object#toString()
53      */

54     public String JavaDoc toString() {
55         return "Hunk [" + line + ">" + changed + (delta < 0 ? "-" : "+") + Math.abs(delta) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
56
}
57     
58     /*
59      * @see java.lang.Object#hashCode()
60      */

61     public int hashCode() {
62         final int prime= 31;
63         int result= 1;
64         result= prime * result + changed;
65         result= prime * result + delta;
66         result= prime * result + line;
67         return result;
68     }
69
70     /*
71      * @see java.lang.Object#equals(java.lang.Object)
72      */

73     public boolean equals(Object JavaDoc obj) {
74         if (obj == this)
75             return true;
76         if (obj instanceof Hunk) {
77             Hunk other= (Hunk) obj;
78             return other.line == this.line && other.delta == this.delta && other.changed == this.changed;
79         }
80         return false;
81     }
82 }
Popular Tags