001/*
002 * Copyright (C) 2009 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect;
018
019import com.google.gwt.user.client.rpc.SerializationException;
020import com.google.gwt.user.client.rpc.SerializationStreamReader;
021import com.google.gwt.user.client.rpc.SerializationStreamWriter;
022import java.util.ArrayList;
023import java.util.Comparator;
024import java.util.List;
025
026/**
027 * This class implements the GWT serialization of {@link CompoundOrdering}.
028 *
029 * @author Chris Povirk
030 */
031public class CompoundOrdering_CustomFieldSerializer {
032
033  public static void deserialize(SerializationStreamReader reader, CompoundOrdering<?> instance) {}
034
035  @SuppressWarnings("unchecked") // deserialization is unsafe
036  public static CompoundOrdering<Object> instantiate(SerializationStreamReader reader)
037      throws SerializationException {
038    int n = reader.readInt();
039    List<Comparator<Object>> comparators = new ArrayList<>();
040    for (int i = 0; i < n; i++) {
041      comparators.add((Comparator<Object>) reader.readObject());
042    }
043    return new CompoundOrdering<>(comparators);
044  }
045
046  public static void serialize(SerializationStreamWriter writer, CompoundOrdering<?> instance)
047      throws SerializationException {
048    writer.writeInt(instance.comparators.length);
049    for (Comparator<?> comparator : instance.comparators) {
050      writer.writeObject(comparator);
051    }
052  }
053}