Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r555925 | skestle | 2007-07-13 03:39:24 -0700 (Fri, 13 Jul 2007) | 2 lines
    
    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
    ------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:54:03 +00:00
parent ae565ed8bc
commit bf07130695
1 changed files with 16 additions and 13 deletions

View File

@ -36,8 +36,8 @@ import org.apache.commons.collections.set.SynchronizedSet;
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public class SynchronizedBag public class SynchronizedBag<E>
extends SynchronizedCollection implements Bag { extends SynchronizedCollection<E> implements Bag<E> {
/** Serialization version */ /** Serialization version */
private static final long serialVersionUID = 8084674570753837109L; private static final long serialVersionUID = 8084674570753837109L;
@ -49,8 +49,8 @@ public class SynchronizedBag
* @return a new synchronized Bag * @return a new synchronized Bag
* @throws IllegalArgumentException if bag is null * @throws IllegalArgumentException if bag is null
*/ */
public static Bag decorate(Bag bag) { public static <T> Bag<T> decorate(Bag<T> bag) {
return new SynchronizedBag(bag); return new SynchronizedBag<T>(bag);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -60,7 +60,7 @@ public class SynchronizedBag
* @param bag the bag to decorate, must not be null * @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null * @throws IllegalArgumentException if bag is null
*/ */
protected SynchronizedBag(Bag bag) { protected SynchronizedBag(Bag<E> bag) {
super(bag); super(bag);
} }
@ -71,7 +71,7 @@ public class SynchronizedBag
* @param lock the lock to use, must not be null * @param lock the lock to use, must not be null
* @throws IllegalArgumentException if bag is null * @throws IllegalArgumentException if bag is null
*/ */
protected SynchronizedBag(Bag bag, Object lock) { protected SynchronizedBag(Bag<E> bag, Object lock) {
super(bag, lock); super(bag, lock);
} }
@ -80,12 +80,12 @@ public class SynchronizedBag
* *
* @return the decorated bag * @return the decorated bag
*/ */
protected Bag getBag() { protected Bag<E> getBag() {
return (Bag) collection; return (Bag<E>) collection;
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public boolean add(Object object, int count) { public boolean add(E object, int count) {
synchronized (lock) { synchronized (lock) {
return getBag().add(object, count); return getBag().add(object, count);
} }
@ -97,9 +97,9 @@ public class SynchronizedBag
} }
} }
public Set uniqueSet() { public Set<E> uniqueSet() {
synchronized (lock) { synchronized (lock) {
Set set = getBag().uniqueSet(); Set<E> set = getBag().uniqueSet();
return new SynchronizedBagSet(set, lock); return new SynchronizedBagSet(set, lock);
} }
} }
@ -114,13 +114,16 @@ public class SynchronizedBag
/** /**
* Synchronized Set for the Bag class. * Synchronized Set for the Bag class.
*/ */
class SynchronizedBagSet extends SynchronizedSet { class SynchronizedBagSet extends SynchronizedSet<E> {
/** Serialization version */
private static final long serialVersionUID = 2990565892366827855L;
/** /**
* Constructor. * Constructor.
* @param set the set to decorate * @param set the set to decorate
* @param lock the lock to use, shared with the bag * @param lock the lock to use, shared with the bag
*/ */
SynchronizedBagSet(Set set, Object lock) { SynchronizedBagSet(Set<E> set, Object lock) {
super(set, lock); super(set, lock);
} }
} }