KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > core > mapping > provider > ResourceDiff


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.mapping.provider;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.team.core.diff.provider.TwoWayDiff;
16 import org.eclipse.team.core.history.IFileRevision;
17 import org.eclipse.team.core.mapping.IResourceDiff;
18
19 /**
20  * Implementation of {@link IResourceDiff}.
21  * <p>
22  * This class may be subclassed by clients.
23  *
24  * @since 3.2
25  */

26 public class ResourceDiff extends TwoWayDiff implements IResourceDiff {
27
28     private final IFileRevision before;
29     private final IFileRevision after;
30     private final IResource resource;
31
32     /**
33      * Create a two-way resource diff
34      * @param resource the resource
35      * @param kind the kind of change (ADDED, REMOVED or CHANGED)
36      * @param flags additional flags that describe the change
37      * @param before the before state of the model object
38      * @param after the after state of the model object
39      */

40     public ResourceDiff(IResource resource, int kind, int flags, IFileRevision before, IFileRevision after) {
41         super(resource.getFullPath(), kind, flags);
42         this.resource = resource;
43         this.before = before;
44         this.after = after;
45     }
46
47     /**
48      * Convenience constructor for creating a simple folder diff
49      * that consists of a resource and a kind only. It is equivalent to
50      * <code>ResourceDiff(resource, kind, 0, null, null)<code>
51      * @param resource a resource
52      * @param kind the kind of change (ADDED, REMOVED or CHANGED)
53      */

54     public ResourceDiff(IResource resource, int kind) {
55         this(resource, kind, 0, null, null);
56         Assert.isTrue(resource.getType() != IResource.FILE);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.team.core.diff.IResourceDiff#getBeforeState()
61      */

62     public IFileRevision getBeforeState() {
63         return before;
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.team.core.diff.IResourceDiff#getAfterState()
68      */

69     public IFileRevision getAfterState() {
70         return after;
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.team.core.diff.IResourceDiff#getResource()
75      */

76     public IResource getResource() {
77         return resource;
78     }
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.team.core.diff.provider.Diff#equals(java.lang.Object)
82      */

83     public boolean equals(Object JavaDoc obj) {
84         if (obj == this)
85             return true;
86         if (super.equals(obj)) {
87             if (obj instanceof ResourceDiff) {
88                 ResourceDiff other = (ResourceDiff) obj;
89                 return getResource().equals(getResource())
90                     && revisionsEqual(getBeforeState(), other.getBeforeState())
91                     && revisionsEqual(getAfterState(), other.getAfterState());
92             }
93         }
94         return false;
95     }
96
97     private boolean revisionsEqual(IFileRevision revision, IFileRevision revision2) {
98         if (revision == null)
99             return revision2 == null;
100         if (revision2 == null)
101             return false;
102         return revision.equals(revision2);
103     }
104
105 }
106
Popular Tags