Author: manik.surtani(a)jboss.com
Date: 2008-07-28 14:21:21 -0400 (Mon, 28 Jul 2008)
New Revision: 6416
Removed:
core/trunk/src/main/java/org/jboss/cache/util/MapCopy.java
core/trunk/src/test/java/org/jboss/cache/util/MapCopyTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
Log:
Removed MapCopy and marshaller now knows how to deal with ImmutableMapCopy
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-07-28
11:29:12 UTC (rev 6415)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-07-28
18:21:21 UTC (rev 6416)
@@ -15,7 +15,7 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.util.MapCopy;
+import org.jboss.cache.util.ImmutableMapCopy;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
@@ -63,7 +63,7 @@
protected static final int MAGICNUMBER_NODEDATA = 18;
protected static final int MAGICNUMBER_GRAVITATERESULT = 19;
protected static final int MAGICNUMBER_SHORT = 20;
- protected static final int MAGICNUMBER_MAPCOPY = 21;
+ protected static final int MAGICNUMBER_IMMUTABLE_MAPCOPY = 21;
protected static final int MAGICNUMBER_MARSHALLEDVALUE = 22;
protected static final int MAGICNUMBER_NULL = 99;
protected static final int MAGICNUMBER_SERIALIZABLE = 100;
@@ -341,9 +341,9 @@
out.writeByte(MAGICNUMBER_TREE_MAP);
marshallMap((Map) o, out, refMap);
}
- else if (o.getClass().equals(MapCopy.class))
+ else if (o.getClass().equals(ImmutableMapCopy.class))
{
- out.writeByte(MAGICNUMBER_MAPCOPY);
+ out.writeByte(MAGICNUMBER_IMMUTABLE_MAPCOPY);
marshallMap((Map) o, out, refMap);
}
else if (o.getClass().equals(HashSet.class))
@@ -584,7 +584,7 @@
return unmarshallHashSet(in, refMap);
case MAGICNUMBER_TREE_SET:
return unmarshallTreeSet(in, refMap);
- case MAGICNUMBER_MAPCOPY:
+ case MAGICNUMBER_IMMUTABLE_MAPCOPY:
return unmarshallMapCopy(in, refMap);
case MAGICNUMBER_BOOLEAN:
return in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
@@ -727,7 +727,7 @@
{
// read in as a HashMap first
Map m = unmarshallHashMap(in, refMap);
- return new MapCopy(m);
+ return new ImmutableMapCopy(m);
}
private Map unmarshallTreeMap(ObjectInputStream in, UnmarshalledReferences refMap)
throws Exception
Deleted: core/trunk/src/main/java/org/jboss/cache/util/MapCopy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/MapCopy.java 2008-07-28 11:29:12 UTC
(rev 6415)
+++ core/trunk/src/main/java/org/jboss/cache/util/MapCopy.java 2008-07-28 18:21:21 UTC
(rev 6416)
@@ -1,122 +0,0 @@
-package org.jboss.cache.util;
-
-import net.jcip.annotations.Immutable;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Contains a fixed array of read-only map entries, from a copy of an existing map.
- * This class is more lightweight for places where the copied map will just be iterated
over.
- * <p/>
- * This map is strictly read-only, and map modification methods (as well as modifications
over iterators) will throw
- * {@link UnsupportedOperationException}s.
- *
- * @author Elias Ross
- * @deprecated see ImmutableMapCopy instead.
- */
-@Immutable
-@Deprecated
-public class MapCopy<K, V> extends AbstractMap<K, V> implements Serializable
-{
-
- private static final long serialVersionUID = -958813082188242956L;
-
- private final List<Entry<K, V>> data;
-
- private transient Set<Map.Entry<K, V>> entrySet;
-
- /**
- * Copies the supplied map to an internal array.
- *
- * @param m map to copy
- */
- public MapCopy(Map<K, V> m)
- {
- data = new ArrayList<Entry<K, V>>(m.size());
- for (Map.Entry<K, V> me : m.entrySet())
- {
- if (me == null)
- throw new NullPointerException();
- data.add(new SimpleImmutableEntry<K, V>(me));
- }
- init();
- }
-
- public MapCopy()
- {
- this((Map<K, V>) Collections.emptyMap());
- }
-
- /**
- * Returns a copy of the given map.
- */
- public static <L, W> Map<L, W> copy(Map<L, W> m)
- {
- return new MapCopy<L, W>(m);
- }
-
- private void init()
- {
- this.entrySet = new AbstractSet<Map.Entry<K, V>>()
- {
- @Override
- public int size()
- {
- return data.size();
- }
-
- @Override
- public Iterator<Map.Entry<K, V>> iterator()
- {
- return new EntryIterator();
- }
- };
- }
-
- private class EntryIterator implements Iterator<Entry<K, V>>
- {
- private int index;
-
- public boolean hasNext()
- {
- return index < data.size();
- }
-
- public Entry<K, V> next()
- {
- return data.get(index++);
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- }
-
- @Override
- public Set<Map.Entry<K, V>> entrySet()
- {
- return entrySet;
- }
-
- @Override
- public int size()
- {
- return data.size();
- }
-
- private void readObject(java.io.ObjectInputStream in) throws IOException,
ClassNotFoundException
- {
- in.defaultReadObject();
- init();
- }
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/util/MapCopyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/MapCopyTest.java 2008-07-28 11:29:12 UTC
(rev 6415)
+++ core/trunk/src/test/java/org/jboss/cache/util/MapCopyTest.java 2008-07-28 18:21:21 UTC
(rev 6416)
@@ -1,155 +0,0 @@
-package org.jboss.cache.util;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.util.stream.MarshalledValueInputStream;
-import org.jboss.util.stream.MarshalledValueOutputStream;
-import org.testng.annotations.Test;
-
-@Test(groups={"functional", "transaction"})
-public class MapCopyTest
-{
- public void testSerializable() throws Exception
- {
- HashMap<String, String> hm = new HashMap<String, String>();
- hm.put(null, null);
- hm.put("y", "z");
- MapCopy<String, String> mc = new MapCopy<String, String>(hm);
- assertEquals(hm, mc);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(os);
- oos.writeObject(mc);
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- ObjectInputStream ois = new ObjectInputStream(is);
- Object o = ois.readObject();
- assertEquals(hm, o);
- }
-
- public void testSerializableWithMarshalledValueStream() throws Exception
- {
- HashMap<String, String> hm = new HashMap<String, String>();
- hm.put(null, null);
- hm.put("y", "z");
- MapCopy<String, String> mc = new MapCopy<String, String>(hm);
- assertEquals(hm, mc);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- ObjectOutputStream oos = new MarshalledValueOutputStream(os);
- oos.writeObject(mc);
- ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
- ObjectInputStream ois = new MarshalledValueInputStream(is);
- Object o = ois.readObject();
- assertEquals(hm, o);
- }
-
- public void testNull()
- {
- HashMap<String, String> hm = new HashMap<String, String>();
- hm.put(null, null);
- MapCopy<String, String> mc = new MapCopy<String, String>(hm);
- assertEquals(hm, mc);
- assertEquals(hm.toString(), mc.toString());
-
- hm.put(null, "x");
- hm.put("y", null);
- mc = new MapCopy<String, String>(hm);
- mc.toString();
- assertEquals(true, mc.containsKey("y"));
- }
-
- public void testAll()
- {
- HashMap<String, String> hm = new HashMap<String, String>();
- hm.put("a", "b");
- hm.put("b", "c");
- MapCopy<String, String> mc = new MapCopy<String, String>(hm);
- assertEquals(hm, mc);
- assertEquals(hm.size(), mc.size());
- try
- {
- mc.clear();
- fail("read only");
- }
- catch (UnsupportedOperationException e)
- {
- }
- HashMap<String, String> bhm = new HashMap<String, String>(hm);
- hm.put("b", "d");
- assertEquals(bhm, mc);
- Map.Entry<String, String> me = mc.entrySet().iterator().next();
- try
- {
- me.setValue("arg");
- fail("read only");
- }
- catch (UnsupportedOperationException e)
- {
- }
- }
-
- public void testModifications()
- {
- Map<String, String> hm = new HashMap<String, String>();
- hm.put("a", "b");
- Map<String, String> mc = new MapCopy<String, String>(hm);
-
- try
- {
- mc.put("x", "y");
- fail("should fail");
- }
- catch (UnsupportedOperationException uoe)
- {
- // ok
- }
-
- try
- {
- mc.remove("a");
- fail("should fail");
- }
- catch (UnsupportedOperationException uoe)
- {
- // ok
- }
-
- try
- {
- mc.keySet().iterator().remove();
- fail("should fail");
- }
- catch (UnsupportedOperationException uoe)
- {
- // ok
- }
-
- try
- {
- mc.entrySet().iterator().remove();
- fail("should fail");
- }
- catch (UnsupportedOperationException uoe)
- {
- // ok
- }
-
- try
- {
- mc.values().iterator().remove();
- fail("should fail");
- }
- catch (UnsupportedOperationException uoe)
- {
- // ok
- }
-
-
- }
-}