You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2007/07/13 12:39:28 UTC
svn commit: r555925 - in
/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src:
java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/
java/org/apache/commons/collections/buffer/
java/org/apache/commons/collect...
Author: skestle
Date: Fri Jul 13 03:39:24 2007
New Revision: 555925
URL: http://svn.apache.org/viewvc?view=rev&rev=555925
Log:
Added Edwin Tellman's patch for COLLECTIONS-243.
It all seems pretty reasonable, and it should all be checked again as the project is worked through
Modified:
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/Bag.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BagUtils.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ListUtils.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/SetUtils.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractBagDecorator.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedBag.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedSortedBag.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/PredicatedBuffer.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/PredicatedList.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/SynchronizedList.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSet.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSortedSet.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSet.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSortedSet.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java
jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestListUtils.java
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/Bag.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/Bag.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/Bag.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/Bag.java Fri Jul 13 03:39:24 2007
@@ -55,7 +55,7 @@
* @param object the object to search for
* @return the number of occurrences of the object, zero if not found
*/
- int getCount(E object);
+ int getCount(Object object);
/**
* <i>(Violation)</i>
@@ -112,7 +112,7 @@
* @param nCopies the number of copies to remove
* @return <code>true</code> if this call changed the collection
*/
- boolean remove(E object, int nCopies);
+ boolean remove(Object object, int nCopies);
/**
* Returns a {@link Set} of unique elements in the Bag.
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BagUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BagUtils.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BagUtils.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BagUtils.java Fri Jul 13 03:39:24 2007
@@ -85,7 +85,7 @@
* @return a synchronized bag backed by that bag
* @throws IllegalArgumentException if the Bag is null
*/
- public static Bag synchronizedBag(Bag bag) {
+ public static <E> Bag<E> synchronizedBag(Bag<E> bag) {
return SynchronizedBag.decorate(bag);
}
@@ -98,7 +98,7 @@
* @return an unmodifiable view of that bag
* @throws IllegalArgumentException if the Bag is null
*/
- public static Bag unmodifiableBag(Bag bag) {
+ public static <E> Bag<E> unmodifiableBag(Bag<E> bag) {
return UnmodifiableBag.decorate(bag);
}
@@ -115,7 +115,7 @@
* @return a predicated bag backed by the given bag
* @throws IllegalArgumentException if the Bag or Predicate is null
*/
- public static Bag predicatedBag(Bag bag, Predicate predicate) {
+ public static <E> Bag<E> predicatedBag(Bag<E> bag, Predicate<? super E> predicate) {
return PredicatedBag.decorate(bag, predicate);
}
@@ -163,7 +163,7 @@
* @return a synchronized bag backed by that bag
* @throws IllegalArgumentException if the SortedBag is null
*/
- public static SortedBag synchronizedSortedBag(SortedBag bag) {
+ public static <E> SortedBag<E> synchronizedSortedBag(SortedBag<E> bag) {
return SynchronizedSortedBag.decorate(bag);
}
@@ -176,7 +176,7 @@
* @return an unmodifiable view of that bag
* @throws IllegalArgumentException if the SortedBag is null
*/
- public static SortedBag unmodifiableSortedBag(SortedBag bag) {
+ public static <E> SortedBag<E> unmodifiableSortedBag(SortedBag<E> bag) {
return UnmodifiableSortedBag.decorate(bag);
}
@@ -193,7 +193,7 @@
* @return a predicated bag backed by the given bag
* @throws IllegalArgumentException if the SortedBag or Predicate is null
*/
- public static SortedBag predicatedSortedBag(SortedBag bag, Predicate predicate) {
+ public static <E> SortedBag<E> predicatedSortedBag(SortedBag<E> bag, Predicate<? super E> predicate) {
return PredicatedSortedBag.decorate(bag, predicate);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ListUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ListUtils.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ListUtils.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/ListUtils.java Fri Jul 13 03:39:24 2007
@@ -68,7 +68,7 @@
* @throws NullPointerException if either list is null
*/
public static List intersection(final List list1, final List list2) {
- final ArrayList result = new ArrayList();
+ final List result = new ArrayList();
final Iterator iterator = list2.iterator();
while (iterator.hasNext()) {
@@ -203,16 +203,15 @@
* @param list the list to generate the hashCode for, may be null
* @return the hash code
*/
- public static int hashCodeForList(final Collection list) {
+ public static <E> int hashCodeForList(final Collection<E> list) {
if (list == null) {
return 0;
}
int hashCode = 1;
- Iterator it = list.iterator();
- Object obj = null;
+ Iterator<E> it = list.iterator();
while (it.hasNext()) {
- obj = it.next();
+ E obj = it.next();
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}
return hashCode;
@@ -234,11 +233,10 @@
* @throws NullPointerException if either parameter is null
* @since Commons Collections 3.2
*/
- public static List retainAll(Collection collection, Collection retain) {
- List list = new ArrayList(Math.min(collection.size(), retain.size()));
+ public static <E> List<E> retainAll(Collection<E> collection, Collection<?> retain) {
+ List<E> list = new ArrayList<E>(Math.min(collection.size(), retain.size()));
- for (Iterator iter = collection.iterator(); iter.hasNext();) {
- Object obj = iter.next();
+ for (E obj : collection) {
if (retain.contains(obj)) {
list.add(obj);
}
@@ -262,11 +260,10 @@
* @throws NullPointerException if either parameter is null
* @since Commons Collections 3.2
*/
- 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) {
+ public static <E> List<E> removeAll(Collection<E> collection, Collection<?> remove) {
+ List<E> list = new ArrayList<E>();
+ for (E obj : collection) {
+ if (!remove.contains(obj)) {
list.add(obj);
}
}
@@ -296,7 +293,7 @@
* @return a synchronized list backed by the given list
* @throws IllegalArgumentException if the list is null
*/
- public static List synchronizedList(List list) {
+ public static <E> List<E> synchronizedList(List<E> list) {
return SynchronizedList.decorate(list);
}
@@ -309,7 +306,7 @@
* @return an unmodifiable list backed by the given list
* @throws IllegalArgumentException if the list is null
*/
- public static List unmodifiableList(List list) {
+ public static <E> List unmodifiableList(List<E> list) {
return UnmodifiableList.decorate(list);
}
@@ -326,7 +323,7 @@
* @return a predicated list backed by the given list
* @throws IllegalArgumentException if the List or Predicate is null
*/
- public static List predicatedList(List list, Predicate predicate) {
+ public static <E> List<E> predicatedList(List<E> list, Predicate<E> predicate) {
return PredicatedList.decorate(list, predicate);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/SetUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/SetUtils.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/SetUtils.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/SetUtils.java Fri Jul 13 03:39:24 2007
@@ -117,16 +117,13 @@
* @param set the set to calculate the hash code for, may be null
* @return the hash code
*/
- public static int hashCodeForSet(final Collection set) {
+ public static <T> int hashCodeForSet(final Collection<T> set) {
if (set == null) {
return 0;
}
- int hashCode = 0;
- Iterator it = set.iterator();
- Object obj = null;
- while (it.hasNext()) {
- obj = it.next();
+ int hashCode = 0;
+ for (T obj : set) {
if (obj != null) {
hashCode += obj.hashCode();
}
@@ -157,7 +154,7 @@
* @return a synchronized set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
- public static Set synchronizedSet(Set set) {
+ public static <T> Set<T> synchronizedSet(Set<T> set) {
return SynchronizedSet.decorate(set);
}
@@ -187,7 +184,7 @@
* @return a predicated set backed by the given set
* @throws IllegalArgumentException if the Set or Predicate is null
*/
- public static Set predicatedSet(Set set, Predicate predicate) {
+ public static <T> Set<T> predicatedSet(Set<T> set, Predicate<? super T> predicate) {
return PredicatedSet.decorate(set, predicate);
}
@@ -245,7 +242,7 @@
* @return a synchronized set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
- public static SortedSet synchronizedSortedSet(SortedSet set) {
+ public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> set) {
return SynchronizedSortedSet.decorate(set);
}
@@ -258,7 +255,7 @@
* @return an unmodifiable set backed by the given set
* @throws IllegalArgumentException if the set is null
*/
- public static SortedSet unmodifiableSortedSet(SortedSet set) {
+ public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> set) {
return UnmodifiableSortedSet.decorate(set);
}
@@ -275,7 +272,7 @@
* @return a predicated sorted set backed by the given sorted set
* @throws IllegalArgumentException if the Set or Predicate is null
*/
- public static SortedSet predicatedSortedSet(SortedSet set, Predicate predicate) {
+ public static <T> SortedSet<T> predicatedSortedSet(SortedSet<T> set, Predicate<? super T> predicate) {
return PredicatedSortedSet.decorate(set, predicate);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractBagDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractBagDecorator.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractBagDecorator.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractBagDecorator.java Fri Jul 13 03:39:24 2007
@@ -31,8 +31,8 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractBagDecorator
- extends AbstractCollectionDecorator implements Bag {
+public abstract class AbstractBagDecorator<E>
+ extends AbstractCollectionDecorator<E> implements Bag<E> {
/**
* Constructor only used in deserialization, do not use otherwise.
@@ -48,7 +48,7 @@
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
- protected AbstractBagDecorator(Bag bag) {
+ protected AbstractBagDecorator(Bag<E> bag) {
super(bag);
}
@@ -57,8 +57,8 @@
*
* @return the decorated bag
*/
- protected Bag decorated() {
- return (Bag) super.decorated();
+ protected Bag<E> decorated() {
+ return (Bag<E>) super.decorated();
}
//-----------------------------------------------------------------------
@@ -66,7 +66,7 @@
return decorated().getCount(object);
}
- public boolean add(Object object, int count) {
+ public boolean add(E object, int count) {
return decorated().add(object, count);
}
@@ -74,7 +74,7 @@
return decorated().remove(object, count);
}
- public Set uniqueSet() {
+ public Set<E> uniqueSet() {
return decorated().uniqueSet();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/AbstractSortedBagDecorator.java Fri Jul 13 03:39:24 2007
@@ -30,8 +30,8 @@
*
* @author Stephen Colebourne
*/
-public abstract class AbstractSortedBagDecorator
- extends AbstractBagDecorator implements SortedBag {
+public abstract class AbstractSortedBagDecorator<E>
+ extends AbstractBagDecorator<E> implements SortedBag<E> {
/**
* Constructor only used in deserialization, do not use otherwise.
@@ -47,7 +47,7 @@
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
- protected AbstractSortedBagDecorator(SortedBag bag) {
+ protected AbstractSortedBagDecorator(SortedBag<E> bag) {
super(bag);
}
@@ -56,20 +56,20 @@
*
* @return the decorated bag
*/
- protected SortedBag decorated() {
- return (SortedBag) super.decorated();
+ protected SortedBag<E> decorated() {
+ return (SortedBag<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Object first() {
+ public E first() {
return decorated().first();
}
- public Object last() {
+ public E last() {
return decorated().last();
}
- public Comparator comparator() {
+ public Comparator<? super E> comparator() {
return decorated().comparator();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedBag.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedBag.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedBag.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedBag.java Fri Jul 13 03:39:24 2007
@@ -41,8 +41,8 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class PredicatedBag
- extends PredicatedCollection implements Bag {
+public class PredicatedBag<E>
+ extends PredicatedCollection<E> implements Bag<E> {
/** Serialization version */
private static final long serialVersionUID = -2575833140344736876L;
@@ -59,8 +59,8 @@
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
- public static Bag decorate(Bag bag, Predicate predicate) {
- return new PredicatedBag(bag, predicate);
+ public static <T> Bag<T> decorate(Bag<T> bag, Predicate<? super T> predicate) {
+ return new PredicatedBag<T>(bag, predicate);
}
//-----------------------------------------------------------------------
@@ -75,7 +75,7 @@
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
- protected PredicatedBag(Bag bag, Predicate predicate) {
+ protected PredicatedBag(Bag<E> bag, Predicate<? super E> predicate) {
super(bag, predicate);
}
@@ -84,12 +84,12 @@
*
* @return the decorated bag
*/
- protected Bag decorated() {
- return (Bag) super.decorated();
+ protected Bag<E> decorated() {
+ return (Bag<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public boolean add(Object object, int count) {
+ public boolean add(E object, int count) {
validate(object);
return decorated().add(object, count);
}
@@ -98,7 +98,7 @@
return decorated().remove(object, count);
}
- public Set uniqueSet() {
+ public Set<E> uniqueSet() {
return decorated().uniqueSet();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedSortedBag.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedSortedBag.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedSortedBag.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/PredicatedSortedBag.java Fri Jul 13 03:39:24 2007
@@ -40,8 +40,8 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class PredicatedSortedBag
- extends PredicatedBag implements SortedBag {
+public class PredicatedSortedBag<E>
+ extends PredicatedBag<E> implements SortedBag<E> {
/** Serialization version */
private static final long serialVersionUID = 3448581314086406616L;
@@ -58,8 +58,8 @@
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
- public static SortedBag decorate(SortedBag bag, Predicate predicate) {
- return new PredicatedSortedBag(bag, predicate);
+ public static <T> SortedBag<T> decorate(SortedBag<T> bag, Predicate<? super T> predicate) {
+ return new PredicatedSortedBag<T>(bag, predicate);
}
//-----------------------------------------------------------------------
@@ -74,7 +74,7 @@
* @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements
*/
- protected PredicatedSortedBag(SortedBag bag, Predicate predicate) {
+ protected PredicatedSortedBag(SortedBag<E> bag, Predicate<? super E> predicate) {
super(bag, predicate);
}
@@ -83,20 +83,20 @@
*
* @return the decorated bag
*/
- protected SortedBag decorated() {
- return (SortedBag) super.decorated();
+ protected SortedBag<E> decorated() {
+ return (SortedBag<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Object first() {
+ public E first() {
return decorated().first();
}
- public Object last() {
+ public E last() {
return decorated().last();
}
- public Comparator comparator() {
+ public Comparator<? super E> comparator() {
return decorated().comparator();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedBag.java Fri Jul 13 03:39:24 2007
@@ -36,8 +36,8 @@
*
* @author Stephen Colebourne
*/
-public class SynchronizedBag
- extends SynchronizedCollection implements Bag {
+public class SynchronizedBag<E>
+ extends SynchronizedCollection<E> implements Bag<E> {
/** Serialization version */
private static final long serialVersionUID = 8084674570753837109L;
@@ -49,8 +49,8 @@
* @return a new synchronized Bag
* @throws IllegalArgumentException if bag is null
*/
- public static Bag decorate(Bag bag) {
- return new SynchronizedBag(bag);
+ public static <T> Bag<T> decorate(Bag<T> bag) {
+ return new SynchronizedBag<T>(bag);
}
//-----------------------------------------------------------------------
@@ -60,7 +60,7 @@
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
- protected SynchronizedBag(Bag bag) {
+ protected SynchronizedBag(Bag<E> bag) {
super(bag);
}
@@ -71,7 +71,7 @@
* @param lock the lock to use, must not be null
* @throws IllegalArgumentException if bag is null
*/
- protected SynchronizedBag(Bag bag, Object lock) {
+ protected SynchronizedBag(Bag<E> bag, Object lock) {
super(bag, lock);
}
@@ -80,12 +80,12 @@
*
* @return the decorated bag
*/
- protected Bag getBag() {
- return (Bag) collection;
+ protected Bag<E> getBag() {
+ return (Bag<E>) collection;
}
//-----------------------------------------------------------------------
- public boolean add(Object object, int count) {
+ public boolean add(E object, int count) {
synchronized (lock) {
return getBag().add(object, count);
}
@@ -97,9 +97,9 @@
}
}
- public Set uniqueSet() {
+ public Set<E> uniqueSet() {
synchronized (lock) {
- Set set = getBag().uniqueSet();
+ Set<E> set = getBag().uniqueSet();
return new SynchronizedBagSet(set, lock);
}
}
@@ -114,13 +114,13 @@
/**
* Synchronized Set for the Bag class.
*/
- class SynchronizedBagSet extends SynchronizedSet {
+ class SynchronizedBagSet extends SynchronizedSet<E> {
/**
* Constructor.
* @param set the set to decorate
* @param lock the lock to use, shared with the bag
*/
- SynchronizedBagSet(Set set, Object lock) {
+ SynchronizedBagSet(Set<E> set, Object lock) {
super(set, lock);
}
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/SynchronizedSortedBag.java Fri Jul 13 03:39:24 2007
@@ -35,8 +35,8 @@
*
* @author Stephen Colebourne
*/
-public class SynchronizedSortedBag
- extends SynchronizedBag implements SortedBag {
+public class SynchronizedSortedBag<E>
+ extends SynchronizedBag<E> implements SortedBag<E> {
/** Serialization version */
private static final long serialVersionUID = 722374056718497858L;
@@ -48,8 +48,8 @@
* @return a new synchronized SortedBag
* @throws IllegalArgumentException if bag is null
*/
- public static SortedBag decorate(SortedBag bag) {
- return new SynchronizedSortedBag(bag);
+ public static <T> SortedBag<T> decorate(SortedBag<T> bag) {
+ return new SynchronizedSortedBag<T>(bag);
}
//-----------------------------------------------------------------------
@@ -59,7 +59,7 @@
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
- protected SynchronizedSortedBag(SortedBag bag) {
+ protected SynchronizedSortedBag(SortedBag<E> bag) {
super(bag);
}
@@ -70,7 +70,7 @@
* @param lock the lock to use, must not be null
* @throws IllegalArgumentException if bag is null
*/
- protected SynchronizedSortedBag(Bag bag, Object lock) {
+ protected SynchronizedSortedBag(Bag<E> bag, Object lock) {
super(bag, lock);
}
@@ -79,24 +79,24 @@
*
* @return the decorated bag
*/
- protected SortedBag getSortedBag() {
- return (SortedBag) collection;
+ protected SortedBag<E> getSortedBag() {
+ return (SortedBag<E>) collection;
}
//-----------------------------------------------------------------------
- public synchronized Object first() {
+ public synchronized E first() {
synchronized (lock) {
return getSortedBag().first();
}
}
- public synchronized Object last() {
+ public synchronized E last() {
synchronized (lock) {
return getSortedBag().last();
}
}
- public synchronized Comparator comparator() {
+ public synchronized Comparator<? super E> comparator() {
synchronized (lock) {
return getSortedBag().comparator();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java Fri Jul 13 03:39:24 2007
@@ -39,8 +39,8 @@
*
* @author Stephen Colebourne
*/
-public final class UnmodifiableSortedBag
- extends AbstractSortedBagDecorator implements Unmodifiable, Serializable {
+public final class UnmodifiableSortedBag<E>
+ extends AbstractSortedBagDecorator<E> implements Unmodifiable, Serializable {
/** Serialization version */
private static final long serialVersionUID = -3190437252665717841L;
@@ -54,11 +54,11 @@
* @return an unmodifiable SortedBag
* @throws IllegalArgumentException if bag is null
*/
- public static SortedBag decorate(SortedBag bag) {
+ public static <T> SortedBag<T> decorate(SortedBag<T> bag) {
if (bag instanceof Unmodifiable) {
return bag;
}
- return new UnmodifiableSortedBag(bag);
+ return new UnmodifiableSortedBag<T>(bag);
}
//-----------------------------------------------------------------------
@@ -68,7 +68,7 @@
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
- private UnmodifiableSortedBag(SortedBag bag) {
+ private UnmodifiableSortedBag(SortedBag<E> bag) {
super(bag);
}
@@ -93,7 +93,7 @@
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
- collection = (Collection) in.readObject();
+ collection = (Collection<E>) in.readObject();
}
//-----------------------------------------------------------------------
@@ -101,11 +101,11 @@
return UnmodifiableIterator.decorate(decorated().iterator());
}
- public boolean add(Object object) {
+ public boolean add(E object) {
throw new UnsupportedOperationException();
}
- public boolean addAll(Collection coll) {
+ public boolean addAll(Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@@ -117,16 +117,16 @@
throw new UnsupportedOperationException();
}
- public boolean removeAll(Collection coll) {
+ public boolean removeAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
- public boolean retainAll(Collection coll) {
+ public boolean retainAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
- public boolean add(Object object, int count) {
+ public boolean add(E object, int count) {
throw new UnsupportedOperationException();
}
@@ -134,8 +134,8 @@
throw new UnsupportedOperationException();
}
- public Set uniqueSet() {
- Set set = decorated().uniqueSet();
+ public Set<E> uniqueSet() {
+ Set<E> set = decorated().uniqueSet();
return UnmodifiableSet.decorate(set);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/PredicatedBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/PredicatedBuffer.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/PredicatedBuffer.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/buffer/PredicatedBuffer.java Fri Jul 13 03:39:24 2007
@@ -39,7 +39,7 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class PredicatedBuffer extends PredicatedCollection implements Buffer {
+public class PredicatedBuffer<E> extends PredicatedCollection<E> implements Buffer<E> {
/** Serialization version */
private static final long serialVersionUID = 2307609000539943581L;
@@ -56,8 +56,8 @@
* @throws IllegalArgumentException if buffer or predicate is null
* @throws IllegalArgumentException if the buffer contains invalid elements
*/
- public static Buffer decorate(Buffer buffer, Predicate predicate) {
- return new PredicatedBuffer(buffer, predicate);
+ public static <T> Buffer<T> decorate(Buffer<T> buffer, Predicate<? super T> predicate) {
+ return new PredicatedBuffer<T>(buffer, predicate);
}
//-----------------------------------------------------------------------
@@ -72,7 +72,7 @@
* @throws IllegalArgumentException if buffer or predicate is null
* @throws IllegalArgumentException if the buffer contains invalid elements
*/
- protected PredicatedBuffer(Buffer buffer, Predicate predicate) {
+ protected PredicatedBuffer(Buffer<E> buffer, Predicate<? super E> predicate) {
super(buffer, predicate);
}
@@ -81,16 +81,16 @@
*
* @return the decorated buffer
*/
- protected Buffer decorated() {
- return (Buffer) super.decorated();
+ protected Buffer<E> decorated() {
+ return (Buffer<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Object get() {
+ public E get() {
return decorated().get();
}
- public Object remove() {
+ public E remove() {
return decorated().remove();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/AbstractCollectionDecorator.java Fri Jul 13 03:39:24 2007
@@ -136,10 +136,7 @@
}
public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- return decorated().equals(object);
+ return object == this || decorated().equals(object);
}
public int hashCode() {
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/collection/TransformedCollection.java Fri Jul 13 03:39:24 2007
@@ -52,14 +52,13 @@
* If there are any elements already in the collection being decorated, they
* are NOT transformed.
*
- * @param <T> the type of the elements in the collection
* @param coll the collection to decorate, must not be null
* @param transformer the transformer to use for conversion, must not be null
* @return a new transformed collection
* @throws IllegalArgumentException if collection or transformer is null
*/
- public static <T> Collection<T> decorate(Collection<T> coll, Transformer<T, T> transformer) {
- return new TransformedCollection<T>(coll, transformer);
+ public static Collection decorate(Collection coll, Transformer transformer) {
+ return new TransformedCollection(coll, transformer);
}
//-----------------------------------------------------------------------
@@ -73,7 +72,7 @@
* @param transformer the transformer to use for conversion, must not be null
* @throws IllegalArgumentException if collection or transformer is null
*/
- protected TransformedCollection(Collection<E> coll, Transformer<E, E> transformer) {
+ protected TransformedCollection(Collection coll, Transformer transformer) {
super(coll);
if (transformer == null) {
throw new IllegalArgumentException("Transformer must not be null");
@@ -89,8 +88,8 @@
* @param object the object to transform
* @return a transformed object
*/
- protected E transform(E object) {
- return transformer.transform(object);
+ protected E transform(Object object) {
+ return transformer.transform((E) object);
}
/**
@@ -101,23 +100,21 @@
* @param coll the collection to transform
* @return a transformed object
*/
- protected Collection<E> transform(Collection<? extends E> coll) {
- List<E> list = new ArrayList<E>(coll.size());
- for (E item : coll) {
+ protected Collection transform(Collection coll) {
+ List list = new ArrayList(coll.size());
+ for (Object item : coll) {
list.add(transform(item));
}
return list;
}
//-----------------------------------------------------------------------
- public boolean add(E object) {
- object = transform(object);
- return decorated().add(object);
+ public boolean add(Object object) {
+ return decorated().add(transform(object));
}
- public boolean addAll(Collection<? extends E> coll) {
- coll = transform(coll);
- return decorated().addAll(coll);
+ public boolean addAll(Collection coll) {
+ return decorated().addAll(transform(coll));
}
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/iterators/AbstractListIteratorDecorator.java Fri Jul 13 03:39:24 2007
@@ -29,10 +29,10 @@
* @author Rodney Waldhoff
* @author Stephen Colebourne
*/
-public class AbstractListIteratorDecorator implements ListIterator {
+public class AbstractListIteratorDecorator<E> implements ListIterator<E> {
/** The iterator being decorated */
- protected final ListIterator iterator;
+ protected final ListIterator<E> iterator;
//-----------------------------------------------------------------------
/**
@@ -41,7 +41,7 @@
* @param iterator the iterator to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
- public AbstractListIteratorDecorator(ListIterator iterator) {
+ public AbstractListIteratorDecorator(ListIterator<E> iterator) {
super();
if (iterator == null) {
throw new IllegalArgumentException("ListIterator must not be null");
@@ -54,7 +54,7 @@
*
* @return the decorated iterator
*/
- protected ListIterator getListIterator() {
+ protected ListIterator<E> getListIterator() {
return iterator;
}
@@ -63,7 +63,7 @@
return iterator.hasNext();
}
- public Object next() {
+ public E next() {
return iterator.next();
}
@@ -75,7 +75,7 @@
return iterator.hasPrevious();
}
- public Object previous() {
+ public E previous() {
return iterator.previous();
}
@@ -87,11 +87,11 @@
iterator.remove();
}
- public void set(Object obj) {
+ public void set(E obj) {
iterator.set(obj);
}
- public void add(Object obj) {
+ public void add(E obj) {
iterator.add(obj);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/PredicatedList.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/PredicatedList.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/PredicatedList.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/PredicatedList.java Fri Jul 13 03:39:24 2007
@@ -16,15 +16,14 @@
*/
package org.apache.commons.collections.list;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.collection.PredicatedCollection;
import org.apache.commons.collections.iterators.AbstractListIteratorDecorator;
+import java.util.Collection;
+import java.util.List;
+import java.util.ListIterator;
+
/**
* Decorates another <code>List</code> to validate that all additions
* match a specified predicate.
@@ -44,7 +43,7 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class PredicatedList extends PredicatedCollection implements List {
+public class PredicatedList<E> extends PredicatedCollection<E> implements List<E> {
/** Serialization version */
private static final long serialVersionUID = -5722039223898659102L;
@@ -57,11 +56,12 @@
*
* @param list the list to decorate, must not be null
* @param predicate the predicate to use for validation, must not be null
+ * @return the decorated list
* @throws IllegalArgumentException if list or predicate is null
* @throws IllegalArgumentException if the list contains invalid elements
*/
- public static List decorate(List list, Predicate predicate) {
- return new PredicatedList(list, predicate);
+ public static <T> List<T> decorate(List<T> list, Predicate<? super T> predicate) {
+ return new PredicatedList<T>(list, predicate);
}
//-----------------------------------------------------------------------
@@ -76,7 +76,7 @@
* @throws IllegalArgumentException if list or predicate is null
* @throws IllegalArgumentException if the list contains invalid elements
*/
- protected PredicatedList(List list, Predicate predicate) {
+ protected PredicatedList(List<E> list, Predicate<? super E> predicate) {
super(list, predicate);
}
@@ -85,12 +85,12 @@
*
* @return the decorated list
*/
- protected List decorated() {
- return (List) super.decorated();
+ protected List<E> decorated() {
+ return (List<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Object get(int index) {
+ public E get(int index) {
return decorated().get(index);
}
@@ -102,56 +102,56 @@
return decorated().lastIndexOf(object);
}
- public Object remove(int index) {
+ public E remove(int index) {
return decorated().remove(index);
}
//-----------------------------------------------------------------------
- public void add(int index, Object object) {
+ public void add(int index, E object) {
validate(object);
decorated().add(index, object);
}
- public boolean addAll(int index, Collection coll) {
- for (Iterator it = coll.iterator(); it.hasNext(); ) {
- validate(it.next());
+ public boolean addAll(int index, Collection<? extends E> coll) {
+ for (E aColl : coll) {
+ validate(aColl);
}
return decorated().addAll(index, coll);
}
- public ListIterator listIterator() {
+ public ListIterator<E> listIterator() {
return listIterator(0);
}
- public ListIterator listIterator(int i) {
+ public ListIterator<E> listIterator(int i) {
return new PredicatedListIterator(decorated().listIterator(i));
}
- public Object set(int index, Object object) {
+ public E set(int index, E object) {
validate(object);
return decorated().set(index, object);
}
- public List subList(int fromIndex, int toIndex) {
- List sub = decorated().subList(fromIndex, toIndex);
- return new PredicatedList(sub, predicate);
+ public List<E> subList(int fromIndex, int toIndex) {
+ List<E> sub = decorated().subList(fromIndex, toIndex);
+ return new PredicatedList<E>(sub, predicate);
}
/**
* Inner class Iterator for the PredicatedList
*/
- protected class PredicatedListIterator extends AbstractListIteratorDecorator {
+ protected class PredicatedListIterator extends AbstractListIteratorDecorator<E> {
- protected PredicatedListIterator(ListIterator iterator) {
+ protected PredicatedListIterator(ListIterator<E> iterator) {
super(iterator);
}
- public void add(Object object) {
+ public void add(E object) {
validate(object);
iterator.add(object);
}
- public void set(Object object) {
+ public void set(E object) {
validate(object);
iterator.set(object);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/SynchronizedList.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/SynchronizedList.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/SynchronizedList.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/list/SynchronizedList.java Fri Jul 13 03:39:24 2007
@@ -35,7 +35,7 @@
*
* @author Stephen Colebourne
*/
-public class SynchronizedList extends SynchronizedCollection implements List {
+public class SynchronizedList<E> extends SynchronizedCollection<E> implements List<E> {
/** Serialization version */
private static final long serialVersionUID = -1403835447328619437L;
@@ -46,8 +46,8 @@
* @param list the list to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
- public static List decorate(List list) {
- return new SynchronizedList(list);
+ public static <T> List<T> decorate(List<T> list) {
+ return new SynchronizedList<T>(list);
}
//-----------------------------------------------------------------------
@@ -57,7 +57,7 @@
* @param list the list to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
- protected SynchronizedList(List list) {
+ protected SynchronizedList(List<E> list) {
super(list);
}
@@ -68,7 +68,7 @@
* @param lock the lock to use, must not be null
* @throws IllegalArgumentException if list is null
*/
- protected SynchronizedList(List list, Object lock) {
+ protected SynchronizedList(List<E> list, Object lock) {
super(list, lock);
}
@@ -77,24 +77,24 @@
*
* @return the decorated list
*/
- protected List getList() {
- return (List) collection;
+ protected List<E> getList() {
+ return (List<E>) collection;
}
//-----------------------------------------------------------------------
- public void add(int index, Object object) {
+ public void add(int index, E object) {
synchronized (lock) {
getList().add(index, object);
}
}
- public boolean addAll(int index, Collection coll) {
+ public boolean addAll(int index, Collection<? extends E> coll) {
synchronized (lock) {
return getList().addAll(index, coll);
}
}
- public Object get(int index) {
+ public E get(int index) {
synchronized (lock) {
return getList().get(index);
}
@@ -140,24 +140,24 @@
return getList().listIterator(index);
}
- public Object remove(int index) {
+ public E remove(int index) {
synchronized (lock) {
return getList().remove(index);
}
}
- public Object set(int index, Object object) {
+ public E set(int index, E object) {
synchronized (lock) {
return getList().set(index, object);
}
}
- public List subList(int fromIndex, int toIndex) {
+ public List<E> subList(int fromIndex, int toIndex) {
synchronized (lock) {
- List list = getList().subList(fromIndex, toIndex);
+ List<E> list = getList().subList(fromIndex, toIndex);
// the lock is passed into the constructor here to ensure that the sublist is
// synchronized on the same lock as the parent list
- return new SynchronizedList(list, lock);
+ return new SynchronizedList<E>(list, lock);
}
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSet.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSet.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSet.java Fri Jul 13 03:39:24 2007
@@ -40,7 +40,7 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class PredicatedSet extends PredicatedCollection implements Set {
+public class PredicatedSet<E> extends PredicatedCollection<E> implements Set<E> {
/** Serialization version */
private static final long serialVersionUID = -684521469108685117L;
@@ -53,11 +53,12 @@
*
* @param set the set to decorate, must not be null
* @param predicate the predicate to use for validation, must not be null
+ * @return a decorated set
* @throws IllegalArgumentException if set or predicate is null
* @throws IllegalArgumentException if the set contains invalid elements
*/
- public static Set decorate(Set set, Predicate predicate) {
- return new PredicatedSet(set, predicate);
+ public static <T> Set<T> decorate(Set<T> set, Predicate<? super T> predicate) {
+ return new PredicatedSet<T>(set, predicate);
}
//-----------------------------------------------------------------------
@@ -72,7 +73,7 @@
* @throws IllegalArgumentException if set or predicate is null
* @throws IllegalArgumentException if the set contains invalid elements
*/
- protected PredicatedSet(Set set, Predicate predicate) {
+ protected PredicatedSet(Set<E> set, Predicate<? super E> predicate) {
super(set, predicate);
}
@@ -81,8 +82,8 @@
*
* @return the decorated set
*/
- protected Set decorated() {
- return (Set) super.decorated();
+ protected Set<E> decorated() {
+ return (Set<E>) super.decorated();
}
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSortedSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSortedSet.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSortedSet.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/PredicatedSortedSet.java Fri Jul 13 03:39:24 2007
@@ -40,7 +40,7 @@
* @author Stephen Colebourne
* @author Paul Jack
*/
-public class PredicatedSortedSet extends PredicatedSet implements SortedSet {
+public class PredicatedSortedSet<E> extends PredicatedSet<E> implements SortedSet<E> {
/** Serialization version */
private static final long serialVersionUID = -9110948148132275052L;
@@ -53,11 +53,12 @@
*
* @param set the set to decorate, must not be null
* @param predicate the predicate to use for validation, must not be null
+ * @return a new predicated sorted set.
* @throws IllegalArgumentException if set or predicate is null
* @throws IllegalArgumentException if the set contains invalid elements
*/
- public static SortedSet decorate(SortedSet set, Predicate predicate) {
- return new PredicatedSortedSet(set, predicate);
+ public static <T> SortedSet<T> decorate(SortedSet<T> set, Predicate<? super T> predicate) {
+ return new PredicatedSortedSet<T>(set, predicate);
}
//-----------------------------------------------------------------------
@@ -72,7 +73,7 @@
* @throws IllegalArgumentException if set or predicate is null
* @throws IllegalArgumentException if the set contains invalid elements
*/
- protected PredicatedSortedSet(SortedSet set, Predicate predicate) {
+ protected PredicatedSortedSet(SortedSet<E> set, Predicate<? super E> predicate) {
super(set, predicate);
}
@@ -81,36 +82,36 @@
*
* @return the decorated sorted set
*/
- protected SortedSet decorated() {
- return (SortedSet) super.decorated();
+ protected SortedSet<E> decorated() {
+ return (SortedSet<E>) super.decorated();
}
//-----------------------------------------------------------------------
- public Comparator comparator() {
+ public Comparator<? super E> comparator() {
return decorated().comparator();
}
- public Object first() {
+ public E first() {
return decorated().first();
}
- public Object last() {
+ public E last() {
return decorated().last();
}
- public SortedSet subSet(Object fromElement, Object toElement) {
- SortedSet sub = decorated().subSet(fromElement, toElement);
- return new PredicatedSortedSet(sub, predicate);
+ public SortedSet<E> subSet(E fromElement, E toElement) {
+ SortedSet<E> sub = decorated().subSet(fromElement, toElement);
+ return new PredicatedSortedSet<E>(sub, predicate);
}
- public SortedSet headSet(Object toElement) {
- SortedSet sub = decorated().headSet(toElement);
- return new PredicatedSortedSet(sub, predicate);
+ public SortedSet<E> headSet(E toElement) {
+ SortedSet<E> sub = decorated().headSet(toElement);
+ return new PredicatedSortedSet<E>(sub, predicate);
}
- public SortedSet tailSet(Object fromElement) {
- SortedSet sub = decorated().tailSet(fromElement);
- return new PredicatedSortedSet(sub, predicate);
+ public SortedSet<E> tailSet(E fromElement) {
+ SortedSet<E> sub = decorated().tailSet(fromElement);
+ return new PredicatedSortedSet<E>(sub, predicate);
}
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSet.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSet.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSet.java Fri Jul 13 03:39:24 2007
@@ -33,7 +33,7 @@
*
* @author Stephen Colebourne
*/
-public class SynchronizedSet extends SynchronizedCollection implements Set {
+public class SynchronizedSet<E> extends SynchronizedCollection<E> implements Set<E> {
/** Serialization version */
private static final long serialVersionUID = -8304417378626543635L;
@@ -44,8 +44,8 @@
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
- public static Set decorate(Set set) {
- return new SynchronizedSet(set);
+ public static <T> Set<T> decorate(Set<T> set) {
+ return new SynchronizedSet<T>(set);
}
//-----------------------------------------------------------------------
@@ -55,7 +55,7 @@
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
- protected SynchronizedSet(Set set) {
+ protected SynchronizedSet(Set<E> set) {
super(set);
}
@@ -66,7 +66,7 @@
* @param lock the lock object to use, must not be null
* @throws IllegalArgumentException if set is null
*/
- protected SynchronizedSet(Set set, Object lock) {
+ protected SynchronizedSet(Set<E> set, Object lock) {
super(set, lock);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSortedSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSortedSet.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSortedSet.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/SynchronizedSortedSet.java Fri Jul 13 03:39:24 2007
@@ -34,7 +34,7 @@
*
* @author Stephen Colebourne
*/
-public class SynchronizedSortedSet extends SynchronizedCollection implements SortedSet {
+public class SynchronizedSortedSet<E> extends SynchronizedCollection<E> implements SortedSet<E> {
/** Serialization version */
private static final long serialVersionUID = 2775582861954500111L;
@@ -45,8 +45,8 @@
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
- public static SortedSet decorate(SortedSet set) {
- return new SynchronizedSortedSet(set);
+ public static <T> SortedSet<T> decorate(SortedSet<T> set) {
+ return new SynchronizedSortedSet<T>(set);
}
//-----------------------------------------------------------------------
@@ -56,7 +56,7 @@
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
- protected SynchronizedSortedSet(SortedSet set) {
+ protected SynchronizedSortedSet(SortedSet<E> set) {
super(set);
}
@@ -67,7 +67,7 @@
* @param lock the lock object to use, must not be null
* @throws IllegalArgumentException if set is null
*/
- protected SynchronizedSortedSet(SortedSet set, Object lock) {
+ protected SynchronizedSortedSet(SortedSet<E> set, Object lock) {
super(set, lock);
}
@@ -76,12 +76,12 @@
*
* @return the decorated set
*/
- protected SortedSet getSortedSet() {
- return (SortedSet) collection;
+ protected SortedSet<E> getSortedSet() {
+ return (SortedSet<E>) collection;
}
//-----------------------------------------------------------------------
- public SortedSet subSet(Object fromElement, Object toElement) {
+ public SortedSet<E> subSet(E fromElement, E toElement) {
synchronized (lock) {
SortedSet set = getSortedSet().subSet(fromElement, toElement);
// the lock is passed into the constructor here to ensure that the
@@ -90,7 +90,7 @@
}
}
- public SortedSet headSet(Object toElement) {
+ public SortedSet<E> headSet(E toElement) {
synchronized (lock) {
SortedSet set = getSortedSet().headSet(toElement);
// the lock is passed into the constructor here to ensure that the
@@ -99,7 +99,7 @@
}
}
- public SortedSet tailSet(Object fromElement) {
+ public SortedSet<E> tailSet(E fromElement) {
synchronized (lock) {
SortedSet set = getSortedSet().tailSet(fromElement);
// the lock is passed into the constructor here to ensure that the
@@ -108,13 +108,13 @@
}
}
- public Object first() {
+ public E first() {
synchronized (lock) {
return getSortedSet().first();
}
}
- public Object last() {
+ public E last() {
synchronized (lock) {
return getSortedSet().last();
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java Fri Jul 13 03:39:24 2007
@@ -37,8 +37,8 @@
*
* @author Stephen Colebourne
*/
-public final class UnmodifiableSortedSet
- extends AbstractSortedSetDecorator
+public final class UnmodifiableSortedSet<E>
+ extends AbstractSortedSetDecorator<E>
implements Unmodifiable, Serializable {
/** Serialization version */
@@ -50,7 +50,7 @@
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
- public static SortedSet decorate(SortedSet set) {
+ public static <T> SortedSet<T> decorate(SortedSet<T> set) {
if (set instanceof Unmodifiable) {
return set;
}
@@ -88,7 +88,7 @@
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
- private UnmodifiableSortedSet(SortedSet set) {
+ private UnmodifiableSortedSet(SortedSet<E> set) {
super(set);
}
@@ -97,11 +97,11 @@
return UnmodifiableIterator.decorate(decorated().iterator());
}
- public boolean add(Object object) {
+ public boolean add(E object) {
throw new UnsupportedOperationException();
}
- public boolean addAll(Collection coll) {
+ public boolean addAll(Collection<? extends E> coll) {
throw new UnsupportedOperationException();
}
@@ -113,27 +113,27 @@
throw new UnsupportedOperationException();
}
- public boolean removeAll(Collection coll) {
+ public boolean removeAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
- public boolean retainAll(Collection coll) {
+ public boolean retainAll(Collection<?> coll) {
throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
- public SortedSet subSet(Object fromElement, Object toElement) {
- SortedSet sub = decorated().subSet(fromElement, toElement);
+ public SortedSet<E> subSet(E fromElement, E toElement) {
+ SortedSet<E> sub = decorated().subSet(fromElement, toElement);
return new UnmodifiableSortedSet(sub);
}
- public SortedSet headSet(Object toElement) {
- SortedSet sub = decorated().headSet(toElement);
+ public SortedSet<E> headSet(E toElement) {
+ SortedSet<E> sub = decorated().headSet(toElement);
return new UnmodifiableSortedSet(sub);
}
- public SortedSet tailSet(Object fromElement) {
- SortedSet sub = decorated().tailSet(fromElement);
+ public SortedSet<E> tailSet(E fromElement) {
+ SortedSet<E> sub = decorated().tailSet(fromElement);
return new UnmodifiableSortedSet(sub);
}
Modified: jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestListUtils.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestListUtils.java?view=diff&rev=555925&r1=555924&r2=555925
==============================================================================
--- jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestListUtils.java (original)
+++ jakarta/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/TestListUtils.java Fri Jul 13 03:39:24 2007
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import junit.framework.Test;
@@ -44,7 +45,7 @@
private static final String x = "x";
private String[] fullArray;
- private List fullList;
+ private List<String> fullList;
public TestListUtils(String name) {
super(name);
@@ -62,8 +63,54 @@
public void testNothing() {
}
-
- public void testpredicatedList() {
+
+ /**
+ * Tests intersecting a non-empty list with an empty list.
+ */
+ public void testIntersectNonEmptyWithEmptyList() {
+ final List<?> empty = Collections.EMPTY_LIST;
+ assertTrue("result not empty", ListUtils.intersection(empty, fullList).isEmpty());
+ }
+
+ /**
+ * Tests intersecting a non-empty list with an empty list.
+ */
+ public void testIntersectEmptyWithEmptyList() {
+ final List<?> empty = Collections.EMPTY_LIST;
+ assertTrue("result not empty", ListUtils.intersection(empty, empty).isEmpty());
+ }
+
+ /**
+ * Tests intersecting a non-empty list with an subset of iteself.
+ */
+ public void testIntersectNonEmptySubset() {
+ // create a copy
+ final List<String> other = new ArrayList(fullList);
+
+ // remove a few items
+ assertNotNull(other.remove(0));
+ assertNotNull(other.remove(1));
+
+ // make sure the intersection is equal to the copy
+ assertEquals(other, ListUtils.intersection(fullList, other));
+ }
+
+ /**
+ * Tests intersecting a non-empty list with an subset of iteself.
+ */
+ public void testIntersectListWithNoOverlapAndDifferentTypes() {
+ final List<Integer> other = Arrays.asList(1, 23);
+ assertTrue(ListUtils.intersection(fullList, other).isEmpty());
+ }
+
+ /**
+ * Tests intersecting a non-empty list with iteself.
+ */
+ public void testIntersectListWithSelf() {
+ assertEquals(fullList, ListUtils.intersection(fullList, fullList));
+ }
+
+ public void testPredicatedList() {
Predicate predicate = new Predicate() {
public boolean evaluate(Object o) {
return o instanceof String;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org