svn commit: r884545 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java

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

svn commit: r884545 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java

jleroux@apache.org
Author: jleroux
Date: Thu Nov 26 13:09:40 2009
New Revision: 884545

URL: http://svn.apache.org/viewvc?rev=884545&view=rev
Log:
Better version of isEmpty() with comments from Scott and Adam on dev ML.
I used one line, please feel free to comment if needed

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

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?rev=884545&r1=884544&r2=884545&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java Thu Nov 26 13:09:40 2009
@@ -753,26 +753,22 @@
         return Boolean.TRUE;
     }
 
+    @SuppressWarnings("unchecked")
     public static boolean isEmpty(Object value) {
         if (value == null) return true;
-
-        if (value instanceof String) {
-            if (((String) value).length() == 0) {
-                return true;
-            }
-        } else if (value instanceof Collection) {
-            if (((Collection<?>) value).size() == 0) {
-                return true;
-            }
-        } else if (value instanceof Map) {
-            if (((Map<?,?>) value).size() == 0) {
-                return true;
-            }
-        } else if (value instanceof CharSequence) {
-            if (((CharSequence) value).length() == 0) {
-                return true;
-            }
-        }
+        
+        if (value instanceof String) return UtilValidate.isEmpty((String) value);
+        if (value instanceof Collection) return UtilValidate.isEmpty((Collection<? extends Object>) value);
+        if (value instanceof Map) return UtilValidate.isEmpty((Map<? extends Object, ? extends Object>) value);
+        if (value instanceof CharSequence) return UtilValidate.isEmpty((CharSequence) value);
+        
+        // These types would flood the log
+        if (value instanceof Boolean) return false;        
+        if (value instanceof Integer) return false;        
+        if (value instanceof java.math.BigDecimal) return false;          
+        if (value instanceof java.sql.Timestamp) return false;        
+        
+        Debug.logWarning("In ObjectType.isEmpty(Object value) returning false for " + value.getClass() + " Object.", module);
         return false;
     }