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 15package com.google.common.collect; 16 17import com.google.gwt.user.client.rpc.SerializationException; 18import com.google.gwt.user.client.rpc.SerializationStreamReader; 19import com.google.gwt.user.client.rpc.SerializationStreamWriter; 20 21import java.util.Map; 22import 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 */ 32final class Table_CustomFieldSerializerBase { 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 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 52 private Table_CustomFieldSerializerBase() {} 53} 54