KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > LinkDescription


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.core.internal.resources;
12
13 import java.net.URI JavaDoc;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.*;
16
17 /**
18  * Object for describing the characteristics of linked resources that are stored
19  * in the project description.
20  */

21 public class LinkDescription implements Comparable JavaDoc {
22
23     private URI JavaDoc localLocation;
24
25     /**
26      * The project relative path.
27      */

28     private IPath path;
29     /**
30      * The resource type (IResource.FILE or IResoruce.FOLDER)
31      */

32     private int type;
33
34     public LinkDescription() {
35         this.path = Path.EMPTY;
36         this.type = -1;
37     }
38
39     public LinkDescription(IResource linkedResource, URI JavaDoc location) {
40         super();
41         Assert.isNotNull(linkedResource);
42         Assert.isNotNull(location);
43         this.type = linkedResource.getType();
44         this.path = linkedResource.getProjectRelativePath();
45         this.localLocation = location;
46     }
47
48     public boolean equals(Object JavaDoc o) {
49         if (!(o.getClass() == LinkDescription.class))
50             return false;
51         LinkDescription other = (LinkDescription) o;
52         return localLocation.equals(other.localLocation) && type == other.type;
53     }
54
55     public URI JavaDoc getLocationURI() {
56         return localLocation;
57     }
58
59     /**
60      * Returns the project relative path of the resource that is linked.
61      * @return the project relative path of the resource that is linked.
62      */

63     public IPath getProjectRelativePath() {
64         return path;
65     }
66
67     public int getType() {
68         return type;
69     }
70
71     public int hashCode() {
72         return type + localLocation.hashCode();
73     }
74
75     public void setLocationURI(URI JavaDoc location) {
76         this.localLocation = location;
77     }
78
79     public void setPath(IPath path) {
80         this.path = path;
81     }
82
83     public void setType(int type) {
84         this.type = type;
85     }
86
87     /**
88      * Compare link descriptions in a way that sorts them topologically by path.
89      * This is important to ensure we process links in topological (breadth-first) order when reconciling
90      * links. See {@link Project#reconcileLinks(ProjectDescription)}.
91      */

92     public int compareTo(Object JavaDoc o) {
93         LinkDescription that = (LinkDescription) o;
94         IPath path1 = this.getProjectRelativePath();
95         IPath path2 = that.getProjectRelativePath();
96         int count1 = path1.segmentCount();
97         int compare = count1 - path2.segmentCount();
98         if (compare != 0)
99             return compare;
100         for (int i = 0; i < count1; i++) {
101             compare = path1.segment(i).compareTo(path2.segment(i));
102             if (compare != 0)
103                 return compare;
104         }
105         return 0;
106     }
107 }
108
Popular Tags