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