commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestCollectionUtils.java
Date Fri, 05 Sep 2003 02:16:33 GMT
psteitz     2003/09/04 19:16:33

  Modified:    collections/src/java/org/apache/commons/collections
                        CollectionUtils.java
               collections/src/test/org/apache/commons/collections
                        TestCollectionUtils.java
  Log:
  Fixed a javadoc error, improved efficiency and added tests for CollectionUtils.isProperSubCollection
  
  Revision  Changes    Path
  1.36      +11 -5     jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java
  
  Index: CollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- CollectionUtils.java	31 Aug 2003 17:26:44 -0000	1.35
  +++ CollectionUtils.java	5 Sep 2003 02:16:33 -0000	1.36
  @@ -282,13 +282,19 @@
        * for each element <i>e</i> in <i>a</i>, and there is at least
one
        * element <i>f</i> such that the cardinality of <i>f</i> in
<i>b</i>
        * is strictly greater than the cardinality of <i>f</i> in <i>a</i>.
  +     * <p>
  +     * The implementation assumes
  +     * <ul>
  +     *    <li><code>a.size()</code> and <code>b.size()</code>
represent the 
  +     *    total cardinality of <i>a</i> and <i>b</i>, resp. </li>
  +     *    <li><code>a.size() < Integer.MAXVALUE</code></li>
  +     * </ul></p>
        *
        * @see #isSubCollection
        * @see Collection#containsAll
        */
       public static boolean isProperSubCollection(final Collection a, final Collection b)
{
  -        // XXX optimize me!
  -        return CollectionUtils.isSubCollection(a,b) && (!(CollectionUtils.isEqualCollection(a,b)));
  +        return (a.size() < b.size()) && CollectionUtils.isSubCollection(a,b);
       }
   
       /**
  @@ -675,7 +681,7 @@
        * </ul>
        * 
        * @param obj  the object to get an index of
  -     * @param index  the index to get
  +     * @param idx  the index to get
        * @throws IndexOutOfBoundsException
        * @throws NoSuchElementException
        */
  
  
  
  1.18      +28 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java
  
  Index: TestCollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TestCollectionUtils.java	31 Aug 2003 17:28:43 -0000	1.17
  +++ TestCollectionUtils.java	5 Sep 2003 02:16:33 -0000	1.18
  @@ -411,6 +411,30 @@
           assertTrue(CollectionUtils.isEqualCollection(a,b));
           assertTrue(CollectionUtils.isEqualCollection(b,a));
       }
  +    
  +    public void testIsProperSubCollection() {
  +        Collection a = new ArrayList();
  +        Collection b = new ArrayList();
  +        assertTrue(!CollectionUtils.isProperSubCollection(a,b));
  +        b.add("1");
  +        assertTrue(CollectionUtils.isProperSubCollection(a,b));
  +        assertTrue(!CollectionUtils.isProperSubCollection(b,a));
  +        assertTrue(!CollectionUtils.isProperSubCollection(b,b));
  +        assertTrue(!CollectionUtils.isProperSubCollection(a,a));
  +        a.add("1");
  +        a.add("2");
  +        b.add("2");
  +        assertTrue(!CollectionUtils.isProperSubCollection(b,a));
  +        assertTrue(!CollectionUtils.isProperSubCollection(a,b));
  +        a.add("1");
  +        assertTrue(CollectionUtils.isProperSubCollection(b,a));
  +        assertTrue(CollectionUtils.isProperSubCollection(
  +            CollectionUtils.intersection(_a, _b), _a));
  +        assertTrue(CollectionUtils.isProperSubCollection(
  +            CollectionUtils.subtract(a, b), a));
  +        assertTrue(!CollectionUtils.isProperSubCollection(
  +            a, CollectionUtils.subtract(a, b)));
  +    }
   
   
       public void testIndex() {
  
  
  

Mime
View raw message