From f98c8827f62fa80e73ab196d0bf112b058f87242 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 3 Jun 2004 22:26:52 +0000 Subject: [PATCH] Reinstate FixedSizeSortedMap superclass to avoid binary incompatibility git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131771 13f79535-47bb-0310-9956-ffa450edef68 --- ...zeSortedMap.emptyCollection.version3.1.obj | Bin 217 -> 155 bytes ...izeSortedMap.fullCollection.version3.1.obj | Bin 480 -> 418 bytes .../collections/map/FixedSizeSortedMap.java | 92 +++++++++++++++--- 3 files changed, 79 insertions(+), 13 deletions(-) diff --git a/data/test/FixedSizeSortedMap.emptyCollection.version3.1.obj b/data/test/FixedSizeSortedMap.emptyCollection.version3.1.obj index 0be17db251c4a9c65fb96360bdc2c5df65b53869..bdfaf67e3a03a2c9edf584da3b2b8ea0a4d53ae5 100644 GIT binary patch delta 18 Zcmcb~IGb^TEr)jEEl>N`Hm(z!!vH{>2M_=N delta 40 wcmbQuc$0C0E&sA3&!alH_HJcjV5lf!(4WYm!|j_`ke<$TaXsI~l8LTi05d-h+5i9m diff --git a/data/test/FixedSizeSortedMap.fullCollection.version3.1.obj b/data/test/FixedSizeSortedMap.fullCollection.version3.1.obj index e261e5370721bb5d1a75af7319bc5ea8fba00b52..0260e21b9f2b6b7a91404fa005f6a47c6a9f53ac 100644 GIT binary patch delta 25 hcmaFByoh;%Er)jEEl>N`Hm)0+l^7XiCof~P0swe$2%!J~ delta 47 zcmZ3){D66aE&sA3&!alH_HJcjV5lf!(4WYm!|j_`ke<$TaXsI~l8vrPjEr)VGZ?J^ DqHqu{ diff --git a/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java b/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java index 166b6a590..810ab4811 100644 --- a/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java +++ b/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java @@ -15,9 +15,20 @@ */ package org.apache.commons.collections.map; -import java.util.Comparator; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; import java.util.SortedMap; +import org.apache.commons.collections.BoundedMap; +import org.apache.commons.collections.collection.UnmodifiableCollection; +import org.apache.commons.collections.set.UnmodifiableSet; + /** * Decorates another SortedMap to fix the size blocking add/remove. *

@@ -34,14 +45,17 @@ import java.util.SortedMap; * This class is Serializable from Commons Collections 3.1. * * @since Commons Collections 3.0 - * @version $Revision: 1.7 $ $Date: 2004/04/09 10:36:01 $ + * @version $Revision: 1.8 $ $Date: 2004/06/03 22:26:52 $ * * @author Stephen Colebourne * @author Paul Jack */ public class FixedSizeSortedMap - extends FixedSizeMap - implements SortedMap { + extends AbstractSortedMapDecorator + implements SortedMap, BoundedMap, Serializable { + + /** Serialization version */ + private static final long serialVersionUID = 3126019624511683653L; /** * Factory method to create a fixed size sorted map. @@ -64,7 +78,6 @@ public class FixedSizeSortedMap super(map); } - //----------------------------------------------------------------------- /** * Gets the map being decorated. * @@ -74,6 +87,63 @@ public class FixedSizeSortedMap return (SortedMap) map; } + //----------------------------------------------------------------------- + /** + * Write the map out using a custom routine. + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + out.writeObject(map); + } + + /** + * Read the map in using a custom routine. + */ + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + map = (Map) in.readObject(); + } + + //----------------------------------------------------------------------- + public Object put(Object key, Object value) { + if (map.containsKey(key) == false) { + throw new IllegalArgumentException("Cannot put new key/value pair - Map is fixed size"); + } + return map.put(key, value); + } + + public void putAll(Map mapToCopy) { + for (Iterator it = mapToCopy.keySet().iterator(); it.hasNext(); ) { + if (mapToCopy.containsKey(it.next()) == false) { + throw new IllegalArgumentException("Cannot put new key/value pair - Map is fixed size"); + } + } + map.putAll(mapToCopy); + } + + public void clear() { + throw new UnsupportedOperationException("Map is fixed size"); + } + + public Object remove(Object key) { + throw new UnsupportedOperationException("Map is fixed size"); + } + + public Set entrySet() { + Set set = map.entrySet(); + return UnmodifiableSet.decorate(set); + } + + public Set keySet() { + Set set = map.keySet(); + return UnmodifiableSet.decorate(set); + } + + public Collection values() { + Collection coll = map.values(); + return UnmodifiableCollection.decorate(coll); + } + //----------------------------------------------------------------------- public SortedMap subMap(Object fromKey, Object toKey) { SortedMap map = getSortedMap().subMap(fromKey, toKey); @@ -90,16 +160,12 @@ public class FixedSizeSortedMap return new FixedSizeSortedMap(map); } - public Comparator comparator() { - return getSortedMap().comparator(); + public boolean isFull() { + return true; } - public Object firstKey() { - return getSortedMap().firstKey(); - } - - public Object lastKey() { - return getSortedMap().lastKey(); + public int maxSize() { + return size(); } }