Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan G2016-01-23 12:56:09 +0000
committerRaymond Auge2016-01-29 14:45:30 +0000
commit2fc142b66c4dc6abf871cfec67768646cb3cd2bb (patch)
treef427eca4d95868b203bbd40f7b6f0a465aba4dd3 /bundles/org.eclipse.equinox.http.servlet/src
parent5841cbadc941eb9c1cca822132a4109da5db932b (diff)
downloadrt.equinox.bundles-2fc142b66c4dc6abf871cfec67768646cb3cd2bb.tar.gz
rt.equinox.bundles-2fc142b66c4dc6abf871cfec67768646cb3cd2bb.tar.xz
rt.equinox.bundles-2fc142b66c4dc6abf871cfec67768646cb3cd2bb.zip
Bug 486412 - [http whiteboard] Implement equals and hashCode methods so object comparisons give the right result
Signed-off-by: Juan Gonzalez <juan.gonzalez@liferay.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.http.servlet/src')
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java
index 81b4e81be..1e65de97d 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java
@@ -9,6 +9,7 @@
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
* Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ * Juan Gonzalez <juan.gonzalez@liferay.com> - Bug 486412
*******************************************************************************/
package org.eclipse.equinox.http.servlet.internal.servlet;
@@ -54,6 +55,19 @@ public class ServletContextAdaptor {
}
}
+ try {
+ Method equalsMethod = Object.class.getMethod("equals", Object.class); //$NON-NLS-1$
+ Method equalsHandlerMethod = ServletContextAdaptor.class.getMethod("equals", Object.class); //$NON-NLS-1$
+ methods.put(equalsMethod, equalsHandlerMethod);
+
+ Method hashCodeMethod = Object.class.getMethod("hashCode", (Class<?>[])null); //$NON-NLS-1$
+ Method hashCodeHandlerMethod = ServletContextAdaptor.class.getMethod("hashCode", (Class<?>[])null); //$NON-NLS-1$
+ methods.put(hashCodeMethod, hashCodeHandlerMethod);
+ }
+ catch (NoSuchMethodException e) {
+ // do nothing
+ }
+
return methods;
}
@@ -87,6 +101,21 @@ public class ServletContextAdaptor {
curClassLoader, interfaces, invocationHandler);
}
+ public boolean equals (Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof ServletContext)) {
+ return false;
+ }
+
+ ServletContext servletContextObj = (ServletContext) obj;
+
+ return (classLoader.equals(servletContextObj.getClassLoader()) &&
+ getServletContextName().equals(servletContextObj.getServletContextName()));
+ }
+
public ClassLoader getClassLoader() {
return classLoader;
}
@@ -244,6 +273,16 @@ public class ServletContextAdaptor {
return contextController.getContextName();
}
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((classLoader == null) ? 0 : classLoader.hashCode());
+ result = prime * result
+ + ((contextName == null) ? 0 : contextName.hashCode());
+ return result;
+ }
+
public void removeAttribute(String attributeName) {
Dictionary<String, Object> attributes = getContextAttributes();
Object attributeValue = attributes.remove(attributeName);

Back to the top