You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ge...@apache.org on 2003/06/25 12:51:44 UTC
cvs commit: jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser ASTSizeFunction.java
geirm 2003/06/25 03:51:44
Modified: jexl/src/java/org/apache/commons/jexl/parser
ASTSizeFunction.java
Log:
patch from mark wilkinson - size () fix
Revision Changes Path
1.2 +15 -7 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ASTSizeFunction.java 26 Apr 2002 04:23:14 -0000 1.1
+++ ASTSizeFunction.java 25 Jun 2003 10:51:44 -0000 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,6 +63,7 @@
* generalized size() function for all classes we can think of
*
* @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @author <a href="hw@kremvax.net">Mark H. Wilkinson</a>
* @version $Id$
*/
public class ASTSizeFunction extends SimpleNode
@@ -96,21 +97,28 @@
{
throw new Exception("size() : null arg");
}
- else if (val instanceof List)
+
+ return new Integer(ASTSizeFunction.sizeOf(val));
+ }
+
+ public static int sizeOf(Object val)
+ throws Exception
+ {
+ if (val instanceof List)
{
- return new Integer(((List)val).size());
+ return ((List)val).size();
}
else if (val.getClass().isArray())
{
- return new Integer(Array.getLength(val));
+ return Array.getLength(val);
}
else if (val instanceof Map)
{
- return new Integer(((Map)val).size());
+ return ((Map)val).size();
}
else if (val instanceof String)
{
- return new Integer(((String)val).length());
+ return ((String)val).length();
}
throw new Exception("size() : unknown type : " + val.getClass());
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org