KickJava   Java API By Example, From Geeks To Geeks.

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


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.ITwoWayDiff;
15
16 /**
17  * Implementation of {@link ITwoWayDiff}. By default, this implementation
18  * returns <code>null</code> for the {@link #getFromPath() } and
19  * {@link #getToPath() }. Subclasses that support move diffs
20  * should override these methods.
21  * <p>
22  * This class may be subclassed by clients.
23  *
24  * @since 3.2
25  */

26 public class TwoWayDiff extends Diff implements ITwoWayDiff {
27
28     /**
29      * Constant (bit mask) that defines the area of the status that is reserved
30      * for use by this abstract class for encoding the flags of the diff.
31      * However, subclasses may include their own bits in the flag
32      * as long as they do not overlap with the bits in the <code>FLAG_MASK</code>
33      *
34      * @see Diff#getStatus()
35      */

36     protected static final int FLAG_MASK = 0xFF00;
37
38     /**
39      * Create a two-way diff
40      * @param path the path of the model object that has changed
41      * @param kind the kind of change
42      * @param flags additional flags that describe the change
43      */

44     public TwoWayDiff(IPath path, int kind, int flags) {
45         super(path, (kind & KIND_MASK) | (flags & ~KIND_MASK));
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.team.core.synchronize.ITwoWayDelta#getFlags()
50      */

51     public int getFlags() {
52         return getStatus() & ~KIND_MASK;
53     }
54     
55     /* (non-Javadoc)
56      * @see org.eclipse.team.core.delta.ITwoWayDelta#getMovedToPath()
57      */

58     public IPath getToPath() {
59         return null;
60     }
61
62     /* (non-Javadoc)
63      * @see org.eclipse.team.core.delta.ITwoWayDelta#getMovedFromPath()
64      */

65     public IPath getFromPath() {
66         return null;
67     }
68     
69     /* (non-Javadoc)
70      * @see org.eclipse.team.core.diff.provider.Diff#equals(java.lang.Object)
71      */

72     public boolean equals(Object JavaDoc obj) {
73         if (obj == this)
74             return true;
75         if (super.equals(obj)) {
76             if (obj instanceof TwoWayDiff) {
77                 TwoWayDiff other = (TwoWayDiff) obj;
78                 return pathsEqual(getFromPath(), other.getFromPath()) && pathsEqual(getToPath(), other.getToPath());
79             }
80         }
81         return false;
82     }
83
84     private boolean pathsEqual(IPath path1, IPath path2) {
85         if (path1 == null)
86             return path2 == null;
87         if (path2 == null)
88             return false;
89         return path1.equals(path2);
90     }
91
92 }
93
Popular Tags