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
This commit is contained in:
Henri Yandell 2008-05-13 06:53:35 +00:00
parent 4ac9d2bf8c
commit 6965d41836
13 changed files with 143 additions and 43 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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.

View File

@ -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.

View File

@ -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");
// }
}

View File

@ -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);
}
}

View File

@ -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");
// }
}

View File

@ -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);
}
}

View File

@ -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");
// }
}