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!

Reply via email to