Created a custom serializer for IdentityHashMap. Refactored the existing collections-based serializers to use common code. Suggested by: mmendez Review by: jat (pair prog) git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2323 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/ArrayList_CustomFieldSerializer.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/ArrayList_CustomFieldSerializer.java index cc9ddd2..999b788 100644 --- a/user/src/com/google/gwt/user/client/rpc/core/java/util/ArrayList_CustomFieldSerializer.java +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/ArrayList_CustomFieldSerializer.java
@@ -28,19 +28,11 @@ public static void deserialize(SerializationStreamReader streamReader, ArrayList instance) throws SerializationException { - int size = streamReader.readInt(); - for (int i = 0; i < size; ++i) { - Object obj = streamReader.readObject(); - instance.add(obj); - } + Collection_CustomFieldSerializerBase.deserialize(streamReader, instance); } public static void serialize(SerializationStreamWriter streamWriter, ArrayList instance) throws SerializationException { - int size = instance.size(); - streamWriter.writeInt(size); - for (Object obj : instance) { - streamWriter.writeObject(obj); - } + Collection_CustomFieldSerializerBase.serialize(streamWriter, instance); } }
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/Collection_CustomFieldSerializerBase.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/Collection_CustomFieldSerializerBase.java new file mode 100644 index 0000000..da0dbd7 --- /dev/null +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/Collection_CustomFieldSerializerBase.java
@@ -0,0 +1,46 @@ +/* + * Copyright 2007 Google Inc. + * + * Licensed 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 com.google.gwt.user.client.rpc.core.java.util; + +import com.google.gwt.user.client.rpc.SerializationException; +import com.google.gwt.user.client.rpc.SerializationStreamReader; +import com.google.gwt.user.client.rpc.SerializationStreamWriter; + +import java.util.Collection; + +/** + * Custom field serializer for {@link java.util.ArrayList}. + */ +public final class Collection_CustomFieldSerializerBase { + + public static void deserialize(SerializationStreamReader streamReader, + Collection instance) throws SerializationException { + int size = streamReader.readInt(); + for (int i = 0; i < size; ++i) { + Object obj = streamReader.readObject(); + instance.add(obj); + } + } + + public static void serialize(SerializationStreamWriter streamWriter, + Collection instance) throws SerializationException { + int size = instance.size(); + streamWriter.writeInt(size); + for (Object obj : instance) { + streamWriter.writeObject(obj); + } + } +}
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/HashMap_CustomFieldSerializer.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/HashMap_CustomFieldSerializer.java index bb32020..34cab03 100644 --- a/user/src/com/google/gwt/user/client/rpc/core/java/util/HashMap_CustomFieldSerializer.java +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/HashMap_CustomFieldSerializer.java
@@ -20,8 +20,6 @@ import com.google.gwt.user.client.rpc.SerializationStreamWriter; import java.util.HashMap; -import java.util.Set; -import java.util.Map.Entry; /** * Custom field serializer for {@link java.util.HashMap}. @@ -30,25 +28,12 @@ public static void deserialize(SerializationStreamReader streamReader, HashMap instance) throws SerializationException { - int size = streamReader.readInt(); - - for (int i = 0; i < size; ++i) { - Object key = streamReader.readObject(); - Object value = streamReader.readObject(); - - instance.put(key, value); - } + Map_CustomFieldSerializerBase.deserialize(streamReader, instance); } public static void serialize(SerializationStreamWriter streamWriter, HashMap instance) throws SerializationException { - int size = instance.size(); - streamWriter.writeInt(size); - - for (Entry entry : (Set<Entry>) instance.entrySet()) { - streamWriter.writeObject(entry.getKey()); - streamWriter.writeObject(entry.getValue()); - } + Map_CustomFieldSerializerBase.serialize(streamWriter, instance); } } \ No newline at end of file
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/HashSet_CustomFieldSerializer.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/HashSet_CustomFieldSerializer.java index d732fbe..7a99148 100644 --- a/user/src/com/google/gwt/user/client/rpc/core/java/util/HashSet_CustomFieldSerializer.java +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/HashSet_CustomFieldSerializer.java
@@ -28,17 +28,11 @@ public static void deserialize(SerializationStreamReader streamReader, HashSet instance) throws SerializationException { - int size = streamReader.readInt(); - for (int i = 0; i < size; ++i) { - instance.add(streamReader.readObject()); - } + Collection_CustomFieldSerializerBase.deserialize(streamReader, instance); } public static void serialize(SerializationStreamWriter streamWriter, HashSet instance) throws SerializationException { - streamWriter.writeInt(instance.size()); - for (Object obj : instance) { - streamWriter.writeObject(obj); - } + Collection_CustomFieldSerializerBase.serialize(streamWriter, instance); } }
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/IdentityHashMap_CustomFieldSerializer.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/IdentityHashMap_CustomFieldSerializer.java new file mode 100644 index 0000000..0f70860 --- /dev/null +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/IdentityHashMap_CustomFieldSerializer.java
@@ -0,0 +1,39 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed 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 com.google.gwt.user.client.rpc.core.java.util; + +import com.google.gwt.user.client.rpc.SerializationException; +import com.google.gwt.user.client.rpc.SerializationStreamReader; +import com.google.gwt.user.client.rpc.SerializationStreamWriter; + +import java.util.IdentityHashMap; + +/** + * Custom field serializer for {@link java.util.HashMap}. + */ +public final class IdentityHashMap_CustomFieldSerializer { + + public static void deserialize(SerializationStreamReader streamReader, + IdentityHashMap instance) throws SerializationException { + Map_CustomFieldSerializerBase.deserialize(streamReader, instance); + } + + public static void serialize(SerializationStreamWriter streamWriter, + IdentityHashMap instance) throws SerializationException { + Map_CustomFieldSerializerBase.serialize(streamWriter, instance); + } + +} \ No newline at end of file
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/Map_CustomFieldSerializerBase.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/Map_CustomFieldSerializerBase.java new file mode 100644 index 0000000..eea66e2 --- /dev/null +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/Map_CustomFieldSerializerBase.java
@@ -0,0 +1,54 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed 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 com.google.gwt.user.client.rpc.core.java.util; + +import com.google.gwt.user.client.rpc.SerializationException; +import com.google.gwt.user.client.rpc.SerializationStreamReader; +import com.google.gwt.user.client.rpc.SerializationStreamWriter; + +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +/** + * Custom field serializer for {@link java.util.HashMap}. + */ +public final class Map_CustomFieldSerializerBase { + + public static void deserialize(SerializationStreamReader streamReader, + Map instance) throws SerializationException { + int size = streamReader.readInt(); + + for (int i = 0; i < size; ++i) { + Object key = streamReader.readObject(); + Object value = streamReader.readObject(); + + instance.put(key, value); + } + } + + public static void serialize(SerializationStreamWriter streamWriter, + Map instance) throws SerializationException { + int size = instance.size(); + streamWriter.writeInt(size); + + for (Entry entry : (Set<Entry>) instance.entrySet()) { + streamWriter.writeObject(entry.getKey()); + streamWriter.writeObject(entry.getValue()); + } + } + +} \ No newline at end of file
diff --git a/user/src/com/google/gwt/user/client/rpc/core/java/util/Vector_CustomFieldSerializer.java b/user/src/com/google/gwt/user/client/rpc/core/java/util/Vector_CustomFieldSerializer.java index b3a4478..61b1eff 100644 --- a/user/src/com/google/gwt/user/client/rpc/core/java/util/Vector_CustomFieldSerializer.java +++ b/user/src/com/google/gwt/user/client/rpc/core/java/util/Vector_CustomFieldSerializer.java
@@ -28,20 +28,11 @@ public static void deserialize(SerializationStreamReader streamReader, Vector instance) throws SerializationException { - int size = streamReader.readInt(); - for (int i = 0; i < size; ++i) { - Object obj = streamReader.readObject(); - instance.add(obj); - } + Collection_CustomFieldSerializerBase.deserialize(streamReader, instance); } public static void serialize(SerializationStreamWriter streamWriter, Vector instance) throws SerializationException { - int size = instance.size(); - streamWriter.writeInt(size); - for (Object obj : instance) { - streamWriter.writeObject(obj); - } + Collection_CustomFieldSerializerBase.serialize(streamWriter, instance); } - }