Author: bayard Date: Tue Sep 15 05:56:22 2009 New Revision: 815087 URL: http://svn.apache.org/viewvc?rev=815087&view=rev Log: 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() ------------------------------------------------------------------------ Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java?rev=815087&r1=815086&r2=815087&view=diff ============================================================================== --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java (original) +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java Tue Sep 15 05:56:22 2009 @@ -42,8 +42,8 @@ * * @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 @@ * @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 @@ * @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 @@ * @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 @@ 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)); } }