KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > core > diff > provider > Diff


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.team.core.diff.provider;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.team.core.diff.*;
15 import org.eclipse.team.internal.core.mapping.SyncInfoToDiffConverter;
16
17 /**
18  * Abstract implementation of {@link IDiff} that can be subclassed by
19  * clients.
20  *
21  * @see ITwoWayDiff
22  * @see IThreeWayDiff
23  * @since 3.2
24  */

25 public abstract class Diff implements IDiff {
26
27     /**
28      * Constant (bit mask) that defines the area of the status that is reserved
29      * for use by this abstract class for encoding the kind of the diff.
30      *
31      * @see #getStatus()
32      */

33     public static final int KIND_MASK = 0xFF;
34
35     private final IPath path;
36
37     private final int status;
38
39     /**
40      * Create a diff node.
41      *
42      * @param path the path of the diff
43      * @param status the status of the diff. The kind should be encoded in the
44      * status along with any additional flags required by a subclass.
45      */

46     protected Diff(IPath path, int status) {
47         this.path = path;
48         this.status = status;
49     }
50
51     /*
52      * (non-Javadoc)
53      *
54      * @see org.eclipse.team.core.synchronize.ISyncDelta#getFullPath()
55      */

56     public IPath getPath() {
57         return path;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.eclipse.team.core.synchronize.ISyncDelta#getKind()
64      */

65     public int getKind() {
66         return getStatus() & KIND_MASK;
67     }
68
69     /**
70      * Return the status of the diff node. The status is a bit field that
71      * contains the kind and any additional status information that subclasses
72      * need to encode. The first byte of the status is reserved for use by this
73      * abstract class as indicated by the <code>KIND_MASK</code>.
74      *
75      * @return the status of the diff node
76      */

77     public final int getStatus() {
78         return status;
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.team.core.diff.IDiffNode#toDiffString()
83      */

84     public String JavaDoc toDiffString() {
85         int kind = getKind();
86         String JavaDoc label = SyncInfoToDiffConverter.diffKindToString(kind);
87         return label;
88     }
89     
90     /* (non-Javadoc)
91      * @see java.lang.Object#hashCode()
92      */

93     public int hashCode() {
94         return getPath().hashCode();
95     }
96     
97     /* (non-Javadoc)
98      * @see java.lang.Object#equals(java.lang.Object)
99      */

100     public boolean equals(Object JavaDoc obj) {
101         if (obj == this)
102             return true;
103         if (obj instanceof Diff) {
104             Diff other = (Diff) obj;
105             return other.getPath().equals(getPath()) && getStatus() == other.getStatus();
106         }
107         return false;
108     }
109 }
110
Popular Tags