You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Henning Schmiedehausen (JIRA)" <ji...@apache.org> on 2006/11/05 19:59:17 UTC

[jira] Updated: (VELOCITY-316) Workaround the lack of equality in CharSequence.

     [ http://issues.apache.org/jira/browse/VELOCITY-316?page=all ]

Henning Schmiedehausen updated VELOCITY-316:
--------------------------------------------

    Bugzilla Id:   (was: 32179)
    Component/s: Engine
                     (was: Source)

> Workaround the lack of equality in CharSequence.
> ------------------------------------------------
>
>                 Key: VELOCITY-316
>                 URL: http://issues.apache.org/jira/browse/VELOCITY-316
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: 1.4
>         Environment: Operating System: All
> Platform: All
>            Reporter: ArtemGr
>            Priority: Minor
>             Fix For: 2.0
>
>
> CharSequence is a nice addition to the Java API,
> helping to encapsulate implementation details
> and allowing programmers to use StringBuffer,
> mutable strings (such as
> http://mg4j.dsi.unimi.it/docs/it/unimi/dsi/mg4j/util/MutableString.html )
> or even their custom classes directly
> instead of costly process of converting everything into a String.
> One of the remaining drawbacks of the CharSequence
> is the lack of support for the Object#equals method.
> Fortunately, in Velocity it can be easily fixed
> in the ASTEQNode and ASTNENode classes.
> Example of the fix is provided in the following patches.
> --- org/apache/velocity/runtime/parser/node/original/ASTEQNode.java	Wed Apr 
> 14 09:26:42 2004
> +++ org/apache/velocity/runtime/parser/node/ASTEQNode.java	Thu Nov 11 14:21:
> 03 2004
> @@ -101,6 +101,20 @@
>          }
>          else
>          {
> +          
> +          /*
> +           * Comparison of CharSequence objects.
> +           */
> +          if (left instanceof CharSequence && right instanceof CharSequence)
> +          {
> +            final CharSequence a = (CharSequence) left;
> +            final CharSequence b = (CharSequence) right;
> +            final int aLen = a.length(); final int bLen = b.length();
> +            if( aLen != bLen ) return false;
> +            int n = aLen; while( 0 != n-- ) if( a.charAt( n ) != b.charAt( n ) 
> ) return false;
> +            return true;
> +          }
> +
>              rsvc.error("Error in evaluation of == expression."
>                            + " Both arguments must be of the same Class."
>                            + " Currently left = " + left.getClass() + ", right = 
> " 
> --- org/apache/velocity/runtime/parser/node/original/ASTNENode.java	Wed Apr 
> 14 09:26:42 2004
> +++ org/apache/velocity/runtime/parser/node/ASTNENode.java	Thu Nov 11 14:22:
> 04 2004
> @@ -74,6 +74,20 @@
>          }
>          else
>          {
> +          
> +          /*
> +           * Comparison of CharSequence objects.
> +           */
> +          if (left instanceof CharSequence && right instanceof CharSequence)
> +          {
> +            final CharSequence a = (CharSequence) left;
> +            final CharSequence b = (CharSequence) right;
> +            final int aLen = a.length(); final int bLen = b.length();
> +            if( aLen != bLen ) return true;
> +            int n = aLen; while( 0 != n-- ) if( a.charAt( n ) != b.charAt( n ) 
> ) return true;
> +            return false;
> +          }
> +
>              rsvc.error("Error in evaluation of != expression."
>                            + " Both arguments must be of the same Class."
>                            + " Currently left = " + left.getClass() + ", right = 
> " 
> The additional check should not have any performance impact,
> since it is performed where the 'Both arguments must be of the same Class'
> error was.
> I really hope Velocity will incorporate at least that minimal
> support for CharSequence, making Java environment
> to be a lot friendlier to some of us.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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