All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.javakaffee.kryoserializers.guava.MultimapSerializerBase Maven / Gradle / Ivy

package de.javakaffee.kryoserializers.guava;

import java.util.Map;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import com.google.common.collect.Multimap;

public abstract class MultimapSerializerBase> extends Serializer {

    public MultimapSerializerBase(boolean acceptsNull, boolean immutable) {
        super(acceptsNull, immutable);
    }

    protected void writeMultimap(Kryo kryo, Output output, Multimap multimap) {
        output.writeInt(multimap.size(), true);
        for (final Map.Entry entry : multimap.entries()) {
            kryo.writeClassAndObject(output, entry.getKey());
            kryo.writeClassAndObject(output, entry.getValue());
        }
    }

    protected void readMultimap(Kryo kryo, Input input, Multimap multimap) {
        final int size = input.readInt(true);
        for (int i = 0; i < size; ++i) {
            final K key = (K) kryo.readClassAndObject(input);
            final V value = (V) kryo.readClassAndObject(input);
            multimap.put(key, value);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy