Fixed a javadoc error, improved efficiency and added tests for CollectionUtils.isProperSubCollection
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131133 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
541dca188d
commit
2c106dd4ea
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.35 2003/08/31 17:26:44 scolebourne Exp $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.36 2003/09/05 02:16:33 psteitz Exp $
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
|
@ -81,7 +81,7 @@ import org.apache.commons.collections.iterators.EnumerationIterator;
|
|||
* A set of {@link Collection} related utility methods.
|
||||
*
|
||||
* @since Commons Collections 1.0
|
||||
* @version $Revision: 1.35 $ $Date: 2003/08/31 17:26:44 $
|
||||
* @version $Revision: 1.36 $ $Date: 2003/09/05 02:16:33 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
* @author Paul Jack
|
||||
|
@ -282,13 +282,19 @@ public class CollectionUtils {
|
|||
* 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 @@ public class CollectionUtils {
|
|||
* </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,7 +1,7 @@
|
|||
/*
|
||||
* $Id: TestCollectionUtils.java,v 1.17 2003/08/31 17:28:43 scolebourne Exp $
|
||||
* $Revision: 1.17 $
|
||||
* $Date: 2003/08/31 17:28:43 $
|
||||
* $Id: TestCollectionUtils.java,v 1.18 2003/09/05 02:16:33 psteitz Exp $
|
||||
* $Revision: 1.18 $
|
||||
* $Date: 2003/09/05 02:16:33 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -81,7 +81,7 @@ import junit.framework.TestSuite;
|
|||
* @author Matthew Hawthorne
|
||||
* @author Stephen Colebourne
|
||||
*
|
||||
* @version $Revision: 1.17 $ $Date: 2003/08/31 17:28:43 $
|
||||
* @version $Revision: 1.18 $ $Date: 2003/09/05 02:16:33 $
|
||||
*/
|
||||
public class TestCollectionUtils extends TestCase {
|
||||
public TestCollectionUtils(String testName) {
|
||||
|
@ -411,6 +411,30 @@ public class TestCollectionUtils extends TestCase {
|
|||
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() {
|
||||
|
|
Loading…
Reference in New Issue