From 6965d41836b7c55c708a885a6cdf94106047c070 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Tue, 13 May 2008 06:53:35 +0000 Subject: [PATCH] Applying my patch from COLLECTIONS-221 - making the CompositeMap, CompositeSet and CompositeCollection serializable. The only difference from the patch is that the creation of the obj files in TestCompositeMap is commented out git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@655751 13f79535-47bb-0310-9956-ffa450edef68 --- ...eCollection.emptyCollection.version3.3.obj | Bin 0 -> 253 bytes ...teCollection.fullCollection.version3.3.obj | Bin 0 -> 381 bytes ...ompositeMap.emptyCollection.version3.3.obj | Bin 0 -> 354 bytes ...CompositeMap.fullCollection.version3.3.obj | Bin 0 -> 605 bytes ...ompositeSet.emptyCollection.version3.3.obj | Bin 0 -> 465 bytes ...CompositeSet.fullCollection.version3.3.obj | Bin 0 -> 866 bytes .../collection/CompositeCollection.java | 5 +- .../commons/collections/map/CompositeMap.java | 6 +- .../collection/TestCompositeCollection.java | 12 ++++ .../collections/map/EmptyMapMutator.java | 43 ++++++++++++++ .../collections/map/TestCompositeMap.java | 31 +++++----- .../collections/set/EmptySetMutator.java | 55 ++++++++++++++++++ .../collections/set/TestCompositeSet.java | 34 +++++------ 13 files changed, 143 insertions(+), 43 deletions(-) create mode 100644 data/test/CompositeCollection.emptyCollection.version3.3.obj create mode 100644 data/test/CompositeCollection.fullCollection.version3.3.obj create mode 100644 data/test/CompositeMap.emptyCollection.version3.3.obj create mode 100644 data/test/CompositeMap.fullCollection.version3.3.obj create mode 100644 data/test/CompositeSet.emptyCollection.version3.3.obj create mode 100644 data/test/CompositeSet.fullCollection.version3.3.obj create mode 100644 src/test/org/apache/commons/collections/map/EmptyMapMutator.java create mode 100644 src/test/org/apache/commons/collections/set/EmptySetMutator.java diff --git a/data/test/CompositeCollection.emptyCollection.version3.3.obj b/data/test/CompositeCollection.emptyCollection.version3.3.obj new file mode 100644 index 0000000000000000000000000000000000000000..4c19ee1571e3493b130742b888602f574a7270ce GIT binary patch literal 253 zcmZ4UmVvdnh`~0$C|xhHATc>3RWCU|H#a}87)a;jq$ZbSqO$dz^K%RGi!)17o#FE8 ze-*z?+RM3!iGeAafjKcJr-VT~+9xZqEK$F-Br``Jq0-uifjzghB(WsFsDvTV2WYE4 z#8!Q%tw0)XD-s)M1ct3D2xEOAMp{=Clor9P)&p4$bS=y{>$@IW3Dxx}XPFonDhe2Y Gpa1|Df?b3F literal 0 HcmV?d00001 diff --git a/data/test/CompositeCollection.fullCollection.version3.3.obj b/data/test/CompositeCollection.fullCollection.version3.3.obj new file mode 100644 index 0000000000000000000000000000000000000000..b0daa230f1a1453a9247b0c308f868b3cfee81f9 GIT binary patch literal 381 zcmZ4UmVvdnh`~0$C|xhHATc>3RWCU|H#a}87)a;jq$ZbSqO$dz^K%RGi!)17o#FE8 ze-*z?+RM3!iGeAafjKcJr-VT~+9xZqEK$F-Br``Jq0-uifjzghB(WsFsDvTV2WYE4 z#8!Q%tw0)XD-s)M1ct3D2xEOAMp{=Clor9P)&p4$bS=y{>$@IW3Dxx}XPFonDhe1F z7+8S*76dsGqS7O=I3qZ3RWCU|H#a}87)a;jq$ZbSg4nr<1$xf;xdr*fnI);d zi3O{ZBYhWKUA2#ifhn4S6Q~0sQ^Ft+?UR*QmZ)D^l9{6qRA}wPz@A%Ll30>oRKj56 z1GGjTVvRo38Xyg~MjvR6KC(3`Kofi+x~(e;N{e8|>w%2d0~!DS!G^Y1?mpa13=9)>Irgp14!Ol}NZIr)hxZi&f2CwVe(mShyA7H8z= uq*N5xI{*z}VBjg|0FnYAW(CkRBO-#vHMgLo65-Zca^gHs{CnBJjsgJV%X)VJ literal 0 HcmV?d00001 diff --git a/data/test/CompositeMap.fullCollection.version3.3.obj b/data/test/CompositeMap.fullCollection.version3.3.obj new file mode 100644 index 0000000000000000000000000000000000000000..9262aadd41d056c013e4e898768698b2e692d3ff GIT binary patch literal 605 zcma)4J5Iwu6nx}MfC4Ch3Q-`@*%B>CARz)siKtN;HqK%P*6d=hlbC{%jyq5T1t&m4 zoPdHR6$KR%XMlNj_>>f$+1)quWmjj0@1(_(HIUh!#l_&yCM!CD_4h) zPjiRQMJm*3LTS;d3lCe`qnZsO83$T*24-Uu4Tu){|+vzCfST3adsdzQ+5xuTS% zO2$|y#!{jR0_xJ*stH^%< literal 0 HcmV?d00001 diff --git a/data/test/CompositeSet.emptyCollection.version3.3.obj b/data/test/CompositeSet.emptyCollection.version3.3.obj new file mode 100644 index 0000000000000000000000000000000000000000..1e13dcc4f533d594bae5117ccbee0c94a61f0e3f GIT binary patch literal 465 zcmZ4UmVvdnh(SNUC|xhHATc>3RWCU|H#a}87)a;jq$ZbSg4o5WC3?>Jxdr*fnI);g zsU?qhUx|LR!c>QefuW*^!Ipq-gh>cPoZ+Uc|5f}pX)os@CI+Tx2Ij<^oDv4{XrHXa zvPAvTlFS@^gi3242KL<2lEjkyq7sHcAE2%J5I5^X-3+ARZbo7Qjet5GVU`Ml=?gK^ zx}u=82xhe&$ZDW#Va8eC_0USFu1`4&@^JwJ0|O&4)C56}gsAjLEY1Li%PyDJsnd3B zH(>^;D(3;J6R>vxl0Z-a)L=v)pg_Uwnp;p(2{a1osw|nKOC_?G%w}R>^kLvk&d)1J X%*;zoDPiD83L>C#pz8}6>KHfxfjOtQ literal 0 HcmV?d00001 diff --git a/data/test/CompositeSet.fullCollection.version3.3.obj b/data/test/CompositeSet.fullCollection.version3.3.obj new file mode 100644 index 0000000000000000000000000000000000000000..e22530830884688ee696ec2c3f4145d8b90bbdec GIT binary patch literal 866 zcmZ4UmVvdnh(SNUC|xhHATc>3RWCU|H#a}87)a;jq$ZbSg4o5WC3?>Jxdr*fnI);g zsU?qhUx|LR!c>QefuW*^!Ipq-gh>cPoZ+Uc|5f}pX)os@CI+Tx2Ij<^oDv4{XrHXa zvPAvTlFS@^gi3242KL<2lEjkyq7sHcAE2%J5I5^X-3+ARZbo7Qjet5GVU`Ml=?gK^ zx}u=82xhe&$ZDW#Va8eC_0USFu1`4&@^JwJ0|O&4)C56}gsAjLEY1Li%PyDJsnd3B zH(>^;D(3;JQ?Pdck_-$&aP>KfdFgtdc_pdosYODM7A*PR*lxkZ!05@qT9%konhFe0 z0kFAXb$+F}NvTC`Yo^L_PkGP{vz(=bfi)zfC^Z#mC_h4Ra0W17GJMU2O%iSe0gViX z8Cl3s$H2wF4OGpCQ0-J%k~+sPq2*n`R~evUCltj3KpR{$(=$qddXSvsl3$vXliINP zke6omZx)~~7ZhC%B4EEVpgPMfCqJ>|*4vYdZrgl#1JvV&s^kIFs}9N)mzg TrIax6Bc)lOa$s@-IgSGW3;`h6 literal 0 HcmV?d00001 diff --git a/src/java/org/apache/commons/collections/collection/CompositeCollection.java b/src/java/org/apache/commons/collections/collection/CompositeCollection.java index 3ba350cb2..dd6296539 100644 --- a/src/java/org/apache/commons/collections/collection/CompositeCollection.java +++ b/src/java/org/apache/commons/collections/collection/CompositeCollection.java @@ -16,6 +16,7 @@ */ package org.apache.commons.collections.collection; +import java.io.Serializable; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; @@ -40,7 +41,7 @@ import org.apache.commons.collections.list.UnmodifiableList; * @author Stephen Colebourne * @author Phil Steitz */ -public class CompositeCollection implements Collection { +public class CompositeCollection implements Collection, Serializable { /** CollectionMutator to handle changes to the collection */ protected CollectionMutator mutator; @@ -393,7 +394,7 @@ public class CompositeCollection implements Collection { /** * Pluggable strategy to handle changes to the composite. */ - public interface CollectionMutator { + public interface CollectionMutator extends Serializable { /** * Called when an object is to be added to the composite. diff --git a/src/java/org/apache/commons/collections/map/CompositeMap.java b/src/java/org/apache/commons/collections/map/CompositeMap.java index 7fa3c460d..bd8394557 100644 --- a/src/java/org/apache/commons/collections/map/CompositeMap.java +++ b/src/java/org/apache/commons/collections/map/CompositeMap.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections.map; +import java.io.Serializable; + import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -43,7 +45,7 @@ import org.apache.commons.collections.set.CompositeSet; * * @author Brian McCallister */ -public class CompositeMap implements Map { +public class CompositeMap implements Map, Serializable { /** Array of all maps in the composite */ private Map[] composite; @@ -479,7 +481,7 @@ public class CompositeMap implements Map { * mutators in a CompositeMap, as well as providing a hook for * callbacks on key collisions. */ - public static interface MapMutator { + public static interface MapMutator extends Serializable { /** * Called when adding a new Composited Map results in a * key collision. diff --git a/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java b/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java index dc5656d1a..52e07cfb4 100644 --- a/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java +++ b/src/test/org/apache/commons/collections/collection/TestCompositeCollection.java @@ -355,4 +355,16 @@ public class TestCompositeCollection extends AbstractTestCollection { assertTrue(c.contains("1")); assertEquals(2, c.size()); } + + public String getCompatibilityVersion() { + return "3.3"; + } + +// public void testCreate() throws Exception { +// resetEmpty(); +// writeExternalFormToDisk((java.io.Serializable) collection, "/tmp/CompositeCollection.emptyCollection.version3.3.obj"); +// resetFull(); +// writeExternalFormToDisk((java.io.Serializable) collection, "/tmp/CompositeCollection.fullCollection.version3.3.obj"); +// } + } diff --git a/src/test/org/apache/commons/collections/map/EmptyMapMutator.java b/src/test/org/apache/commons/collections/map/EmptyMapMutator.java new file mode 100644 index 000000000..58d4de4f2 --- /dev/null +++ b/src/test/org/apache/commons/collections/map/EmptyMapMutator.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.collections.map; + +import java.util.Map; +import java.util.Collection; + +/** + * This class is used in TestCompositeMap. When testing serialization, + * the class has to be separate of TestCompositeMap, else the test + * class also has to be serialized. + */ +class EmptyMapMutator implements CompositeMap.MapMutator { + public void resolveCollision(CompositeMap composite, + Map existing, + Map added, + Collection intersect) { + // Do nothing + } + + public Object put(CompositeMap map, Map[] composited, Object key, Object value) { + return composited[0].put(key, value); + } + + public void putAll(CompositeMap map, Map[] composited, Map t) { + composited[0].putAll(t); + } + +} diff --git a/src/test/org/apache/commons/collections/map/TestCompositeMap.java b/src/test/org/apache/commons/collections/map/TestCompositeMap.java index dfff654c0..17202600b 100644 --- a/src/test/org/apache/commons/collections/map/TestCompositeMap.java +++ b/src/test/org/apache/commons/collections/map/TestCompositeMap.java @@ -58,23 +58,7 @@ public class TestCompositeMap extends AbstractTestMap { public Map makeEmptyMap() { CompositeMap map = new CompositeMap(); map.addComposited(new HashMap()); - map.setMutator(new CompositeMap.MapMutator() { - public void resolveCollision(CompositeMap composite, - Map existing, - Map added, - Collection intersect) { - // Do nothing - } - - public Object put(CompositeMap map, Map[] composited, Object key, Object value) { - return composited[0].put(key, value); - } - - public void putAll(CompositeMap map, Map[] composited, Map t) { - composited[0].putAll(t); - } - - }); + map.setMutator( new EmptyMapMutator() ); return map; } @@ -223,5 +207,16 @@ public class TestCompositeMap extends AbstractTestMap { map.putAll(null); assertTrue(pass); } -} + public String getCompatibilityVersion() { + return "3.3"; + } + +// public void testCreate() throws Exception { +// resetEmpty(); +// writeExternalFormToDisk((java.io.Serializable) map, "/tmp/CompositeMap.emptyCollection.version3.3.obj"); +// resetFull(); +// writeExternalFormToDisk((java.io.Serializable) map, "/tmp/CompositeMap.fullCollection.version3.3.obj"); +// } + +} diff --git a/src/test/org/apache/commons/collections/set/EmptySetMutator.java b/src/test/org/apache/commons/collections/set/EmptySetMutator.java new file mode 100644 index 000000000..cc57bfd04 --- /dev/null +++ b/src/test/org/apache/commons/collections/set/EmptySetMutator.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.collections.set; + +import java.util.Collection; +import java.util.Set; + +import org.apache.commons.collections.collection.CompositeCollection; + +/** + * This class is used in TestCompositeSet. When testing serialization, + * the class has to be separate of TestCompositeSet, else the test + * class also has to be serialized. + */ +class EmptySetMutator implements CompositeSet.SetMutator { + private Set contained; + + public EmptySetMutator(Set set) { + this.contained = set; + } + + public void resolveCollision(CompositeSet comp, Set existing, + Set added, Collection intersects) { + throw new IllegalArgumentException(); + } + + public boolean add(CompositeCollection composite, + Collection[] collections, Object obj) { + return contained.add(obj); + } + + public boolean addAll(CompositeCollection composite, + Collection[] collections, Collection coll) { + return contained.addAll(coll); + } + + public boolean remove(CompositeCollection composite, + Collection[] collections, Object obj) { + return contained.remove(obj); + } +} diff --git a/src/test/org/apache/commons/collections/set/TestCompositeSet.java b/src/test/org/apache/commons/collections/set/TestCompositeSet.java index 155cb098c..8d46697b2 100644 --- a/src/test/org/apache/commons/collections/set/TestCompositeSet.java +++ b/src/test/org/apache/commons/collections/set/TestCompositeSet.java @@ -48,27 +48,7 @@ public class TestCompositeSet extends AbstractTestSet { public Set makeEmptySet() { final HashSet contained = new HashSet(); CompositeSet set = new CompositeSet(contained); - set.setMutator(new CompositeSet.SetMutator() { - public void resolveCollision(CompositeSet comp, Set existing, - Set added, Collection intersects) { - throw new IllegalArgumentException(); - } - - public boolean add(CompositeCollection composite, - Collection[] collections, Object obj) { - return contained.add(obj); - } - - public boolean addAll(CompositeCollection composite, - Collection[] collections, Collection coll) { - return contained.addAll(coll); - } - - public boolean remove(CompositeCollection composite, - Collection[] collections, Object obj) { - return contained.remove(obj); - } - }); + set.setMutator( new EmptySetMutator(contained) ); return set; } @@ -173,4 +153,16 @@ public class TestCompositeSet extends AbstractTestSet { // expected } } + + public String getCompatibilityVersion() { + return "3.3"; + } + +// public void testCreate() throws Exception { +// resetEmpty(); +// writeExternalFormToDisk((java.io.Serializable) collection, "/tmp/CompositeSet.emptyCollection.version3.3.obj"); +// resetFull(); +// writeExternalFormToDisk((java.io.Serializable) collection, "/tmp/CompositeSet.fullCollection.version3.3.obj"); +// } + }