You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2004/06/04 00:26:52 UTC
cvs commit: jakarta-commons/collections/data/test FixedSizeSortedMap.fullCollection.version3.1.obj FixedSizeSortedMap.emptyCollection.version3.1.obj
scolebourne 2004/06/03 15:26:52
Modified: collections/src/java/org/apache/commons/collections/map
FixedSizeSortedMap.java
collections/data/test
FixedSizeSortedMap.fullCollection.version3.1.obj
FixedSizeSortedMap.emptyCollection.version3.1.obj
Log:
Reinstate FixedSizeSortedMap superclass to avoid binary incompatibility
Revision Changes Path
1.8 +79 -13 jakarta-commons/collections/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java
Index: FixedSizeSortedMap.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/map/FixedSizeSortedMap.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FixedSizeSortedMap.java 9 Apr 2004 10:36:01 -0000 1.7
+++ FixedSizeSortedMap.java 3 Jun 2004 22:26:52 -0000 1.8
@@ -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 <code>SortedMap</code> to fix the size blocking add/remove.
* <p>
@@ -40,8 +51,11 @@
* @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 @@
super(map);
}
- //-----------------------------------------------------------------------
/**
* Gets the map being decorated.
*
@@ -75,6 +88,63 @@
}
//-----------------------------------------------------------------------
+ /**
+ * 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);
return new FixedSizeSortedMap(map);
@@ -90,16 +160,12 @@
return new FixedSizeSortedMap(map);
}
- public Comparator comparator() {
- return getSortedMap().comparator();
- }
-
- public Object firstKey() {
- return getSortedMap().firstKey();
+ public boolean isFull() {
+ return true;
}
- public Object lastKey() {
- return getSortedMap().lastKey();
+ public int maxSize() {
+ return size();
}
}
1.3 +2 -3 jakarta-commons/collections/data/test/FixedSizeSortedMap.fullCollection.version3.1.obj
<<Binary file>>
1.3 +1 -2 jakarta-commons/collections/data/test/FixedSizeSortedMap.emptyCollection.version3.1.obj
<<Binary file>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org