Re: Is there a more efficient way to look up a list?

Daniel Dekany <[email protected]> Tue, 16 May 2006 20:27:15 +0200
Newsgroups gmane.comp.text.fmpp
Message-ID <[email protected]>
Tuesday, May 16, 2006, 5:27:22 PM, Bruce Perryman wrote:

> Hello. I hope that I explain this clearly enough.
>
> Let's say I have the code 'BBB' stored in 'myCode' and the following li=
st:
>
> options=3D
> [code:AAA,description:A1,text:A2,
> =A0code:BBB,description:B1,text:B2,
> =A0code:CCC,description:C1,text:C2,
> =A0code:DDD,description:D1,text:D2]
>
> I need to display the description of the code value that I have.
> What I currently do is the following:
>
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 <#list options as x>=20
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 <#if (x.code?trim=3D=3Dmycod=
e)>=A0=20
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0 ${x.description?tri=
m}
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 =A0 </#if>
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0  </#list>=A0=A0=A0=A0=A0=A0=20
>
> It seems to work. But is there a more efficient way to do this?

What about using a map where the key is the code for the options?

Also, if the <#list> solution remains, put a <#break> after the
${x.description?trim}. Unless, there can be more list items with the
same code.

--=20
Best regards,
 Daniel Dekany



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642