commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/jexl/src/test/org/apache/commons/jexl JexlTest.java
Date Sun, 15 Aug 2004 16:01:12 GMT
dion        2004/08/15 09:01:12

  Modified:    jexl/xdocs changes.xml
               jexl/src/java/org/apache/commons/jexl/parser
                        ASTSizeFunction.java
               jexl/src/test/org/apache/commons/jexl JexlTest.java
  Log:
  Handle any size method that returns an int
  
  Revision  Changes    Path
  1.4       +1 -0      jakarta-commons/jexl/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/xdocs/changes.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- changes.xml	15 Aug 2004 15:46:45 -0000	1.3
  +++ changes.xml	15 Aug 2004 16:01:12 -0000	1.4
  @@ -25,6 +25,7 @@
     </properties>
     <body>
       <release version="1.0-beta-3-SNAPSHOT" date="in CVS">
  +      <action dev="dion" type="add">Handle any size() method that returns an int</action>
         <action dev="dion" type="fix" issue="30562">Can't issue .size() on java.util.Set</action>
       </release>
     </body>
  
  
  
  1.6       +20 -3     jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java
  
  Index: ASTSizeFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTSizeFunction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ASTSizeFunction.java	15 Aug 2004 15:32:52 -0000	1.5
  +++ ASTSizeFunction.java	15 Aug 2004 16:01:12 -0000	1.6
  @@ -16,6 +16,9 @@
   package org.apache.commons.jexl.parser;
   
   import org.apache.commons.jexl.JexlContext;
  +import org.apache.commons.jexl.util.Introspector;
  +import org.apache.commons.jexl.util.introspection.Info;
  +import org.apache.commons.jexl.util.introspection.VelMethod;
   
   import java.util.List;
   import java.util.Map;
  @@ -87,8 +90,22 @@
           {
               return ((Set)val).size();
           }
  -
  -        throw new Exception("size() : unknown type : " + val.getClass());
  +        else {
  +        	// check if there is a size method on the object that returns an integer
  +        	// and if so, just use it
  +        	Object[] params = new Object[0];
  +        	Info velInfo = new Info("",1,1);
  +            VelMethod vm = Introspector.getUberspect().getMethod(val, "size", params, velInfo);
  +            if (vm != null && vm.getReturnType() == Integer.TYPE)
  +            {
  +            	Integer result = (Integer)vm.invoke(val, params);
  +            	return result.intValue();
  +            }
  +            else
  +            {
  +                throw new Exception("size() : unknown type : " + val.getClass());
  +            }
  +        }
       }
   
   }
  
  
  
  1.38      +10 -2     jakarta-commons/jexl/src/test/org/apache/commons/jexl/JexlTest.java
  
  Index: JexlTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jexl/src/test/org/apache/commons/jexl/JexlTest.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- JexlTest.java	15 Aug 2004 15:32:52 -0000	1.37
  +++ JexlTest.java	15 Aug 2004 16:01:12 -0000	1.38
  @@ -16,6 +16,7 @@
   package org.apache.commons.jexl;
   
   import java.util.ArrayList;
  +import java.util.BitSet;
   import java.util.HashMap;
   import java.util.HashSet;
   import java.util.List;
  @@ -397,21 +398,28 @@
           list.add("5");
   
           jc.getVars().put("list", list);
  -        
  +
  +        // 30652 - support for set
           Set set = new HashSet();
           set.addAll(list);
           set.add("1");
           
           jc.getVars().put("set", set);
  +        
  +        // support generic int size() method
  +        BitSet bitset = new BitSet(5);
  +        jc.getVars().put("bitset", bitset);
   
           assertExpression(jc, "size(s)", new Integer(5));
           assertExpression(jc, "size(array)", new Integer(5));
           assertExpression(jc, "size(list)", new Integer(5));
           assertExpression(jc, "size(map)", new Integer(5));
           assertExpression(jc, "size(set)", new Integer(5));
  +        assertExpression(jc, "size(bitset)", new Integer(64));
           assertExpression(jc, "list.size()", new Integer(5));
           assertExpression(jc, "map.size()", new Integer(5));
           assertExpression(jc, "set.size()", new Integer(5));
  +        assertExpression(jc, "bitset.size()", new Integer(64));
   
           assertExpression(jc, "list.get(size(list) - 1)", "5");
           assertExpression(jc, "list[size(list) - 1]", "5");
  
  
  

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


Mime
View raw message