You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Daniel Rall <dl...@finemaltcoding.com> on 2003/02/13 04:03:34 UTC

Re: Possible fix for [Bug 14711]

Mind attaching this to the issue in patch format?  `cvs diff -u
file.java > patch`.  Thanks!

"apache-velocity-dev-subscriber" <ap...@unitedplanet.de> writes:

> // The following quick fix may solve bug 14711. However it is not tested thoroughly nor we are sure if it fits in well.
> 
>     private Twonk calcDistance( Object[] set, Class[] base )
>     {
>         if ( set.length != base.length)
>             return null;
>             
>         Twonk twonk = new Twonk( set.length );
> 
>         for (int i = 0; i < set.length; i++)
>         {
>             /* 
>              * can I get from here to there?
>              */
>              
>             Class setclass = set[i].getClass();
>             
>             Class tmpclass = base[i];
> 
> 			if (tmpclass.isPrimitive())
> 			{
> 				if (tmpclass.equals(Boolean.TYPE))
> 					tmpclass = java.lang.Boolean.class;
> 				else if (tmpclass.equals(Byte.TYPE))
> 					tmpclass = java.lang.Byte.class;
> 				else if (tmpclass.equals(Character.TYPE))
> 					tmpclass = java.lang.Character.class;
> 				else if (tmpclass.equals(Double.TYPE))
> 					tmpclass = java.lang.Double.class;
> 				else if (tmpclass.equals(Float.TYPE))
> 					tmpclass = java.lang.Float.class;
> 				else if (tmpclass.equals(Integer.TYPE))
> 					tmpclass = java.lang.Integer.class;
> 				else if (tmpclass.equals(Long.TYPE))
> 					tmpclass = java.lang.Long.class;
> 				else if (tmpclass.equals(Short.TYPE))
> 					tmpclass = java.lang.Short.class;
> 			}
> 
>             if ( !tmpclass.isAssignableFrom( set[i].getClass() ))
>                 return null;
>     
>             /*
>              * ok, I can.  How many steps?
>              */
>            
>             Class c = setclass;
>                       
>             while( c != null)
>             {      
>                 /*
>                  * is this a valid step?
>                  */
>                  
>                 if ( !tmpclass.isAssignableFrom( c ) )
>                 {      
>                     /*
>                      *  it stopped being assignable - therefore we are looking at
>                      *  an interface as our target, so move back one step
>                      *  from the distance as the stop wasn't valid
>                      */
>                     break;
>                 }
>                 
>                 if(  tmpclass.equals( c ) )
>                 {
>                     /*
>                      *  we are equal, so no need to move forward
>                      */
>                      
>                     break;
>                 }
> 
>                 c = c.getSuperclass();
>                 twonk.distance++;
>                 twonk.vec[i]++;
>             }
>          }
>                 
>         return twonk;
>     }
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 

Daniel Rall <dl...@finemaltcoding.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org