10888a09821a98ac0680fad765217302858e70fa4Paul Duffin/* 20888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Copyright (C) 2012 The Guava Authors 30888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 40888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 50888a09821a98ac0680fad765217302858e70fa4Paul Duffin * in compliance with the License. You may obtain a copy of the License at 60888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 70888a09821a98ac0680fad765217302858e70fa4Paul Duffin * http://www.apache.org/licenses/LICENSE-2.0 80888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 90888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Unless required by applicable law or agreed to in writing, software distributed under the License 100888a09821a98ac0680fad765217302858e70fa4Paul Duffin * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 110888a09821a98ac0680fad765217302858e70fa4Paul Duffin * or implied. See the License for the specific language governing permissions and limitations under 120888a09821a98ac0680fad765217302858e70fa4Paul Duffin * the License. 130888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 140888a09821a98ac0680fad765217302858e70fa4Paul Duffin 150888a09821a98ac0680fad765217302858e70fa4Paul Duffinpackage com.google.common.collect; 160888a09821a98ac0680fad765217302858e70fa4Paul Duffin 170888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.gwt.user.client.rpc.SerializationException; 180888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.gwt.user.client.rpc.SerializationStreamReader; 190888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.gwt.user.client.rpc.SerializationStreamWriter; 200888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.gwt.user.client.rpc.core.java.util.Map_CustomFieldSerializerBase; 210888a09821a98ac0680fad765217302858e70fa4Paul Duffin 220888a09821a98ac0680fad765217302858e70fa4Paul Duffin/** 230888a09821a98ac0680fad765217302858e70fa4Paul Duffin * This class contains static utility methods for writing {@link ImmutableTable} GWT field 240888a09821a98ac0680fad765217302858e70fa4Paul Duffin * serializers. Serializers should delegate to {@link #serialize} and {@link #instantiate}. 250888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 260888a09821a98ac0680fad765217302858e70fa4Paul Duffin * @author Chris Povirk 270888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 280888a09821a98ac0680fad765217302858e70fa4Paul Duffinfinal class ImmutableTable_CustomFieldSerializerBase { 290888a09821a98ac0680fad765217302858e70fa4Paul Duffin public static ImmutableTable<Object, Object, Object> instantiate(SerializationStreamReader reader) 300888a09821a98ac0680fad765217302858e70fa4Paul Duffin throws SerializationException { 310888a09821a98ac0680fad765217302858e70fa4Paul Duffin ImmutableTable.Builder<Object, Object, Object> builder = ImmutableTable.builder(); 320888a09821a98ac0680fad765217302858e70fa4Paul Duffin int rowCount = reader.readInt(); 330888a09821a98ac0680fad765217302858e70fa4Paul Duffin for (int i = 0; i < rowCount; i++) { 340888a09821a98ac0680fad765217302858e70fa4Paul Duffin Object rowKey = reader.readObject(); 350888a09821a98ac0680fad765217302858e70fa4Paul Duffin int colCount = reader.readInt(); 360888a09821a98ac0680fad765217302858e70fa4Paul Duffin for (int j = 0; j < colCount; j++) { 370888a09821a98ac0680fad765217302858e70fa4Paul Duffin builder.put(rowKey, reader.readObject(), reader.readObject()); 380888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 390888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 400888a09821a98ac0680fad765217302858e70fa4Paul Duffin return builder.build(); 410888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 420888a09821a98ac0680fad765217302858e70fa4Paul Duffin 430888a09821a98ac0680fad765217302858e70fa4Paul Duffin public static void serialize( 440888a09821a98ac0680fad765217302858e70fa4Paul Duffin SerializationStreamWriter writer, ImmutableTable<Object, Object, Object> table) 450888a09821a98ac0680fad765217302858e70fa4Paul Duffin throws SerializationException { 460888a09821a98ac0680fad765217302858e70fa4Paul Duffin writer.writeInt(table.rowKeySet().size()); 470888a09821a98ac0680fad765217302858e70fa4Paul Duffin for (Object rowKey : table.rowKeySet()) { 480888a09821a98ac0680fad765217302858e70fa4Paul Duffin writer.writeObject(rowKey); 490888a09821a98ac0680fad765217302858e70fa4Paul Duffin Map_CustomFieldSerializerBase.serialize(writer, table.row(rowKey)); 500888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 510888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 520888a09821a98ac0680fad765217302858e70fa4Paul Duffin 530888a09821a98ac0680fad765217302858e70fa4Paul Duffin private ImmutableTable_CustomFieldSerializerBase() {} 540888a09821a98ac0680fad765217302858e70fa4Paul Duffin} 55