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

org.aksw.jenax.io.kryo.jena.Expr1Serializer Maven / Gradle / Ivy

package org.aksw.jenax.io.kryo.jena;

import java.util.function.Function;

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


public class Expr1Serializer
    extends Serializer
{
    protected Function getArg;
    protected Function ctor;

    public Expr1Serializer(Function getArg, Function ctor) {
        super();
        this.getArg = getArg;
        this.ctor = ctor;
    }

    @Override
    public void write(Kryo kryo, Output output, I obj) {
        O arg = getArg.apply(obj);
        kryo.writeClassAndObject(output, arg);
    }

    @Override
    public I read(Kryo kryo, Input input, Class objClass) {
        @SuppressWarnings("unchecked")
        O arg = (O)kryo.readClassAndObject(input);
        I result = ctor.apply(arg);
        return result;
    }
}