svn commit: r591093 - /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r591093 - /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java

doogie-3
Author: doogie
Date: Thu Nov  1 10:24:41 2007
New Revision: 591093

URL: http://svn.apache.org/viewvc?rev=591093&view=rev
Log:
Allow null keys/values in collections/maps.

Modified:
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java?rev=591093&r1=591092&r2=591093&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilGenerics.java Thu Nov  1 10:24:41 2007
@@ -38,7 +38,7 @@
             if (!(clz.isInstance(object))) throw new ClassCastException("Not a " + clz.getName());
             int i = 0;
             for (Object value: (Collection) object) {
-                if (!type.isInstance(value)) {
+                if (value != null && !type.isInstance(value)) {
                     throw new IllegalArgumentException("Value(" + i + "), with value(" + value + ") is not a " + type.getName());
                 }
                 i++;
@@ -75,10 +75,10 @@
             Map<?, ?> map = (Map) object;
             int i = 0;
             for (Map.Entry<?, ?> entry: map.entrySet()) {
-                if (!keyType.isInstance(entry.getKey())) {
+                if (entry.getKey() != null && !keyType.isInstance(entry.getKey())) {
                     throw new IllegalArgumentException("Key(" + i + "), with value(" + entry.getKey() + ") is not a " + keyType);
                 }
-                if (!valueType.isInstance(entry.getValue())) {
+                if (entry.getValue() != null && !valueType.isInstance(entry.getValue())) {
                     throw new IllegalArgumentException("Value(" + i + "), with value(" + entry.getValue() + ") is not a " + valueType);
                 }
                 i++;
@@ -106,10 +106,10 @@
         Map<K, V> map = FastMap.newInstance();
         for (int i = 0; i < data.length; ) {
             Object key = data[i];
-            if (!(keyType.isInstance(key))) throw new IllegalArgumentException("Key(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
+            if (key != null && !(keyType.isInstance(key))) throw new IllegalArgumentException("Key(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
             i++;
             Object value = data[i];
-            if (!(valueType.isInstance(value))) throw new IllegalArgumentException("Value(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
+            if (value != null && !(valueType.isInstance(value))) throw new IllegalArgumentException("Value(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
             i++;
             map.put(keyType.cast(key), valueType.cast(value));
         }
@@ -126,7 +126,7 @@
         Map<K, Object> map = FastMap.newInstance();
         for (int i = 0; i < data.length; ) {
             Object key = data[i];
-            if (!(keyType.isInstance(key))) throw new IllegalArgumentException("Key(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
+            if (key != null && !(keyType.isInstance(key))) throw new IllegalArgumentException("Key(" + i + ") is not a " + keyType.getName() + ", was(" + key.getClass().getName() + ")");
             i++;
             Object value = data[i];
             map.put(keyType.cast(key), value);