You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/11/05 16:20:12 UTC
svn commit: r592040 -
/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
Author: jstrachan
Date: Mon Nov 5 07:20:11 2007
New Revision: 592040
URL: http://svn.apache.org/viewvc?rev=592040&view=rev
Log:
added a test case and fix for http://issues.apache.org/activemq/browse/CAMEL-206
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java?rev=592040&r1=592039&r2=592040&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java Mon Nov 5 07:20:11 2007
@@ -16,10 +16,14 @@
*/
package org.apache.camel.util;
+import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.w3c.dom.NodeList;
+
/**
* A number of helper methods for working with collections
*
@@ -32,7 +36,35 @@
*/
private CollectionHelper() {
}
-
+
+ /**
+ * Returns the size of the collection if it can be determined to be a collection
+ */
+ public static Integer size(Object value) {
+ if (value != null) {
+ if (value instanceof Collection) {
+ Collection collection = (Collection) value;
+ return collection.size();
+ }
+ else if (value instanceof Map) {
+ Map map = (Map) value;
+ return map.size();
+ }
+ else if (value instanceof Object[]) {
+ Object[] array = (Object[]) value;
+ return array.length;
+ }
+ else if (value.getClass().isArray()) {
+ return Array.getLength(value);
+ }
+ else if (value instanceof NodeList) {
+ NodeList nodeList = (NodeList) value;
+ return nodeList.getLength();
+ }
+ }
+ return null;
+ }
+
/**
* Sets the value of the entry in the map for the given key, though if the
* map already contains a value for the given key then the value is appended