org.aksw.jenax.io.kryo.jena.ExprFunctionNSerializer Maven / Gradle / Ivy
package org.aksw.jenax.io.kryo.jena;
import java.util.List;
import java.util.function.Function;
import org.apache.jena.sparql.expr.Expr;
import org.apache.jena.sparql.expr.ExprFunction;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
/**
* Serializer for subclasses of {@link ExprFunction}. Mainly for use with ExprFunctionN.
* ExprFunctions that take a fixed number of arguments should use serializers that avoid the List overhead.
*/
public class ExprFunctionNSerializer extends Serializer {
protected Function, T> ctor;
public ExprFunctionNSerializer(Function, T> ctor) {
super();
this.ctor = ctor;
}
@Override
public void write(Kryo kryo, Output output, ExprFunction obj) {
List args = obj.getArgs();
kryo.writeClassAndObject(output, args);
}
@Override
public T read(Kryo kryo, Input input, Class objClass) {
@SuppressWarnings("unchecked")
List args = (List)kryo.readClassAndObject(input);
T result = ctor.apply(args);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy