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@815018 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:54:08 +00:00
parent 6fa2bab941
commit 8416671c32
1 changed files with 16 additions and 15 deletions

View File

@ -41,8 +41,8 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public final class UnmodifiableSortedBag public final class UnmodifiableSortedBag<E>
extends AbstractSortedBagDecorator implements Unmodifiable, Serializable { extends AbstractSortedBagDecorator<E> implements Unmodifiable, Serializable {
/** Serialization version */ /** Serialization version */
private static final long serialVersionUID = -3190437252665717841L; private static final long serialVersionUID = -3190437252665717841L;
@ -56,11 +56,11 @@ public final class UnmodifiableSortedBag
* @return an unmodifiable SortedBag * @return an unmodifiable SortedBag
* @throws IllegalArgumentException if bag is null * @throws IllegalArgumentException if bag is null
*/ */
public static SortedBag decorate(SortedBag bag) { public static <E> SortedBag<E> decorate(SortedBag<E> bag) {
if (bag instanceof Unmodifiable) { if (bag instanceof Unmodifiable) {
return bag; return bag;
} }
return new UnmodifiableSortedBag(bag); return new UnmodifiableSortedBag<E>(bag);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -70,7 +70,7 @@ public final class UnmodifiableSortedBag
* @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
*/ */
private UnmodifiableSortedBag(SortedBag bag) { private UnmodifiableSortedBag(SortedBag<E> bag) {
super(bag); super(bag);
} }
@ -93,21 +93,22 @@ public final class UnmodifiableSortedBag
* @throws IOException * @throws IOException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();
collection = (Collection) in.readObject(); collection = (Collection<E>) in.readObject();
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public Iterator iterator() { public Iterator<E> iterator() {
return UnmodifiableIterator.decorate(getCollection().iterator()); return UnmodifiableIterator.decorate(decorated().iterator());
} }
public boolean add(Object object) { public boolean add(E object) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public boolean addAll(Collection coll) { public boolean addAll(Collection<? extends E> coll) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -119,16 +120,16 @@ public final class UnmodifiableSortedBag
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public boolean removeAll(Collection coll) { public boolean removeAll(Collection<?> coll) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public boolean retainAll(Collection coll) { public boolean retainAll(Collection<?> coll) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public boolean add(Object object, int count) { public boolean add(E object, int count) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -136,8 +137,8 @@ public final class UnmodifiableSortedBag
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public Set uniqueSet() { public Set<E> uniqueSet() {
Set set = getBag().uniqueSet(); Set<E> set = decorated().uniqueSet();
return UnmodifiableSet.decorate(set); return UnmodifiableSet.decorate(set);
} }