Why don't you always just do string.toUpperCase() on get's and put's One liner....
-----Original Message----- From: Guillermo Meyer [mailto:[EMAIL PROTECTED] Sent: Friday, February 13, 2004 12:48 PM To: 'Struts Users Mailing List' Subject: RE: [OT] Case insensitive Map keys The problem is that new Integer("hello".hashCode()) and new Integer("heLLo".hashCode()) are different integers, and I want them to be equals. Fredy's solution sounds interesting (Do a bit-by-bit XAND). We'll try it and let you know... -----Original Message----- From: Brian Lee [mailto:[EMAIL PROTECTED] Sent: Viernes, 13 de Febrero de 2004 03:39 p.m. To: [EMAIL PROTECTED] Subject: RE: [OT] Case insensitive Map keys Have you tried just using new Integer(str.hashCode())? It should be pretty quick. Its implementation is similar to yours below but has fewer operations so it should be faster (and more standard). BAL >From: "Villalba Arias, Fredy [BILBOMATICA]" <[EMAIL PROTECTED]> >To: "Struts Users Mailing List" ><[EMAIL PROTECTED]>,<[EMAIL PROTECTED]> >Subject: RE: [OT] Case insensitive Map keys >Date: Fri, 13 Feb 2004 17:12:44 +0100 >-----Mensaje original----- >De: Guillermo Meyer [mailto:[EMAIL PROTECTED] >Enviado el: viernes, 13 de febrero de 2004 14:38 >Para: 'Struts Users Mailing List' >Asunto: RE: [OT] Case insensitive Map keys > >I'm trying the following: > > public class KeyGeneratedMap extends HashMap { > public Object put(Object key, Object value) { > return >super.put(this.generateKey(key.toString()), value); > } > > public Object get(Object key) { > return >super.get(this.generateKey(key.toString())); > } > > /** > * This generates an integer object for Strings and are >case insensitive, that is > * Hello and heLLO generate the same Integer object value > */ > private Object generateKey(String str) { > int len = str.length(); > int h=0; > char val[] = str.toCharArray(); > char c; > for (int i = 0; i < len; i++) { > c=val[i++]; > if(c>=97 && c <=122) > c-=32; > > h = 31*h + c; > } > return new Integer(h); > } > } > >This by now is three times faster than using toUpperCase for storing >and retrievinig items from the hash. What do you think? > >-----Original Message----- >From: Navjot Singh [mailto:[EMAIL PROTECTED] >Sent: Viernes, 13 de Febrero de 2004 02:53 a.m. >To: Struts Users Mailing List >Subject: RE: [OT] Case insensitive Map keys > > >oops!! thanks for correcting me freddy. > >well in that case, if you map is not modified frequently, try the >FastHashMap from the Apache Commons. either you override and read and >write your own. > > >-----Original Message----- > >From: Villalba Arias, Fredy [BILBOMATICA] > >[mailto:[EMAIL PROTECTED] > >Sent: Thursday, February 12, 2004 5:50 PM > >To: Struts Users Mailing List > >Subject: RE: [OT] Case insensitive Map keys > > > > > >Navjot, > > > >I believe this is exactly what Guillermo CLEARLY stated he had > >already tried (and is not efficient enough for him). > > > >If you had taken a little bit longer and read carefully, then maybe > >you'd have noticed. > > > >Regards, > >Freddy. > > > >-----Mensaje original----- > >De: Navjot Singh [mailto:[EMAIL PROTECTED] > >Enviado el: jueves, 12 de febrero de 2004 13:14 > >Para: Struts Users Mailing List; [EMAIL PROTECTED] > >Asunto: RE: [OT] Case insensitive Map keys > > > >yes. here it is. > > > >public CIMap extends HashMap > >{ > > > > public Object get(String key) > > { > > return super.get(key.toLowerCase()); > > } > > > > public Object put(String key, Object value) > > { > > super.put(key.toLowerCase(),value); > > } > >} > > > >This was simple implementation. By the time you ask the Q and wait > >for reply. you could have written on your own. > > > >Navjot Singh > > > > > >>-----Original Message----- > >>From: Guillermo Meyer [mailto:[EMAIL PROTECTED] > >>Sent: Thursday, February 12, 2004 5:24 PM > >>To: 'Struts Users Mailing List' > >>Subject: [OT] Case insensitive Map keys > >> > >> > >>Hi: > >>Does anyone know an implementation of Map where keys are String and > >>case insensitive? I want to do this: > >> > >>map.put("propertyName", "DATA"); > >> > >>And then, I should be able to get the value like this: Object obj = > >>map.get("PROPERTYNAME"); > >> > >>Or like this: > >>Object obj = map.get("propertyname"); //or whatever. case > >>insensitive. > >> > >>We tried using toUppercase when putting and toUppercase when > >>getting, and using equalsIgnoreCase but this is not as efficient as > >>we need. May there be a way to calculate a hash for strings in upper > >>or lower case to result in the same value? > >> > >>Thanks in advance. > >> > >>Guillermo. > >> > >> > >>NOTA DE CONFIDENCIALIDAD > >>Este mensaje (y sus anexos) es confidencial, esta dirigido > >>exclusivamente a las personas direccionadas en el mail y puede > >>contener informacion (i)de propiedad exclusiva de Interbanking S.A. > >>o > >>(ii) amparada por el secreto profesional. Cualquier opinion en el > >>contenido, es exclusiva de su autor y no representa necesariamente la > >>opinion de Interbanking S.A. El acceso no autorizado, uso, > >>reproduccion, o divulgacion esta prohibido. Interbanking S.A no > >>asumira responsabilidad ni obligacion legal alguna por cualquier > >>informacion incorrecta o alterada contenida en este mensaje. Si usted > >>ha recibido este mensaje por error, le rogamos tenga la amabilidad de > >>destruirlo inmediatamente junto con todas las copias del mismo, > >>notificando al remitente. No debera utilizar, revelar, distribuir, > >>imprimir o copiar este mensaje ni ninguna de sus partes si usted no es > > >>el destinatario. Muchas gracias. > >> > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > >--- > >Incoming mail is certified Virus Free. > >Checked by AVG anti-virus system (http://www.grisoft.com). > >Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003 > > > > > >--- > >Outgoing mail is certified Virus Free. > >Checked by AVG anti-virus system (http://www.grisoft.com). > >Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003 > > > > > >--------------------------------------------------------------------- > >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] > >NOTA DE CONFIDENCIALIDAD >Este mensaje (y sus anexos) es confidencial, esta dirigido >exclusivamente a >las personas direccionadas en el mail y puede contener informacion (i)de >propiedad exclusiva de Interbanking S.A. o (ii) amparada por el secreto >profesional. Cualquier opinion en el contenido, es exclusiva de su autor y >no representa necesariamente la opinion de Interbanking S.A. El acceso no >autorizado, uso, reproduccion, o divulgacion esta prohibido. Interbanking >S.A no asumira responsabilidad ni obligacion legal alguna por cualquier >informacion incorrecta o alterada contenida en este mensaje. Si usted ha >recibido este mensaje por error, le rogamos tenga la amabilidad de >destruirlo inmediatamente junto con todas las copias del mismo, notificando >al remitente. No debera utilizar, revelar, distribuir, imprimir o copiar >este mensaje ni ninguna de sus partes si usted no es el destinatario. >Muchas gracias. > > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > >--- >Incoming mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003 > > >--- >Outgoing mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003 > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > _________________________________________________________________ Find great local high-speed Internet access value at the MSN High-Speed Marketplace. http://click.atdmt.com/AVE/go/onm00200360ave/direct/01/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] NOTA DE CONFIDENCIALIDAD Este mensaje (y sus anexos) es confidencial, esta dirigido exclusivamente a las personas direccionadas en el mail y puede contener informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) amparada por el secreto profesional. Cualquier opinion en el contenido, es exclusiva de su autor y no representa necesariamente la opinion de Interbanking S.A. El acceso no autorizado, uso, reproduccion, o divulgacion esta prohibido. Interbanking S.A no asumira responsabilidad ni obligacion legal alguna por cualquier informacion incorrecta o alterada contenida en este mensaje. Si usted ha recibido este mensaje por error, le rogamos tenga la amabilidad de destruirlo inmediatamente junto con todas las copias del mismo, notificando al remitente. No debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni ninguna de sus partes si usted no es el destinatario. Muchas gracias. --------------------------------------------------------------------- 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]