I agree with Geir.
Couldn't the original problem be resolved by doing:
#set ($names = [ 'first', 'second', 'third' ])
<PRE>$names.get($peer.Role.intValue())</PRE>
Or something like that? Or is this not possible in velocity?
Jose Alberto
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Geir Magnusson Jr.
> Sent: Wednesday, June 20, 2001 4:21 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PATCH] Array access from non-Integer, numeric types
>
>
> The problem with this slippery slope is:
>
> 1) Instead of the j.u.ArrayList that all understand, we now have this
> 'different thing' that we must document and maintain.
>
> 2) Everyone will see this as on opportunity to add support
> for their own
> class, like String.
>
> Can I ask why it returns a Byte?
>
> geir
>
>
> "Henning P. Schmiedehausen" wrote:
> >
> > Hi,
> >
> > in an application, I have a (Torque generated Turbine Peer) class,
> > which contains some methods that return numeric, non-integer types
> > (like Short or Byte). In a template I wanted to do this:
> >
> > #set ($names = [ 'first', 'second', 'third' ])
> > <PRE>$names.get($peer.Role)</PRE>
> >
> > where the getRole() method of the $peer class returns a Byte.
> >
> > This does not work in Velocity 1.1, because the internal class
> > representing the $names object array has only a get(int o) method.
> >
> > The attached patch replaces the used java.util.ArrayList
> class with an
> > inner class to ASTObjectArray. With this patch, the code above works
> > fine.
> >
> > Regards
> > Henning
> >
> > ---
> velocity-1.1.orig/src/java/org/apache/velocity/runtime/parser/
> node/ASTObjectArray.java Sat Jun 16 19:50:27 2001
> > +++
> velocity-1.1.work/src/java/org/apache/velocity/runtime/parser/
> node/ASTObjectArray.java Wed Jun 20 00:34:00 2001
> > @@ -55,8 +55,6 @@
> > * <http://www.apache.org/>.
> > */
> >
> > -import java.util.ArrayList;
> > -
> > import org.apache.velocity.context.InternalContextAdapter;
> > import org.apache.velocity.runtime.parser.Parser;
> >
> > @@ -95,4 +93,22 @@
> >
> > return objectArray;
> > }
> > +
> > + /**
> > + * Inner class that is able to de-reference any Number type
> > + * as index
> > + */
> > +
> > + public class ArrayList extends java.util.ArrayList
> > + {
> > + public Object get(Object o)
> > + throws IndexOutOfBoundsException
> > + {
> > + if(!(o instanceof Number))
> > + throw new IndexOutOfBoundsException();
> > +
> > + return this.get(((Number)o).intValue());
> > + }
> > + }
> > }
> > +
> >
> > --
> > Dipl.-Inf. (Univ.) Henning P. Schmiedehausen --
> Geschaeftsfuehrer
> > INTERMETA - Gesellschaft fuer Mehrwertdienste mbH
> [EMAIL PROTECTED]
> >
> > Am Schwabachgrund 22 Fon.: 09131 / 50654-0 [EMAIL PROTECTED]
> > D-91054 Buckenhof Fax.: 09131 / 50654-20
>
> --
> Geir Magnusson Jr. [EMAIL PROTECTED]
> System and Software Consulting
> Developing for the web? See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!
>