diff --git a/data/test/CompositeCollection.emptyCollection.version3.3.obj b/data/test/CompositeCollection.emptyCollection.version3.3.obj new file mode 100644 index 000000000..4c19ee157 Binary files /dev/null and b/data/test/CompositeCollection.emptyCollection.version3.3.obj differ diff --git a/data/test/CompositeCollection.fullCollection.version3.3.obj b/data/test/CompositeCollection.fullCollection.version3.3.obj new file mode 100644 index 000000000..b0daa230f Binary files /dev/null and b/data/test/CompositeCollection.fullCollection.version3.3.obj differ diff --git a/data/test/CompositeMap.emptyCollection.version3.3.obj b/data/test/CompositeMap.emptyCollection.version3.3.obj new file mode 100644 index 000000000..eb4dfd563 Binary files /dev/null and b/data/test/CompositeMap.emptyCollection.version3.3.obj differ diff --git a/data/test/CompositeMap.fullCollection.version3.3.obj b/data/test/CompositeMap.fullCollection.version3.3.obj new file mode 100644 index 000000000..9262aadd4 Binary files /dev/null and b/data/test/CompositeMap.fullCollection.version3.3.obj differ diff --git a/data/test/CompositeSet.emptyCollection.version3.3.obj b/data/test/CompositeSet.emptyCollection.version3.3.obj new file mode 100644 index 000000000..1e13dcc4f Binary files /dev/null and b/data/test/CompositeSet.emptyCollection.version3.3.obj differ diff --git a/data/test/CompositeSet.fullCollection.version3.3.obj b/data/test/CompositeSet.fullCollection.version3.3.obj new file mode 100644 index 000000000..e22530830 Binary files /dev/null and b/data/test/CompositeSet.fullCollection.version3.3.obj differ 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"); +// } + }