KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > CVSRevisionNumberCompareCriteria


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.internal.ccvs.core;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.team.core.variants.IResourceVariant;
16 import org.eclipse.team.core.variants.IResourceVariantComparator;
17 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
18 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
19
20 /**
21  * CVSRevisionNumberCompareCriteria
22  */

23  public class CVSRevisionNumberCompareCriteria implements IResourceVariantComparator {
24     
25     private boolean isThreeWay;
26
27     public CVSRevisionNumberCompareCriteria(boolean isThreeWay) {
28         this.isThreeWay = isThreeWay;
29     }
30     
31     /**
32      * @see RemoteSyncElement#timestampEquals(IResourceVariant, IResourceVariant)
33      */

34     protected boolean compare(ICVSRemoteResource e1, ICVSRemoteResource e2) {
35         if(e1.isContainer()) {
36             if(e2.isContainer()) {
37                 return true;
38             }
39             return false;
40         }
41         return e1.equals(e2);
42     }
43
44     /**
45      * @see RemoteSyncElement#timestampEquals(IResource, IResourceVariant)
46      */

47     protected boolean compare(IResource e1, ICVSRemoteResource e2) {
48         if(e1.getType() != IResource.FILE) {
49             if(e2.isContainer()) {
50                 return true;
51             }
52             return false;
53         }
54         ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile)e1);
55         try {
56             byte[] syncBytes1 = cvsFile.getSyncBytes();
57             byte[] syncBytes2 = ((ICVSRemoteFile)e2).getSyncBytes();
58         
59             if(syncBytes1 != null) {
60                 if(ResourceSyncInfo.isDeletion(syncBytes1) || ResourceSyncInfo.isMerge(syncBytes1) || cvsFile.isModified(null)) {
61                     return false;
62                 }
63                 return ResourceSyncInfo.getRevision(syncBytes1).equals(ResourceSyncInfo.getRevision(syncBytes2));
64             }
65             return false;
66         } catch(CVSException e) {
67             CVSProviderPlugin.log(e);
68             return false;
69         }
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.team.core.subscribers.IComparisonCriteria#compare(org.eclipse.core.resources.IResource, org.eclipse.team.core.subscribers.ISubscriberResource)
74      */

75     public boolean compare(IResource local, IResourceVariant remote) {
76         return compare(local, (ICVSRemoteResource)remote);
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.team.core.subscribers.IComparisonCriteria#compare(org.eclipse.team.core.subscribers.ISubscriberResource, org.eclipse.team.core.subscribers.ISubscriberResource)
81      */

82     public boolean compare(IResourceVariant base, IResourceVariant remote) {
83         return compare((ICVSRemoteResource)base, (ICVSRemoteResource)remote);
84     }
85
86     /* (non-Javadoc)
87      * @see org.eclipse.team.core.subscribers.ISubscriberResourceComparator#isThreeWay()
88      */

89     public boolean isThreeWay() {
90         return isThreeWay;
91     }
92 }
93
Popular Tags