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

Also see the following revisions:

    ------------------------------------------------------------------------
    r471189 | scolebourne | 2006-11-04 05:57:57 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getMap(), getOrderedMap() and getSortedMap() - use decorated()
    ------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815086 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:56:20 +00:00
parent ce592ac817
commit 51a2b9eae0
1 changed files with 17 additions and 24 deletions

View File

@ -24,12 +24,10 @@ import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.MapIterator;
import org.apache.commons.collections.OrderedMap;
import org.apache.commons.collections.OrderedMapIterator;
import org.apache.commons.collections.Unmodifiable;
import org.apache.commons.collections.collection.UnmodifiableCollection;
import org.apache.commons.collections.iterators.UnmodifiableMapIterator;
import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator;
import org.apache.commons.collections.set.UnmodifiableSet;
@ -45,9 +43,8 @@ import org.apache.commons.collections.set.UnmodifiableSet;
*
* @author Stephen Colebourne
*/
public final class UnmodifiableOrderedMap
extends AbstractOrderedMapDecorator
implements Unmodifiable, Serializable {
public final class UnmodifiableOrderedMap<K, V> extends AbstractOrderedMapDecorator<K, V> implements
Unmodifiable, Serializable {
/** Serialization version */
private static final long serialVersionUID = 8136428161720526266L;
@ -58,11 +55,11 @@ public final class UnmodifiableOrderedMap
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
public static OrderedMap decorate(OrderedMap map) {
public static <K, V> OrderedMap<K, V> decorate(OrderedMap<K, V> map) {
if (map instanceof Unmodifiable) {
return map;
}
return new UnmodifiableOrderedMap(map);
return new UnmodifiableOrderedMap<K, V>(map);
}
//-----------------------------------------------------------------------
@ -72,7 +69,7 @@ public final class UnmodifiableOrderedMap
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
private UnmodifiableOrderedMap(OrderedMap map) {
private UnmodifiableOrderedMap(OrderedMap<K, V> map) {
super(map);
}
@ -97,19 +94,15 @@ public final class UnmodifiableOrderedMap
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
}
//-----------------------------------------------------------------------
public MapIterator mapIterator() {
MapIterator it = getOrderedMap().mapIterator();
return UnmodifiableMapIterator.decorate(it);
}
public OrderedMapIterator orderedMapIterator() {
OrderedMapIterator it = getOrderedMap().orderedMapIterator();
public OrderedMapIterator<K, V> mapIterator() {
OrderedMapIterator<K, V> it = decorated().mapIterator();
return UnmodifiableOrderedMapIterator.decorate(it);
}
@ -117,30 +110,30 @@ public final class UnmodifiableOrderedMap
throw new UnsupportedOperationException();
}
public Object put(Object key, Object value) {
public V put(K key, V value) {
throw new UnsupportedOperationException();
}
public void putAll(Map mapToCopy) {
public void putAll(Map<? extends K, ? extends V> mapToCopy) {
throw new UnsupportedOperationException();
}
public Object remove(Object key) {
public V remove(Object key) {
throw new UnsupportedOperationException();
}
public Set entrySet() {
Set set = super.entrySet();
public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> set = super.entrySet();
return UnmodifiableEntrySet.decorate(set);
}
public Set keySet() {
Set set = super.keySet();
public Set<K> keySet() {
Set<K> set = super.keySet();
return UnmodifiableSet.decorate(set);
}
public Collection values() {
Collection coll = super.values();
public Collection<V> values() {
Collection<V> coll = super.values();
return UnmodifiableCollection.decorate(coll);
}