de.javakaffee.kryoserializers.guava.ImmutableSetSerializer Maven / Gradle / Ivy
package de.javakaffee.kryoserializers.guava;
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.ImmutableSet;
import com.google.common.collect.Sets;
/**
* A kryo {@link Serializer} for guava-libraries {@link ImmutableSet}.
*
*@implNote ImmutableSet builder would be a little bit more efficient for less than five elements
*(the array.clone as done by copyOf is saved), for more elements copyOf seems to get more efficient.
*/
public class ImmutableSetSerializer extends Serializer> {
private static final boolean DOES_NOT_ACCEPT_NULL = false;
private static final boolean IMMUTABLE = true;
public ImmutableSetSerializer() {
super(DOES_NOT_ACCEPT_NULL, IMMUTABLE);
}
@Override
public void write(Kryo kryo, Output output, ImmutableSet