Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.
Also see the following revisions: ------------------------------------------------------------------------ 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@815017 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8d2b27c1d5
commit
6fa2bab941
|
@ -41,8 +41,8 @@ import org.apache.commons.collections.set.UnmodifiableSet;
|
|||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public final class UnmodifiableBag
|
||||
extends AbstractBagDecorator implements Unmodifiable, Serializable {
|
||||
public final class UnmodifiableBag<E>
|
||||
extends AbstractBagDecorator<E> implements Unmodifiable, Serializable {
|
||||
|
||||
/** Serialization version */
|
||||
private static final long serialVersionUID = -1873799975157099624L;
|
||||
|
@ -56,11 +56,11 @@ public final class UnmodifiableBag
|
|||
* @return an unmodifiable Bag
|
||||
* @throws IllegalArgumentException if bag is null
|
||||
*/
|
||||
public static Bag decorate(Bag bag) {
|
||||
public static <E> Bag<E> decorate(Bag<E> bag) {
|
||||
if (bag instanceof Unmodifiable) {
|
||||
return bag;
|
||||
}
|
||||
return new UnmodifiableBag(bag);
|
||||
return new UnmodifiableBag<E>(bag);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -70,7 +70,7 @@ public final class UnmodifiableBag
|
|||
* @param bag the bag to decorate, must not be null
|
||||
* @throws IllegalArgumentException if bag is null
|
||||
*/
|
||||
private UnmodifiableBag(Bag bag) {
|
||||
private UnmodifiableBag(Bag<E> bag) {
|
||||
super(bag);
|
||||
}
|
||||
|
||||
|
@ -93,21 +93,22 @@ public final class UnmodifiableBag
|
|||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection) in.readObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Iterator iterator() {
|
||||
return UnmodifiableIterator.decorate(getCollection().iterator());
|
||||
public Iterator<E> iterator() {
|
||||
return UnmodifiableIterator.<E>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();
|
||||
}
|
||||
|
||||
|
@ -119,16 +120,16 @@ public final class UnmodifiableBag
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -136,9 +137,9 @@ public final class UnmodifiableBag
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Set uniqueSet() {
|
||||
Set set = getBag().uniqueSet();
|
||||
return UnmodifiableSet.decorate(set);
|
||||
public Set<E> uniqueSet() {
|
||||
Set<E> set = decorated().uniqueSet();
|
||||
return UnmodifiableSet.<E>decorate(set);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue