You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2007/12/12 00:24:14 UTC

svn commit: r603412 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java

Author: mbenson
Date: Tue Dec 11 15:24:10 2007
New Revision: 603412

URL: http://svn.apache.org/viewvc?rev=603412&view=rev
Log:
[JXPATH-108] count nodes in a NodeSet

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java?rev=603412&r1=603411&r2=603412&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java (original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java Tue Dec 11 15:24:10 2007
@@ -319,6 +319,9 @@
         else if (value instanceof Collection) {
             count = ((Collection) value).size();
         }
+        else if (value instanceof NodeSet) {
+            count = ((NodeSet) value).getPointers().size();
+        }
         else if (value == null) {
             count = 0;
         }

Modified: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java?rev=603412&r1=603411&r2=603412&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java (original)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java Tue Dec 11 15:24:10 2007
@@ -372,6 +372,8 @@
             "test:nodeSet()/@name",
             "Name 1",
             "/beans[1]/@name");
+
+        assertEquals(2, ((Number) context.getValue("count(test:nodeSet())")).intValue());
     }
 
     public void testEstablishNodeSetBaseline() {