• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.collect;
16 
17 import com.google.gwt.user.client.rpc.SerializationException;
18 import com.google.gwt.user.client.rpc.SerializationStreamReader;
19 import com.google.gwt.user.client.rpc.SerializationStreamWriter;
20 
21 import java.util.Map;
22 import java.util.Map.Entry;
23 
24 /**
25  * This class contains static utility methods for writing {@link Table} GWT field serializers.
26  * Serializers should delegate to {@link #serialize} and {@link #populate}.
27  *
28  * <p>For {@link ImmutableTable}, see {@link ImmutableTable_CustomFieldSerializerBase}.
29  *
30  * @author Chris Povirk
31  */
32 final class Table_CustomFieldSerializerBase {
populate( SerializationStreamReader reader, T table)33   static <T extends StandardTable<Object, Object, Object>> T populate(
34       SerializationStreamReader reader, T table) throws SerializationException {
35     Map<?, ?> hashMap = (Map<?, ?>) reader.readObject();
36     for (Entry<?, ?> row : hashMap.entrySet()) {
37       table.row(row.getKey()).putAll((Map<?, ?>) row.getValue());
38     }
39     return table;
40   }
41 
serialize(SerializationStreamWriter writer, StandardTable<?, ?, ?> table)42   static void serialize(SerializationStreamWriter writer, StandardTable<?, ?, ?> table)
43       throws SerializationException {
44     /*
45      * The backing map of a {Hash,Tree}BasedTable is a {Hash,Tree}Map of {Hash,Tree}Maps. Therefore,
46      * the backing map is serializable (assuming that the row, column and values, along with any
47      * comparators, are all serializable).
48      */
49     writer.writeObject(table.backingMap);
50   }
51 
Table_CustomFieldSerializerBase()52   private Table_CustomFieldSerializerBase() {}
53 }
54