Fix formatting
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131828 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a8e5d5380
commit
2e2ac4ba93
|
@ -38,7 +38,7 @@ import org.apache.commons.collections.collection.UnmodifiableCollection;
|
|||
* Provides utility methods and decorators for {@link Collection} instances.
|
||||
*
|
||||
* @since Commons Collections 1.0
|
||||
* @version $Revision: 1.63 $ $Date: 2004/12/11 06:30:38 $
|
||||
* @version $Revision: 1.64 $ $Date: 2004/12/19 16:56:30 $
|
||||
*
|
||||
* @author Rodney Waldhoff
|
||||
* @author Paul Jack
|
||||
|
@ -55,7 +55,7 @@ import org.apache.commons.collections.collection.UnmodifiableCollection;
|
|||
*/
|
||||
public class CollectionUtils {
|
||||
|
||||
/** Constant to avoid repeated object creation */
|
||||
/** Constant to avoid repeated object creation */
|
||||
private static Integer INTEGER_ONE = new Integer(1);
|
||||
|
||||
/**
|
||||
|
@ -1049,22 +1049,23 @@ public class CollectionUtils {
|
|||
return UnmodifiableCollection.decorate(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable copy of the collection.
|
||||
* <p>
|
||||
/**
|
||||
* Returns an unmodifiable copy of the collection.
|
||||
* <p>
|
||||
* This method uses the implementation in the decorators subpackage.
|
||||
*
|
||||
* @param collection the <code>Collection</code> to copy.
|
||||
* @return an unmodifiable <code>Collection</code>.
|
||||
* @throws IllegalArgumentException if collection is null
|
||||
*/
|
||||
public static Collection unmodifiableCollectionCopy(final Collection collection){
|
||||
if (collection == null) throw new IllegalArgumentException("null not permitted.");
|
||||
* @param collection the <code>Collection</code> to copy.
|
||||
* @return an unmodifiable <code>Collection</code>.
|
||||
* @throws IllegalArgumentException if collection is null
|
||||
*/
|
||||
public static Collection unmodifiableCollectionCopy(final Collection collection){
|
||||
if (collection == null) throw new IllegalArgumentException("null not permitted.");
|
||||
|
||||
final Collection copy = new ArrayList(collection.size());
|
||||
copy.addAll(collection);
|
||||
return UnmodifiableCollection.decorate(copy);
|
||||
}
|
||||
|
||||
final Collection copy = new ArrayList(collection.size());
|
||||
copy.addAll(collection);
|
||||
return UnmodifiableCollection.decorate(copy);
|
||||
}
|
||||
/**
|
||||
* Returns a predicated (validating) collection backed by the given collection.
|
||||
* <p>
|
||||
|
@ -1111,42 +1112,41 @@ public class CollectionUtils {
|
|||
return TransformedCollection.decorate(collection, transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection containing all the elements in <code>collection</code>
|
||||
* that are also in <code>retain</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned collection is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>retain</code> does not contain <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* the collection <code>c</code> and thus cannot call <code>c.retainAll(retain);</code>.
|
||||
*
|
||||
* @param collection the collection whose contents are the target of the #retailAll operation
|
||||
* @param retain the collection containing the elements to be retained in the returned collection
|
||||
* @return a <code>Collection</code> containing all the elements of <code>collection</code>
|
||||
* that occur at least once in <code>retain</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static Collection retainAll(final Collection collection, final Collection retain) {
|
||||
return ListUtils.retainAll(collection, retain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the elements in <code>remove</code> from <code>collection</code>. That is, this
|
||||
* method returns a collection containing all the elements in <code>c</code>
|
||||
* that are not in <code>remove</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned collection is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>remove</code> contains <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* the collection <code>c</code> and thus cannot call <code>collection.removeAll(remove);</code>.
|
||||
*
|
||||
* @param collection the collection from which items are removed (in the returned collection)
|
||||
* @param remove the items to be removed from the returned <code>collection</code>
|
||||
* @return a <code>Collection</code> containing all the elements of <code>collection</code> except
|
||||
* any elements that also occur in <code>remove</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static Collection removeAll(final Collection collection, final Collection remove) {
|
||||
return ListUtils.retainAll(collection, remove);
|
||||
}
|
||||
/**
|
||||
* Returns a collection containing all the elements in <code>collection</code>
|
||||
* that are also in <code>retain</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned collection is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>retain</code> does not contain <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* the collection <code>c</code> and thus cannot call <code>c.retainAll(retain);</code>.
|
||||
*
|
||||
* @param collection the collection whose contents are the target of the #retailAll operation
|
||||
* @param retain the collection containing the elements to be retained in the returned collection
|
||||
* @return a <code>Collection</code> containing all the elements of <code>collection</code>
|
||||
* that occur at least once in <code>retain</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static Collection retainAll(Collection collection, Collection retain) {
|
||||
return ListUtils.retainAll(collection, retain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the elements in <code>remove</code> from <code>collection</code>. That is, this
|
||||
* method returns a collection containing all the elements in <code>c</code>
|
||||
* that are not in <code>remove</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned collection is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>remove</code> contains <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* the collection <code>c</code> and thus cannot call <code>collection.removeAll(remove);</code>.
|
||||
*
|
||||
* @param collection the collection from which items are removed (in the returned collection)
|
||||
* @param remove the items to be removed from the returned <code>collection</code>
|
||||
* @return a <code>Collection</code> containing all the elements of <code>collection</code> except
|
||||
* any elements that also occur in <code>remove</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static Collection removeAll(Collection collection, Collection remove) {
|
||||
return ListUtils.retainAll(collection, remove);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.commons.collections.list.UnmodifiableList;
|
|||
* Provides utility methods and decorators for {@link List} instances.
|
||||
*
|
||||
* @since Commons Collections 1.0
|
||||
* @version $Revision: 1.29 $ $Date: 2004/12/11 06:22:58 $
|
||||
* @version $Revision: 1.30 $ $Date: 2004/12/19 16:56:30 $
|
||||
*
|
||||
* @author Federico Barbieri
|
||||
* @author Peter Donald
|
||||
|
@ -259,21 +259,21 @@ public class ListUtils {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list copy of the collection.
|
||||
* <p>
|
||||
* This method uses the unmodifiable list implementation in the decorators subpackage.
|
||||
* @param collection the <code>Collection</code> to copy.
|
||||
* @return an unmodifiable <code>List</code>.
|
||||
* @throws IllegalArgumentException if collection is null.
|
||||
*/
|
||||
public static List unmodifiableListCopy(final Collection collection) {
|
||||
if (collection == null) throw new IllegalArgumentException("null not permitted.");
|
||||
/**
|
||||
* Returns an unmodifiable list copy of the collection.
|
||||
* <p>
|
||||
* This method uses the unmodifiable list implementation in the decorators subpackage.
|
||||
* @param collection the <code>Collection</code> to copy.
|
||||
* @return an unmodifiable <code>List</code>.
|
||||
* @throws IllegalArgumentException if collection is null.
|
||||
*/
|
||||
public static List unmodifiableListCopy(final Collection collection) {
|
||||
if (collection == null) throw new IllegalArgumentException("null not permitted.");
|
||||
|
||||
final List copy = new ArrayList(collection.size());
|
||||
copy.addAll(collection);
|
||||
return UnmodifiableList.decorate(copy);
|
||||
}
|
||||
final List copy = new ArrayList(collection.size());
|
||||
copy.addAll(collection);
|
||||
return UnmodifiableList.decorate(copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicated (validating) list backed by the given list.
|
||||
|
@ -369,65 +369,55 @@ public class ListUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a List containing all the elements in <code>collection</code>
|
||||
* that are also in <code>retain</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned list is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>retain</code> does not contain <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* the collection <code>c</code> and thus cannot call <code>collection.retainAll(retain);</code>.
|
||||
*
|
||||
* @param collection the collection whose contents are the target of the #retailAll operation
|
||||
* @param retain the collection containing the elements to be retained in the returned collection
|
||||
* @return a <code>List</code> containing all the elements of <code>c</code>
|
||||
* that occur at least once in <code>retain</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static List retainAll(final Collection collection, final Collection retain) {
|
||||
final List list = new ArrayList(Math.min(collection.size(), retain.size()));
|
||||
* Returns a List containing all the elements in <code>collection</code>
|
||||
* that are also in <code>retain</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned list is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>retain</code> does not contain <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* the collection <code>c</code> and thus cannot call <code>collection.retainAll(retain);</code>.
|
||||
*
|
||||
* @param collection the collection whose contents are the target of the #retailAll operation
|
||||
* @param retain the collection containing the elements to be retained in the returned collection
|
||||
* @return a <code>List</code> containing all the elements of <code>c</code>
|
||||
* that occur at least once in <code>retain</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static List retainAll(Collection collection, Collection retain) {
|
||||
List list = new ArrayList(Math.min(collection.size(), retain.size()));
|
||||
|
||||
Object item = null;
|
||||
for (final Iterator iter = collection.iterator(); iter.hasNext();)
|
||||
{
|
||||
item = iter.next();
|
||||
for (Iterator iter = collection.iterator(); iter.hasNext();) {
|
||||
Object obj = iter.next();
|
||||
if (retain.contains(obj)) {
|
||||
list.add(obj);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
if (retain.contains(item))
|
||||
{
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the elements in <code>remove</code> from <code>collection</code>. That is, this
|
||||
* method returns a list containing all the elements in <code>c</code>
|
||||
* that are not in <code>remove</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned collection is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>remove</code> contains <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* <code>collection</code> and thus cannot call <code>collection.removeAll(remove);</code>.
|
||||
*
|
||||
* @param collection the collection from which items are removed (in the returned collection)
|
||||
* @param remove the items to be removed from the returned <code>collection</code>
|
||||
* @return a <code>List</code> containing all the elements of <code>c</code> except
|
||||
* any elements that also occur in <code>remove</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static List removeAll(final Collection collection, final Collection remove) {
|
||||
final List list = new ArrayList();
|
||||
|
||||
Object o = null;
|
||||
for (final Iterator iter = collection.iterator(); iter.hasNext();)
|
||||
{
|
||||
o = iter.next();
|
||||
if (remove.contains(o) == false)
|
||||
{
|
||||
list.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* Removes the elements in <code>remove</code> from <code>collection</code>. That is, this
|
||||
* method returns a list containing all the elements in <code>c</code>
|
||||
* that are not in <code>remove</code>. The cardinality of an element <code>e</code>
|
||||
* in the returned collection is the same as the cardinality of <code>e</code>
|
||||
* in <code>collection</code> unless <code>remove</code> contains <code>e</code>, in which
|
||||
* case the cardinality is zero. This method is useful if you do not wish to modify
|
||||
* <code>collection</code> and thus cannot call <code>collection.removeAll(remove);</code>.
|
||||
*
|
||||
* @param collection the collection from which items are removed (in the returned collection)
|
||||
* @param remove the items to be removed from the returned <code>collection</code>
|
||||
* @return a <code>List</code> containing all the elements of <code>c</code> except
|
||||
* any elements that also occur in <code>remove</code>.
|
||||
* @throws NullPointerException if either parameter is null
|
||||
*/
|
||||
public static List removeAll(Collection collection, Collection remove) {
|
||||
List list = new ArrayList();
|
||||
for (Iterator iter = collection.iterator(); iter.hasNext();) {
|
||||
Object obj = iter.next();
|
||||
if (remove.contains(obj) == false) {
|
||||
list.add(obj);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ import org.apache.commons.collections.map.UnmodifiableSortedMap;
|
|||
* </ul>
|
||||
*
|
||||
* @since Commons Collections 1.0
|
||||
* @version $Revision: 1.50 $ $Date: 2004/12/11 06:26:13 $
|
||||
* @version $Revision: 1.51 $ $Date: 2004/12/19 16:56:30 $
|
||||
*
|
||||
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
|
||||
* @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
|
||||
|
@ -1222,19 +1222,19 @@ public class MapUtils {
|
|||
return UnmodifiableMap.decorate(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable copy of the map.
|
||||
/**
|
||||
* Returns an unmodifiable copy of the map.
|
||||
* @param map the map to make an unmodifiable copy of, must not be null
|
||||
* @return an unmodifiable map backed by the given map
|
||||
* @throws IllegalArgumentException if the map is null
|
||||
*/
|
||||
public static Map unmodifiableMapCopy(final Map map) {
|
||||
if (map == null) throw new IllegalArgumentException("null not permitted.");
|
||||
*/
|
||||
public static Map unmodifiableMapCopy(Map map) {
|
||||
if (map == null) throw new IllegalArgumentException("null not permitted.");
|
||||
|
||||
final Map copy = new HashMap(map.size(), 1.0f);
|
||||
copy.putAll(map);
|
||||
return MapUtils.unmodifiableMap(copy);
|
||||
}
|
||||
Map copy = new HashMap(map.size(), 1.0f);
|
||||
copy.putAll(map);
|
||||
return MapUtils.unmodifiableMap(copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicated (validating) map backed by the given map.
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.apache.commons.collections;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -52,7 +51,7 @@ import org.apache.commons.collections.collection.UnmodifiableCollection;
|
|||
* @author Steven Melzer
|
||||
* @author Neil O'Toole
|
||||
*
|
||||
* @version $Revision: 1.42 $ $Date: 2004/12/11 06:30:38 $
|
||||
* @version $Revision: 1.43 $ $Date: 2004/12/19 16:56:31 $
|
||||
*/
|
||||
public class TestCollectionUtils extends TestCase {
|
||||
|
||||
|
@ -1198,30 +1197,26 @@ public class TestCollectionUtils extends TestCase {
|
|||
}
|
||||
|
||||
public void testUnmodifiableCollectionCopy() {
|
||||
Collection collection = new ArrayList();
|
||||
collection.add("a");
|
||||
Collection copy = CollectionUtils.unmodifiableCollectionCopy(collection);
|
||||
Collection collection = new ArrayList();
|
||||
collection.add("a");
|
||||
Collection copy = CollectionUtils.unmodifiableCollectionCopy(collection);
|
||||
|
||||
assertTrue(copy instanceof Unmodifiable);
|
||||
assertTrue(CollectionUtils.isEqualCollection(collection, copy));
|
||||
collection.clear();
|
||||
assertTrue(copy.isEmpty() == false);
|
||||
assertTrue(copy instanceof Unmodifiable);
|
||||
assertTrue(CollectionUtils.isEqualCollection(collection, copy));
|
||||
collection.clear();
|
||||
assertTrue(copy.isEmpty() == false);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
copy.clear();
|
||||
fail("should be unmodifiable.");
|
||||
}
|
||||
catch (UnsupportedOperationException uoe)
|
||||
{} // this is what we want
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
} // this is what we want
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
copy = CollectionUtils.unmodifiableCollectionCopy(null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
}
|
||||
catch(IllegalArgumentException iae)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.commons.collections.list.PredicatedList;
|
|||
/**
|
||||
* Tests for ListUtils.
|
||||
*
|
||||
* @version $Revision: 1.20 $ $Date: 2004/12/11 06:24:10 $
|
||||
* @version $Revision: 1.21 $ $Date: 2004/12/19 16:56:31 $
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
* @author Neil O'Toole
|
||||
|
@ -35,17 +35,17 @@ import org.apache.commons.collections.list.PredicatedList;
|
|||
*/
|
||||
public class TestListUtils extends BulkTest {
|
||||
|
||||
private static final String a = "a";
|
||||
private static final String b = "b";
|
||||
private static final String c = "c";
|
||||
private static final String d = "d";
|
||||
private static final String e = "e";
|
||||
private static final String x = "x";
|
||||
private static final String a = "a";
|
||||
private static final String b = "b";
|
||||
private static final String c = "c";
|
||||
private static final String d = "d";
|
||||
private static final String e = "e";
|
||||
private static final String x = "x";
|
||||
|
||||
private String[] fullArray;
|
||||
private List fullList;
|
||||
private String[] fullArray;
|
||||
private List fullList;
|
||||
|
||||
public TestListUtils(String name) {
|
||||
public TestListUtils(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
@ -53,10 +53,10 @@ public class TestListUtils extends BulkTest {
|
|||
return BulkTest.makeSuite(TestListUtils.class);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
fullArray = new String[]{a, b, c, d, e};
|
||||
fullList = new ArrayList(Arrays.asList(fullArray));
|
||||
}
|
||||
public void setUp() {
|
||||
fullArray = new String[]{a, b, c, d, e};
|
||||
fullList = new ArrayList(Arrays.asList(fullArray));
|
||||
}
|
||||
|
||||
|
||||
public void testNothing() {
|
||||
|
@ -106,11 +106,11 @@ public class TestListUtils extends BulkTest {
|
|||
assertEquals(6, list.size());
|
||||
}
|
||||
|
||||
public void testEquals() {
|
||||
Collection data = Arrays.asList( new String[] { "a", "b", "c" });
|
||||
public void testEquals() {
|
||||
Collection data = Arrays.asList( new String[] { "a", "b", "c" });
|
||||
|
||||
List a = new ArrayList( data );
|
||||
List b = new ArrayList( data );
|
||||
List a = new ArrayList( data );
|
||||
List b = new ArrayList( data );
|
||||
|
||||
assertEquals(true, a.equals(b));
|
||||
assertEquals(true, ListUtils.isEqualList(a, b));
|
||||
|
@ -119,13 +119,13 @@ public class TestListUtils extends BulkTest {
|
|||
assertEquals(false, ListUtils.isEqualList(a, null));
|
||||
assertEquals(false, ListUtils.isEqualList(null, b));
|
||||
assertEquals(true, ListUtils.isEqualList(null, null));
|
||||
}
|
||||
}
|
||||
|
||||
public void testHashCode() {
|
||||
Collection data = Arrays.asList( new String[] { "a", "b", "c" });
|
||||
public void testHashCode() {
|
||||
Collection data = Arrays.asList( new String[] { "a", "b", "c" });
|
||||
|
||||
List a = new ArrayList( data );
|
||||
List b = new ArrayList( data );
|
||||
List a = new ArrayList( data );
|
||||
List b = new ArrayList( data );
|
||||
|
||||
assertEquals(true, a.hashCode() == b.hashCode());
|
||||
assertEquals(true, a.hashCode() == ListUtils.hashCodeForList(a));
|
||||
|
@ -134,79 +134,67 @@ public class TestListUtils extends BulkTest {
|
|||
a.clear();
|
||||
assertEquals(false, ListUtils.hashCodeForList(a) == ListUtils.hashCodeForList(b));
|
||||
assertEquals(0, ListUtils.hashCodeForList(null));
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnmodifiableListCopy() {
|
||||
List list = new ArrayList();
|
||||
list.add("a");
|
||||
List copy = ListUtils.unmodifiableListCopy(list);
|
||||
public void testUnmodifiableListCopy() {
|
||||
List list = new ArrayList();
|
||||
list.add("a");
|
||||
List copy = ListUtils.unmodifiableListCopy(list);
|
||||
|
||||
assertTrue(copy instanceof Unmodifiable);
|
||||
assertTrue(list.equals(copy));
|
||||
list.clear();
|
||||
assertTrue(copy.isEmpty() == false);
|
||||
assertTrue(copy instanceof Unmodifiable);
|
||||
assertTrue(list.equals(copy));
|
||||
list.clear();
|
||||
assertTrue(copy.isEmpty() == false);
|
||||
|
||||
try
|
||||
{
|
||||
copy.clear();
|
||||
fail("should be unmodifiable.");
|
||||
}
|
||||
catch (UnsupportedOperationException uoe)
|
||||
{
|
||||
// this is what we want
|
||||
}
|
||||
try {
|
||||
copy.clear();
|
||||
fail("should be unmodifiable.");
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// this is what we want
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
list = ListUtils.unmodifiableListCopy(null);
|
||||
fail("expecting IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
// this is what we want
|
||||
}
|
||||
}
|
||||
try {
|
||||
list = ListUtils.unmodifiableListCopy(null);
|
||||
fail("expecting IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// this is what we want
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetainAll() {
|
||||
List sub = new ArrayList();
|
||||
sub.add(a);
|
||||
sub.add(b);
|
||||
sub.add(x);
|
||||
public void testRetainAll() {
|
||||
List sub = new ArrayList();
|
||||
sub.add(a);
|
||||
sub.add(b);
|
||||
sub.add(x);
|
||||
|
||||
List retained = ListUtils.retainAll(fullList, sub);
|
||||
assertTrue(retained.size() == 2);
|
||||
sub.remove(x);
|
||||
assertTrue(retained.equals(sub));
|
||||
fullList.retainAll(sub);
|
||||
assertTrue(retained.equals(fullList));
|
||||
List retained = ListUtils.retainAll(fullList, sub);
|
||||
assertTrue(retained.size() == 2);
|
||||
sub.remove(x);
|
||||
assertTrue(retained.equals(sub));
|
||||
fullList.retainAll(sub);
|
||||
assertTrue(retained.equals(fullList));
|
||||
|
||||
try
|
||||
{
|
||||
List list = ListUtils.retainAll(null, null);
|
||||
fail("expecting NullPointerException");
|
||||
}
|
||||
catch(NullPointerException npe)
|
||||
{} // this is what we want
|
||||
}
|
||||
try {
|
||||
List list = ListUtils.retainAll(null, null);
|
||||
fail("expecting NullPointerException");
|
||||
} catch(NullPointerException npe){} // this is what we want
|
||||
}
|
||||
|
||||
public void testRemoveAll() {
|
||||
List sub = new ArrayList();
|
||||
sub.add(a);
|
||||
sub.add(b);
|
||||
sub.add(x);
|
||||
public void testRemoveAll() {
|
||||
List sub = new ArrayList();
|
||||
sub.add(a);
|
||||
sub.add(b);
|
||||
sub.add(x);
|
||||
|
||||
List remainder = ListUtils.removeAll(fullList, sub);
|
||||
assertTrue(remainder.size() == 3);
|
||||
fullList.removeAll(sub);
|
||||
assertTrue(remainder.equals(fullList));
|
||||
List remainder = ListUtils.removeAll(fullList, sub);
|
||||
assertTrue(remainder.size() == 3);
|
||||
fullList.removeAll(sub);
|
||||
assertTrue(remainder.equals(fullList));
|
||||
|
||||
try
|
||||
{
|
||||
List list = ListUtils.removeAll(null, null);
|
||||
fail("expecting NullPointerException");
|
||||
}
|
||||
catch(NullPointerException npe)
|
||||
{} // this is what we want
|
||||
}
|
||||
try {
|
||||
List list = ListUtils.removeAll(null, null);
|
||||
fail("expecting NullPointerException");
|
||||
} catch(NullPointerException npe) {} // this is what we want
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.commons.collections.map.TestPredicatedMap;
|
|||
/**
|
||||
* Tests for MapUtils.
|
||||
*
|
||||
* @version $Revision: 1.25 $ $Date: 2004/12/11 06:26:13 $
|
||||
* @version $Revision: 1.26 $ $Date: 2004/12/19 16:56:31 $
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
* @author Arun Mammen Thomas
|
||||
|
@ -771,36 +771,30 @@ public class TestMapUtils extends BulkTest {
|
|||
assertEquals(EXPECTED_OUT, out.toString());
|
||||
}
|
||||
|
||||
public void testUnmodifiableMapCopy() {
|
||||
Map map = new HashMap();
|
||||
map.put("key", "value");
|
||||
public void testUnmodifiableMapCopy() {
|
||||
Map map = new HashMap();
|
||||
map.put("key", "value");
|
||||
|
||||
Map copy = MapUtils.unmodifiableMapCopy(map);
|
||||
assertTrue(copy instanceof Unmodifiable);
|
||||
assertEquals(map, copy);
|
||||
map.clear();
|
||||
assertFalse(map.equals(copy));
|
||||
Map copy = MapUtils.unmodifiableMapCopy(map);
|
||||
assertTrue(copy instanceof Unmodifiable);
|
||||
assertEquals(map, copy);
|
||||
map.clear();
|
||||
assertFalse(map.equals(copy));
|
||||
|
||||
try
|
||||
{
|
||||
copy.clear();
|
||||
fail("should be unmodifiable.");
|
||||
}
|
||||
catch (UnsupportedOperationException uoe)
|
||||
{
|
||||
// this is what we want
|
||||
}
|
||||
try {
|
||||
copy.clear();
|
||||
fail("should be unmodifiable.");
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// this is what we want
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
map = MapUtils.unmodifiableMapCopy(null);
|
||||
fail("expecting IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
// this is what we want
|
||||
}
|
||||
try {
|
||||
map = MapUtils.unmodifiableMapCopy(null);
|
||||
fail("expecting IllegalArgumentException");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// this is what we want
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue