Hey Matt, Check this link: http://www.cafeaulait.org/course/week4/38.html
"Anytime you override equals() you should also override hashCode(). The hashCode() method should ideally return the same int for any two objects that compare equal and a different int for any two objects that don't compare equal, where equality is defined by the equals() method. This is used as an index by the java.util.Hashtable class. " Paulo -----Original Message----- From: paulo caroli [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 24, 2004 10:46 AM To: 'Turbine JCS Users List' Subject: RE: Cache returning unexpected items. Matt, I advice you to test your key comparison to ensure it is working. For some cases you need to implement the public int hashCode() method as well as the public boolean equals(Object obj) method. Thanks, Paulo -----Original Message----- From: Matthew Cooke [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 24, 2004 6:01 AM To: Turbine JCS Users List Subject: Re: Cache returning unexpected items. > How are you comparing the keys? > Thanks, > > Paulo Paulo, Maybe that is the problem. Does the key object need to be comparable or something? (appologies for long post - I've tried to include most of the relevant key related code) Here are the important parts of the key object we use: public class RealCacheKey implements CacheKey { private Collection myMultipartKey = new HashSet(); public RealCacheKey(HttpServletRequest aServletRequest) { addURIParametersInto(myMultipartKey, aServletRequest); } <...snip...> public static void addURIParametersInto(Collection aCollection, HttpServletRequest aRequest) { Enumeration names = aRequest.getParameterNames(); while (names.hasMoreElements()) { String aKey = (String) names.nextElement(); if (!isCacheBuster(aKey)) { String[] values = aRequest.getParameterValues(aKey); aCollection.add(new MapEntry(aKey, Arrays.asList(values))); } } } private boolean equals(RealCacheKey another) { return myMultipartKey.equals(another.myMultipartKey); } public boolean equals(Object another) { return (another instanceof CacheKey) && equals((RealCacheKey) another); } <...snip...> } The cachekey interface extends serializable. The map entries are serializable and look like this: public class MapEntry implements java.util.Map.Entry, Comparable, Serializable { private static final String NULL = "null"; private Object key; private Object value; public MapEntry(Object aKey, Object aValue) { super(); this.key = (aKey == null) ? NULL : aKey; this.value = (aValue == null) ? NULL : aValue; } <...snip...> Cheers, Matt. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
