Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 299551
Collapse All | Expand All

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

Return to bug 299551