commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r657503 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/CollectionUtils.java test/org/apache/commons/collections/TestCollectionUtils.java
Date Sun, 18 May 2008 07:36:47 GMT
Author: bayard
Date: Sun May 18 00:36:46 2008
New Revision: 657503

URL: http://svn.apache.org/viewvc?rev=657503&view=rev
Log:
Modifying sizeIsEmpty such that null -> true and not an IllegalArgumentException as per
Benjamin Bentmann's patch to COLLECTIONS-298

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java?rev=657503&r1=657502&r2=657503&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
Sun May 18 00:36:46 2008
@@ -941,13 +941,15 @@
      * Note: This method is named to avoid clashing with
      * {@link #isEmpty(Collection)}.
      * 
-     * @param object  the object to get the size of, not null
-     * @return true if empty
-     * @throws IllegalArgumentException thrown if object is not recognised or null
+     * @param object  the object to get the size of, may be null
+     * @return true if empty or null
+     * @throws IllegalArgumentException thrown if object is not recognised
      * @since Commons Collections 3.2
      */
     public static boolean sizeIsEmpty(Object object) {
-        if (object instanceof Collection) {
+        if (object == null) {
+            return true;
+        } else if (object instanceof Collection) {
             return ((Collection) object).isEmpty();
         } else if (object instanceof Map) {
             return ((Map) object).isEmpty();
@@ -957,8 +959,6 @@
             return ((Iterator) object).hasNext() == false;
         } else if (object instanceof Enumeration) {
             return ((Enumeration) object).hasMoreElements() == false;
-        } else if (object == null) {
-            throw new IllegalArgumentException("Unsupported object type: null");
         } else {
             try {
                 return Array.getLength(object) == 0;

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java?rev=657503&r1=657502&r2=657503&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java
Sun May 18 00:36:46 2008
@@ -802,6 +802,9 @@
     }
 
     //-----------------------------------------------------------------------
+    public void testSizeIsEmpty_Null() {
+        assertEquals(true, CollectionUtils.sizeIsEmpty(null));
+    }
     public void testSizeIsEmpty_List() {
         List list = new ArrayList();
         assertEquals(true, CollectionUtils.sizeIsEmpty(list));
@@ -856,10 +859,6 @@
     }
     public void testSizeIsEmpty_Other() {
         try {
-            CollectionUtils.sizeIsEmpty(null);
-            fail("Expecting IllegalArgumentException");
-        } catch (IllegalArgumentException ex) {}
-        try {
             CollectionUtils.sizeIsEmpty("not a list");
             fail("Expecting IllegalArgumentException");
         } catch (IllegalArgumentException ex) {}



Mime
View raw message