|
Lines 46-75
Link Here
|
| 46 |
* Return false if one of them is null |
46 |
* Return false if one of them is null |
| 47 |
*/ |
47 |
*/ |
| 48 |
public static boolean sameURL(URL url1, URL url2) { |
48 |
public static boolean sameURL(URL url1, URL url2) { |
| 49 |
|
|
|
| 50 |
if (url1 == null || url2 == null) |
| 51 |
return false; |
| 52 |
if (url1 == url2) |
49 |
if (url1 == url2) |
| 53 |
return true; |
50 |
return true; |
| 54 |
if (url1.equals(url2)) |
51 |
if (url1 == null ^ url2 == null) |
| 55 |
return true; |
52 |
return false; |
| 56 |
|
53 |
|
| 57 |
// check if URL are file: URL as we may |
54 |
// check if URL are file: URL as we may |
| 58 |
// have 2 URL pointing to the same featureReference |
55 |
// have 2 URL pointing to the same featureReference |
| 59 |
// but with different representation |
56 |
// but with different representation |
| 60 |
// (i.e. file:/C;/ and file:C:/) |
57 |
// (i.e. file:/C;/ and file:C:/) |
| 61 |
if (!"file".equalsIgnoreCase(url1.getProtocol())) //$NON-NLS-1$ |
58 |
final boolean isFile1 = "file".equalsIgnoreCase(url1.getProtocol());//$NON-NLS-1$ |
| 62 |
return false; |
59 |
final boolean isFile2 = "file".equalsIgnoreCase(url2.getProtocol());//$NON-NLS-1$ |
| 63 |
if (!"file".equalsIgnoreCase(url2.getProtocol())) //$NON-NLS-1$ |
60 |
if (isFile1 && isFile2) { |
| 64 |
return false; |
61 |
File file1 = new File(url1.getFile()); |
| 65 |
|
62 |
File file2 = new File(url2.getFile()); |
| 66 |
File file1 = new File(url1.getFile()); |
63 |
return file1.equals(file2); |
| 67 |
File file2 = new File(url2.getFile()); |
64 |
} |
| 68 |
|
65 |
// URL1 xor URL2 is a file, return false. (They either both need to be files, or neither) |
| 69 |
if (file1 == null) |
66 |
if (isFile1 ^ isFile2) |
| 70 |
return false; |
67 |
return false; |
|
|
68 |
return getExternalForm(url1).equals(getExternalForm(url2)); |
| 69 |
} |
| 71 |
|
70 |
|
| 72 |
return (file1.equals(file2)); |
71 |
/** |
|
|
72 |
* Gets the external form of this URL. In particular, it trims any white space, |
| 73 |
* removes a trailing slash and creates a lower case string. |
| 74 |
*/ |
| 75 |
private static String getExternalForm(URL url) { |
| 76 |
String externalForm = url.toExternalForm(); |
| 77 |
if (externalForm == null) |
| 78 |
return ""; //$NON-NLS-1$ |
| 79 |
externalForm = externalForm.trim(); |
| 80 |
if (externalForm.endsWith("/")) { //$NON-NLS-1$ |
| 81 |
// Remove the trailing slash |
| 82 |
externalForm = externalForm.substring(0, externalForm.length() - 1); |
| 83 |
} |
| 84 |
return externalForm.toLowerCase(); |
| 73 |
} |
85 |
} |
| 74 |
|
86 |
|
| 75 |
/** |
87 |
/** |
|
Lines 114-131
Link Here
|
| 114 |
* <code>false</code> otherwise |
126 |
* <code>false</code> otherwise |
| 115 |
*/ |
127 |
*/ |
| 116 |
public boolean equals(Object object) { |
128 |
public boolean equals(Object object) { |
| 117 |
|
|
|
| 118 |
if (object == null) |
129 |
if (object == null) |
| 119 |
return false; |
130 |
return false; |
| 120 |
if (getURL() == null) |
|
|
| 121 |
return false; |
| 122 |
|
| 123 |
if (!(object instanceof SiteFeature)) |
131 |
if (!(object instanceof SiteFeature)) |
| 124 |
return false; |
132 |
return false; |
|
|
133 |
SiteFeature that = (SiteFeature) object; |
| 134 |
if (this.featureId == null) { |
| 135 |
if (that.featureId != null) |
| 136 |
return false; |
| 137 |
} else if (!this.featureId.equals(that.featureId)) |
| 138 |
return false; |
| 139 |
if (this.featureVersion == null) { |
| 140 |
if (that.featureVersion != null) |
| 141 |
return false; |
| 142 |
} else if (!this.featureVersion.equals(that.featureVersion)) |
| 143 |
return false; |
| 144 |
if (this.label == null) { |
| 145 |
if (that.label != null) |
| 146 |
return false; |
| 147 |
} else if (!this.label.equals(that.label)) |
| 148 |
return false; |
| 149 |
return sameURL(this.getURL(), that.getURL()); |
| 150 |
} |
| 125 |
|
151 |
|
| 126 |
SiteFeature f = (SiteFeature) object; |
152 |
/* (non-Javadoc) |
| 127 |
|
153 |
* @see java.lang.Object#hashCode() |
| 128 |
return sameURL(getURL(), f.getURL()); |
154 |
*/ |
|
|
155 |
public int hashCode() { |
| 156 |
final int prime = 31; |
| 157 |
int result = 1; |
| 158 |
result = prime * result + (featureId == null ? 0 : featureId.hashCode()); |
| 159 |
result = prime * result + (featureVersion == null ? 0 : featureVersion.hashCode()); |
| 160 |
if (this.getURL() == null) |
| 161 |
return result; |
| 162 |
|
| 163 |
if ("file".equalsIgnoreCase(getURL().getProtocol())) {//$NON-NLS-1$ |
| 164 |
// If the URL is a file, then create the HashCode from the file |
| 165 |
File f = new File(getURL().getFile()); |
| 166 |
if (f != null) |
| 167 |
result = prime * result + f.hashCode(); |
| 168 |
} else |
| 169 |
// Otherwise create it from the External form of the URL (in lower case) |
| 170 |
result = prime * result + getExternalForm(this.getURL()).hashCode(); |
| 171 |
return result; |
| 129 |
} |
172 |
} |
| 130 |
|
173 |
|
| 131 |
/** |
174 |
/** |