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

org.mapdb.serializer.SerializerArrayTuple Maven / Gradle / Ivy

package org.mapdb.serializer;

import org.jetbrains.annotations.NotNull;
import org.mapdb.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

/**
 * Serializer for tuples. It serializes fixed size array, where each array index can use different serializer.
 *
 * It takes array of serializes in constructor parameter. All tuples (arrays) must have the same size.
 */
public class SerializerArrayTuple implements GroupSerializer {

    protected final Serializer[] ser;
    protected final Comparator[] comp;
    protected final int size;

    public SerializerArrayTuple(Serializer[] serializers, Comparator[] comparators) {
        this.ser = serializers.clone();
        this.comp = comparators.clone();
        this.size = ser.length;
    }

    public SerializerArrayTuple(Serializer... serializers) {
        this.ser = serializers.clone();
        this.comp = ser;
        this.size = ser.length;
    }


    protected Object[] cast(Object o){
        if(CC.ASSERT && ((Object[])o).length%size!=0) {
            throw new AssertionError();
        }
        return (Object[])o;
    }

    @Override
    public void serialize(@NotNull DataOutput2 out, @NotNull Object[] value) throws IOException {
        for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy