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
    ------------------------------------------------------------------------
    r471201 | scolebourne | 2006-11-04 06:17:26 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getBag() - use covariant decorated()
    ------------------------------------------------------------------------


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

View File

@ -41,8 +41,8 @@ import org.apache.commons.collections.collection.PredicatedCollection;
* @author Stephen Colebourne * @author Stephen Colebourne
* @author Paul Jack * @author Paul Jack
*/ */
public class PredicatedBag public class PredicatedBag<E>
extends PredicatedCollection implements Bag { extends PredicatedCollection<E> implements Bag<E> {
/** Serialization version */ /** Serialization version */
private static final long serialVersionUID = -2575833140344736876L; private static final long serialVersionUID = -2575833140344736876L;
@ -59,8 +59,8 @@ public class PredicatedBag
* @throws IllegalArgumentException if bag or predicate is null * @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements * @throws IllegalArgumentException if the bag contains invalid elements
*/ */
public static Bag decorate(Bag bag, Predicate predicate) { public static <T> Bag<T> decorate(Bag<T> bag, Predicate<? super T> predicate) {
return new PredicatedBag(bag, predicate); return new PredicatedBag<T>(bag, predicate);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -75,7 +75,7 @@ public class PredicatedBag
* @throws IllegalArgumentException if bag or predicate is null * @throws IllegalArgumentException if bag or predicate is null
* @throws IllegalArgumentException if the bag contains invalid elements * @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); super(bag, predicate);
} }
@ -84,26 +84,26 @@ public class PredicatedBag
* *
* @return the decorated bag * @return the decorated bag
*/ */
protected Bag getBag() { protected Bag<E> decorated() {
return (Bag) getCollection(); return (Bag<E>) super.decorated();
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public boolean add(Object object, int count) { public boolean add(E object, int count) {
validate(object); validate(object);
return getBag().add(object, count); return decorated().add(object, count);
} }
public boolean remove(Object object, int count) { public boolean remove(Object object, int count) {
return getBag().remove(object, count); return decorated().remove(object, count);
} }
public Set uniqueSet() { public Set<E> uniqueSet() {
return getBag().uniqueSet(); return decorated().uniqueSet();
} }
public int getCount(Object object) { public int getCount(Object object) {
return getBag().getCount(object); return decorated().getCount(object);
} }
} }