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@815087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:56:22 +00:00
parent 51a2b9eae0
commit cb26da928c
1 changed files with 29 additions and 34 deletions

View File

@ -42,8 +42,8 @@ import org.apache.commons.collections.set.UnmodifiableSet;
*
* @author Stephen Colebourne
*/
public final class UnmodifiableSortedMap
extends AbstractSortedMapDecorator
public final class UnmodifiableSortedMap<K, V>
extends AbstractSortedMapDecorator<K, V>
implements Unmodifiable, Serializable {
/** Serialization version */
@ -55,11 +55,11 @@ public final class UnmodifiableSortedMap
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
public static SortedMap decorate(SortedMap map) {
public static <K, V> SortedMap<K, V> decorate(SortedMap<K, V> map) {
if (map instanceof Unmodifiable) {
return map;
}
return new UnmodifiableSortedMap(map);
return new UnmodifiableSortedMap<K, V>(map);
}
//-----------------------------------------------------------------------
@ -69,10 +69,10 @@ public final class UnmodifiableSortedMap
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
private UnmodifiableSortedMap(SortedMap map) {
private UnmodifiableSortedMap(SortedMap<K, V> map) {
super(map);
}
//-----------------------------------------------------------------------
/**
* Write the map out using a custom routine.
@ -94,9 +94,10 @@ public final class UnmodifiableSortedMap
* @throws ClassNotFoundException
* @since Commons Collections 3.1
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map) in.readObject();
map = (Map<K, V>) in.readObject();
}
//-----------------------------------------------------------------------
@ -104,59 +105,53 @@ public final class UnmodifiableSortedMap
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();
return UnmodifiableEntrySet.decorate(set);
public Set<Map.Entry<K, V>> entrySet() {
return UnmodifiableEntrySet.decorate(super.entrySet());
}
public Set keySet() {
Set set = super.keySet();
return UnmodifiableSet.decorate(set);
public Set<K> keySet() {
return UnmodifiableSet.decorate(super.keySet());
}
public Collection values() {
Collection coll = super.values();
return UnmodifiableCollection.decorate(coll);
public Collection<V> values() {
return UnmodifiableCollection.decorate(super.values());
}
//-----------------------------------------------------------------------
public Object firstKey() {
return getSortedMap().firstKey();
public K firstKey() {
return decorated().firstKey();
}
public Object lastKey() {
return getSortedMap().lastKey();
public K lastKey() {
return decorated().lastKey();
}
public Comparator comparator() {
return getSortedMap().comparator();
public Comparator<? super K> comparator() {
return decorated().comparator();
}
public SortedMap subMap(Object fromKey, Object toKey) {
SortedMap map = getSortedMap().subMap(fromKey, toKey);
return new UnmodifiableSortedMap(map);
public SortedMap<K, V> subMap(K fromKey, K toKey) {
return new UnmodifiableSortedMap<K, V>(decorated().subMap(fromKey, toKey));
}
public SortedMap headMap(Object toKey) {
SortedMap map = getSortedMap().headMap(toKey);
return new UnmodifiableSortedMap(map);
public SortedMap<K, V> headMap(K toKey) {
return new UnmodifiableSortedMap<K, V>(decorated().headMap(toKey));
}
public SortedMap tailMap(Object fromKey) {
SortedMap map = getSortedMap().tailMap(fromKey);
return new UnmodifiableSortedMap(map);
public SortedMap<K, V> tailMap(K fromKey) {
return new UnmodifiableSortedMap<K, V>(decorated().tailMap(fromKey));
}
}