1 11 package org.eclipse.core.internal.resources; 12 13 import java.net.URI ; 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.core.runtime.*; 16 17 21 public class LinkDescription implements Comparable { 22 23 private URI localLocation; 24 25 28 private IPath path; 29 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 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 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 getLocationURI() { 56 return localLocation; 57 } 58 59 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 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 92 public int compareTo(Object 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 |